Refactor Windows installer configuration and improve logging functionality
- Changed installation scope from "perMachine" to "perUser" in the Windows installer configuration. - Updated installation directory from "ProgramFiles64Folder" to "LocalAppDataFolder" for user-specific installations. - Enhanced the configuration saving method to create parent directories if they don't exist. - Improved the main window script loading logic to support multiple installation scenarios (development, PyInstaller, MSI). - Added detailed logging for script loading failures and success messages. - Implemented a new method to reconfigure logging settings at runtime, allowing dynamic updates from the settings dialog. - Enhanced the settings dialog to handle configuration saving, including log level changes and error handling.
This commit is contained in:
parent
0c276b9022
commit
8f3f859e5b
9 changed files with 3068 additions and 2905 deletions
|
|
@ -1,5 +1,6 @@
|
|||
"""Settings dialog for configuration management."""
|
||||
|
||||
import logging
|
||||
from pathlib import Path
|
||||
from typing import List, Optional
|
||||
|
||||
|
|
@ -22,6 +23,9 @@ from PySide6.QtWidgets import (
|
|||
|
||||
from webdrop_bridge.config import Config, ConfigurationError
|
||||
from webdrop_bridge.core.config_manager import ConfigExporter, ConfigProfile, ConfigValidator
|
||||
from webdrop_bridge.utils.logging import reconfigure_logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class SettingsDialog(QDialog):
|
||||
|
|
@ -76,6 +80,63 @@ class SettingsDialog(QDialog):
|
|||
|
||||
self.setLayout(layout)
|
||||
|
||||
def accept(self) -> None:
|
||||
"""Handle OK button - save configuration changes to file.
|
||||
|
||||
Validates configuration and saves to the default config path.
|
||||
Applies log level changes immediately in the running application.
|
||||
If validation or save fails, shows error and stays in dialog.
|
||||
"""
|
||||
try:
|
||||
# Get updated configuration data from UI
|
||||
config_data = self.get_config_data()
|
||||
|
||||
# Preserve URL mappings from original config (not editable in UI yet)
|
||||
config_data["url_mappings"] = [
|
||||
{
|
||||
"url_prefix": m.url_prefix,
|
||||
"local_path": m.local_path
|
||||
}
|
||||
for m in self.config.url_mappings
|
||||
]
|
||||
|
||||
# Update the config object with new values
|
||||
old_log_level = self.config.log_level
|
||||
self.config.log_level = config_data["log_level"]
|
||||
self.config.log_file = Path(config_data["log_file"]) if config_data["log_file"] else None
|
||||
self.config.allowed_roots = [Path(r).resolve() for r in config_data["allowed_roots"]]
|
||||
self.config.allowed_urls = config_data["allowed_urls"]
|
||||
self.config.window_width = config_data["window_width"]
|
||||
self.config.window_height = config_data["window_height"]
|
||||
|
||||
# Save to file (creates parent dirs if needed)
|
||||
config_path = Config.get_default_config_path()
|
||||
self.config.to_file(config_path)
|
||||
|
||||
logger.info(f"Configuration saved to {config_path}")
|
||||
logger.info(f" Log level: {self.config.log_level} (was: {old_log_level})")
|
||||
logger.info(f" Window size: {self.config.window_width}x{self.config.window_height}")
|
||||
|
||||
# Apply log level change immediately to running application
|
||||
if old_log_level != self.config.log_level:
|
||||
logger.info(f"🔄 Updating log level: {old_log_level} → {self.config.log_level}")
|
||||
reconfigure_logging(
|
||||
logger_name="webdrop_bridge",
|
||||
level=self.config.log_level,
|
||||
log_file=self.config.log_file
|
||||
)
|
||||
logger.info(f"✅ Log level updated to {self.config.log_level}")
|
||||
|
||||
# Call parent accept to close dialog
|
||||
super().accept()
|
||||
|
||||
except ConfigurationError as e:
|
||||
logger.error(f"Configuration error: {e}")
|
||||
self._show_error(f"Configuration Error:\n\n{e}")
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to save configuration: {e}", exc_info=True)
|
||||
self._show_error(f"Failed to save configuration:\n\n{e}")
|
||||
|
||||
def _create_paths_tab(self) -> QWidget:
|
||||
"""Create paths configuration tab."""
|
||||
widget = QWidget()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue