diff --git a/.gitignore b/.gitignore index fcc6129..5fd14eb 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ client.db client.log settings.log config.json +default_config.log diff --git a/default_config.py b/default_config.py index 83abcd9..7c267bf 100644 --- a/default_config.py +++ b/default_config.py @@ -21,6 +21,18 @@ def format_json_single_line_arrays(data, indent=4): return format_value(data, indent) +# Recursive function to check and update nested dictionaries +def update_dict(default, actual): + updated = False + for key, value in default.items(): + if key not in actual: + actual[key] = value + updated = True + elif isinstance(value, dict): + # Recursively check nested dictionaries + updated = update_dict(value, actual[key]) or updated + return updated + def initialize_config(): app_directory = os.path.dirname(os.path.abspath(__file__)) json_file_path = os.path.join(app_directory, "config.json") @@ -52,13 +64,13 @@ def initialize_config(): "window_frame_selected": ["green", "black"], "log_header": ["blue", "black"], "log": ["green", "black"], + "settings_default": ["white", "black"], "settings_sensitive": ["red", "black"], "settings_save": ["green", "black"], "settings_breadcrumbs": ["white", "black"] }, } - if not os.path.exists(json_file_path): with open(json_file_path, "w", encoding="utf-8") as json_file: formatted_json = format_json_single_line_arrays(default_config_variables) @@ -69,21 +81,17 @@ def initialize_config(): loaded_config = json.load(json_file) # Check and add missing variables - updated = False - for key, value in default_config_variables.items(): - if key not in loaded_config: - loaded_config[key] = value - updated = True + updated = update_dict(default_config_variables, loaded_config) # Update the JSON file if any variables were missing if updated: - with open(json_file_path, "w", encoding="utf-8") as json_file: - json.dump(loaded_config, json_file, indent=4, ensure_ascii=False) - logging.info(f"JSON file updated with missing default variables.") + formatted_json = format_json_single_line_arrays(loaded_config) + with open(json_file_path, "w", encoding="utf-8") as json_file: + json_file.write(formatted_json) + logging.info(f"JSON file updated with missing default variables and COLOR_CONFIG items.") return loaded_config - # Call the function when the script is imported loaded_config = initialize_config() @@ -116,4 +124,4 @@ if __name__ == "__main__": print(f"ACK String: {ack_str}") print(f"NAK String: {nak_str}") print(f"ACK Unknown String: {ack_unknown_str}") - print(f"Color Config: {COLOR_CONFIG}") + print(f"Color Config: {COLOR_CONFIG}") \ No newline at end of file diff --git a/settings.py b/settings.py index 5a0369f..c099a47 100644 --- a/settings.py +++ b/settings.py @@ -44,7 +44,7 @@ def display_menu(current_menu, menu_path, selected_index, show_save_option): try: # Use red color for "Reboot" or "Shutdown" - color = get_color("settings_sensitive" if option in sensitive_settings else "default", reverse = (idx == selected_index)) + color = get_color("settings_sensitive" if option in sensitive_settings else "settings_default", reverse = (idx == selected_index)) menu_win.addstr(idx + 3, 4, f"{display_option:<{width // 2 - 2}} {display_value}".ljust(width - 8), color) except curses.error: pass