From 8a1f6811c0c8be3bf1cc4ee47536aa909b25fec8 Mon Sep 17 00:00:00 2001 From: Maksim Totmin Date: Sun, 31 May 2026 18:01:55 +0700 Subject: [PATCH] Move config to ~/.config/neo-pod-desktop/config.ini with migration - Config is now in XDG_CONFIG_HOME (~/.config/) for write access in AppImage - Auto-migrates existing config.ini from project root on first run - Creates directory on save() if not exists --- src/config_loader.py | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/src/config_loader.py b/src/config_loader.py index f9be2e2..96075cd 100644 --- a/src/config_loader.py +++ b/src/config_loader.py @@ -21,23 +21,33 @@ class ConfigLoader: def __init__(self, config_file: Optional[str] = None): """ Initialize the configuration loader - + Args: config_file: Path to configuration file (optional) """ - # Default config file is in the project root directory if not config_file: self.config_file = os.path.join( - os.path.dirname(os.path.dirname(os.path.abspath(__file__))), - "config.ini" + os.path.expanduser("~"), ".config", "neo-pod-desktop", "config.ini" ) + self._migrate_old_config() else: self.config_file = config_file - + self.config = configparser.ConfigParser() - + # Load configuration self.load() + + def _migrate_old_config(self): + """Migrate config from old project-root location to XDG config dir.""" + old_path = os.path.join( + os.path.dirname(os.path.dirname(os.path.abspath(__file__))), + "config.ini" + ) + if os.path.exists(old_path) and not os.path.exists(self.config_file): + logger.info("Migrating config from %s to %s", old_path, self.config_file) + os.makedirs(os.path.dirname(self.config_file), exist_ok=True) + os.rename(old_path, self.config_file) def load(self) -> bool: """ @@ -63,16 +73,17 @@ class ConfigLoader: def save(self) -> bool: """ Save configuration to file - + Returns: True if successful, False otherwise """ try: logger.info(f"Saving configuration to {self.config_file}") - + os.makedirs(os.path.dirname(self.config_file), exist_ok=True) + with open(self.config_file, 'w') as f: self.config.write(f) - + return True except Exception as e: logger.error(f"Failed to save configuration: {e}")