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.
This commit is contained in:
parent
42a4ccfc24
commit
9d275488e2
3 changed files with 20 additions and 14 deletions
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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.)
|
||||
|
|
|
|||
Loading…
Reference in a new issue