few fixes
This commit is contained in:
parent
890c6ff6ba
commit
02752c7e4a
@ -5,7 +5,7 @@ from os import path
|
||||
import app.utils.paths as paths
|
||||
import json
|
||||
import logging
|
||||
from typing import Dict, Any, Union
|
||||
from typing import Dict, Any
|
||||
|
||||
# Configure logging
|
||||
logger: logging.Logger = logging.getLogger(__name__)
|
||||
@ -19,24 +19,6 @@ class SettingsManager:
|
||||
self.observer_manager: ObserverManager = observer_manager
|
||||
self.theme_manager: ThemeManager = theme_manager
|
||||
|
||||
# Hardcoded fallback settings in case files are missing
|
||||
self.fallback_settings: Dict[str, Any] = {
|
||||
"theme": "dark",
|
||||
"lang": "fr",
|
||||
"window_size": {"width": 1000, "height": 600},
|
||||
"maximized": False
|
||||
}
|
||||
|
||||
self.fallback_config: Dict[str, Any] = {
|
||||
"app_name": "Application",
|
||||
"app_os": "Windows",
|
||||
"app_version": "1.0.0",
|
||||
"architecture": "x64",
|
||||
"icon_path": "data/assets/icon.ico",
|
||||
"main_script": "main.py",
|
||||
"git_repo": ""
|
||||
}
|
||||
|
||||
# Load default settings
|
||||
self.default_settings: Dict[str, Any] = self._load_default_settings()
|
||||
# Load config
|
||||
@ -59,21 +41,16 @@ class SettingsManager:
|
||||
if path.exists(defaults_path):
|
||||
with open(defaults_path, 'r', encoding='utf-8') as f:
|
||||
settings = json.load(f)
|
||||
# Validate required keys
|
||||
for key in self.fallback_settings.keys():
|
||||
if key not in settings:
|
||||
logger.warning(f"Missing key '{key}' in defaults_settings.json, using fallback")
|
||||
settings[key] = self.fallback_settings[key]
|
||||
return settings
|
||||
else:
|
||||
logger.warning(f"defaults_settings.json not found, using fallback settings")
|
||||
return self.fallback_settings.copy()
|
||||
logger.warning(f"defaults_settings.json not found")
|
||||
return {}
|
||||
except (json.JSONDecodeError, FileNotFoundError, KeyError, UnicodeDecodeError) as e:
|
||||
logger.error(f"Error loading default settings: {e}")
|
||||
return self.fallback_settings.copy()
|
||||
return {}
|
||||
except Exception as e:
|
||||
logger.error(f"Unexpected error loading default settings: {e}")
|
||||
return self.fallback_settings.copy()
|
||||
return {}
|
||||
|
||||
def _load_config(self) -> Dict[str, Any]:
|
||||
"""Load config.json with error handling"""
|
||||
@ -82,21 +59,16 @@ class SettingsManager:
|
||||
if path.exists(config_path):
|
||||
with open(config_path, 'r', encoding='utf-8') as f:
|
||||
config = json.load(f)
|
||||
# Validate required keys
|
||||
for key in self.fallback_config.keys():
|
||||
if key not in config:
|
||||
logger.warning(f"Missing key '{key}' in config.json, using fallback")
|
||||
config[key] = self.fallback_config[key]
|
||||
return config
|
||||
else:
|
||||
logger.warning("config.json not found, using fallback config")
|
||||
return self.fallback_config.copy()
|
||||
logger.warning("config.json not found")
|
||||
return {}
|
||||
except (json.JSONDecodeError, FileNotFoundError, KeyError, UnicodeDecodeError) as e:
|
||||
logger.error(f"Error loading config: {e}")
|
||||
return self.fallback_config.copy()
|
||||
return {}
|
||||
except Exception as e:
|
||||
logger.error(f"Unexpected error loading config: {e}")
|
||||
return self.fallback_config.copy()
|
||||
return {}
|
||||
|
||||
def _initialize_qsettings(self) -> QSettings:
|
||||
"""Initialize QSettings with error handling"""
|
||||
@ -114,10 +86,10 @@ class SettingsManager:
|
||||
def get_config(self, key: str) -> Any:
|
||||
"""Get configuration value by key"""
|
||||
try:
|
||||
return self.config.get(key, self.fallback_config.get(key))
|
||||
return self.config.get(key)
|
||||
except Exception as e:
|
||||
logger.error(f"Error getting config key '{key}': {e}")
|
||||
return self.fallback_config.get(key)
|
||||
return None
|
||||
|
||||
# Theme
|
||||
def get_theme(self) -> str:
|
||||
@ -126,7 +98,7 @@ class SettingsManager:
|
||||
return self.settings.value("theme", self.default_settings.get("theme"))
|
||||
except Exception as e:
|
||||
logger.error(f"Error getting theme: {e}")
|
||||
return self.fallback_settings["theme"]
|
||||
return ""
|
||||
|
||||
def set_theme(self, mode: str) -> None:
|
||||
"""Set the application theme"""
|
||||
@ -145,7 +117,7 @@ class SettingsManager:
|
||||
return self.settings.value("lang", self.default_settings.get("lang"))
|
||||
except Exception as e:
|
||||
logger.error(f"Error getting language: {e}")
|
||||
return self.fallback_settings["lang"]
|
||||
return ""
|
||||
|
||||
def set_language(self, lang_code: str) -> None:
|
||||
"""Set the application language"""
|
||||
@ -163,14 +135,14 @@ class SettingsManager:
|
||||
size = self.settings.value("window_size", self.default_settings.get("window_size"))
|
||||
# Validate window size values
|
||||
if isinstance(size, dict) and "width" in size and "height" in size:
|
||||
width = int(size["width"]) if size["width"] > 0 else self.fallback_settings["window_size"]["width"]
|
||||
height = int(size["height"]) if size["height"] > 0 else self.fallback_settings["window_size"]["height"]
|
||||
width = int(size["width"]) if size["width"] > 0 else 1000
|
||||
height = int(size["height"]) if size["height"] > 0 else 600
|
||||
return {"width": width, "height": height}
|
||||
else:
|
||||
return self.fallback_settings["window_size"].copy()
|
||||
return {"width": 1000, "height": 600}
|
||||
except Exception as e:
|
||||
logger.error(f"Error getting window size: {e}")
|
||||
return self.fallback_settings["window_size"].copy()
|
||||
return {"width": 1000, "height": 600}
|
||||
|
||||
def set_window_size(self, width: int, height: int) -> None:
|
||||
"""Set the window size"""
|
||||
@ -196,10 +168,10 @@ class SettingsManager:
|
||||
elif isinstance(value, bool):
|
||||
return value
|
||||
else:
|
||||
return self.fallback_settings["maximized"]
|
||||
return False
|
||||
except Exception as e:
|
||||
logger.error(f"Error getting maximized state: {e}")
|
||||
return self.fallback_settings["maximized"]
|
||||
return False
|
||||
|
||||
def set_maximized(self, maximized: bool) -> None:
|
||||
"""Set the window maximized state"""
|
||||
|
@ -106,9 +106,7 @@ class UpdateManager:
|
||||
if download_cancelled:
|
||||
f.truncate(0)
|
||||
f.close()
|
||||
os.remove(local_path, dir_fd=None)
|
||||
self.alert_manager.show_info(self.language_manager.get_text("update_aborted"), parent=parent)
|
||||
return False
|
||||
break
|
||||
|
||||
if chunk:
|
||||
f.write(chunk)
|
||||
@ -117,8 +115,12 @@ class UpdateManager:
|
||||
loading_bar.set_progress(percent)
|
||||
|
||||
dialog.close()
|
||||
|
||||
|
||||
|
||||
if download_cancelled:
|
||||
os.remove(local_path, dir_fd=None)
|
||||
self.alert_manager.show_info(self.language_manager.get_text("update_aborted"), parent=parent)
|
||||
return False
|
||||
|
||||
msg = self.language_manager.get_text("update_downloaded").replace("{local_path}", local_path)
|
||||
self.alert_manager.show_success(msg, parent=parent)
|
||||
|
||||
|
@ -69,10 +69,10 @@ class TabsWidget(QWidget):
|
||||
self.end_buttons = []
|
||||
|
||||
# Icon Colors
|
||||
self.selected_icon_color = self.theme_manager.current_theme.get_color("selected_icon")
|
||||
self.unselected_icon_color = self.theme_manager.current_theme.get_color("unselected_icon")
|
||||
self.selected_border_icon_color = self.theme_manager.current_theme.get_color("selected_border_icon")
|
||||
self.hover_icon_color = self.theme_manager.current_theme.get_color("hover_icon")
|
||||
self.selected_icon_color = self.theme_manager.current_theme.get_color("icon_selected_color")
|
||||
self.unselected_icon_color = self.theme_manager.current_theme.get_color("icon_unselected_color")
|
||||
self.selected_border_icon_color = self.theme_manager.current_theme.get_color("icon_selected_border_color")
|
||||
self.hover_icon_color = self.theme_manager.current_theme.get_color("icon_hover_color")
|
||||
|
||||
# Spacer items for alignment
|
||||
self.left_spacer = None
|
||||
@ -446,14 +446,14 @@ class TabsWidget(QWidget):
|
||||
if self.onTabChange and old_index != index:
|
||||
try:
|
||||
self.onTabChange(index)
|
||||
except Exception as e:
|
||||
print(f"Error in onTabChange callback: {e}")
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
def set_theme(self):
|
||||
self.selected_icon_color = self.theme_manager.current_theme.get_color("selected_icon")
|
||||
self.unselected_icon_color = self.theme_manager.current_theme.get_color("unselected_icon")
|
||||
self.selected_border_icon_color = self.theme_manager.current_theme.get_color("selected_border_icon")
|
||||
self.hover_icon_color = self.theme_manager.current_theme.get_color("hover_icon")
|
||||
self.selected_icon_color = self.theme_manager.current_theme.get_color("icon_selected_color")
|
||||
self.unselected_icon_color = self.theme_manager.current_theme.get_color("icon_unselected_color")
|
||||
self.selected_border_icon_color = self.theme_manager.current_theme.get_color("icon_selected_border_color")
|
||||
self.hover_icon_color = self.theme_manager.current_theme.get_color("icon_hover_color")
|
||||
# Apply theme to all buttons
|
||||
for i, button in enumerate(self.buttons):
|
||||
# Check if button is currently selected
|
||||
|
Loading…
x
Reference in New Issue
Block a user