From 9d275488e2c290287aed9b280217abdc1a914ffc Mon Sep 17 00:00:00 2001 From: Broque Thomas Date: Tue, 6 Jan 2026 09:29:11 -0800 Subject: [PATCH] Add config reload support and improve config loading Introduces a reload_config method to SpotifyClient and refactors ConfigManager to support reloading configuration from a file. Updates web_server.py to use the new config loading mechanism, ensuring configuration is loaded into the existing singleton instance and SpotifyClient is properly re-initialized after settings changes. --- config/settings.py | 10 ++++++++++ core/spotify_client.py | 4 ++++ web_server.py | 20 ++++++-------------- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/config/settings.py b/config/settings.py index 43327079..091f8dd6 100644 --- a/config/settings.py +++ b/config/settings.py @@ -14,6 +14,16 @@ class ConfigManager: import os db_path = os.environ.get('DATABASE_PATH', 'database/music_library.db') self.database_path = Path(db_path) + self.load_config(config_path) + + def load_config(self, config_path: str = None): + """ + Load configuration from database or file. + Can be called to reload settings into the existing instance. + """ + if config_path: + self.config_path = Path(config_path) + self._load_config() def _get_encryption_key(self) -> bytes: diff --git a/core/spotify_client.py b/core/spotify_client.py index 6e3d4965..81b93240 100644 --- a/core/spotify_client.py +++ b/core/spotify_client.py @@ -170,6 +170,10 @@ class SpotifyClient: self.sp: Optional[spotipy.Spotify] = None self.user_id: Optional[str] = None self._setup_client() + + def reload_config(self): + """Reload configuration and re-initialize client""" + self._setup_client() def _setup_client(self): config = config_manager.get_spotify_config() diff --git a/web_server.py b/web_server.py index e0a76918..d0d62c3b 100644 --- a/web_server.py +++ b/web_server.py @@ -58,19 +58,9 @@ else: if os.path.exists(config_path): print(f"Found config file at: {config_path}") - # Assuming your config_manager has a method to load from a specific path - if hasattr(config_manager, 'load_config'): - config_manager.load_config(config_path) - print("✅ Web server configuration loaded successfully.") - else: - # Fallback if no load_config method, try re-initializing with path - print("🔴 WARNING: config_manager does not have a 'load_config' method. Attempting re-init.") - try: - from config.settings import ConfigManager - config_manager = ConfigManager(config_path) - print("✅ Web server configuration re-initialized successfully.") - except Exception as e: - print(f"🔴 FAILED to re-initialize config_manager: {e}") + # Load configuration into the existing singleton instance + config_manager.load_config(config_path) + print("✅ Web server configuration loaded successfully.") else: print(f"🔴 WARNING: config.json not found at {config_path}. Using default settings.") # Correctly point to the 'webui' directory for templates and static files @@ -2242,7 +2232,9 @@ def handle_settings(): services_text = ", ".join(changed_services) add_activity_item("⚙️", "Settings Updated", f"{services_text} configuration saved", "Now") - spotify_client._setup_client() + add_activity_item("⚙️", "Settings Updated", f"{services_text} configuration saved", "Now") + + spotify_client.reload_config() plex_client.server = None jellyfin_client.server = None # Reload orchestrator settings (download source mode, hybrid_primary, etc.)