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
This commit is contained in:
parent
7a86732953
commit
8a1f6811c0
@ -25,12 +25,11 @@ class ConfigLoader:
|
||||
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
|
||||
|
||||
@ -39,6 +38,17 @@ class ConfigLoader:
|
||||
# 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:
|
||||
"""
|
||||
Load configuration from file
|
||||
@ -69,6 +79,7 @@ class ConfigLoader:
|
||||
"""
|
||||
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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user