summaryrefslogtreecommitdiffstats
path: root/hyprsunset_qt/settings.py
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-07-17 10:12:49 +0200
committerDanilo M. <danix@danix.xyz>2026-07-17 10:12:49 +0200
commitfa74bf36bd5cce6e86c9f38f71284d8d429cc5d6 (patch)
treeef0ede9d4945224badf3d03ac7a702f4a18b2f8a /hyprsunset_qt/settings.py
parent7548ce1bfd4496d7cb035706307d709801a54a30 (diff)
downloadhyprsunset-qt-fa74bf36bd5cce6e86c9f38f71284d8d429cc5d6.tar.gz
hyprsunset-qt-fa74bf36bd5cce6e86c9f38f71284d8d429cc5d6.zip
feat: app settings INI
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Diffstat (limited to 'hyprsunset_qt/settings.py')
-rw-r--r--hyprsunset_qt/settings.py53
1 files changed, 53 insertions, 0 deletions
diff --git a/hyprsunset_qt/settings.py b/hyprsunset_qt/settings.py
new file mode 100644
index 0000000..d9cca39
--- /dev/null
+++ b/hyprsunset_qt/settings.py
@@ -0,0 +1,53 @@
+"""App settings stored in ~/.config/hyprsunset-qt/config (INI)."""
+
+from __future__ import annotations
+
+import configparser
+from dataclasses import dataclass
+from pathlib import Path
+
+SETTINGS_PATH = Path.home() / ".config" / "hyprsunset-qt" / "config"
+DEFAULT_CACHE = "~/.config/hyprsunset-qt/sun.json"
+
+
+@dataclass
+class Settings:
+ lat: str = ""
+ lon: str = ""
+ auto_detect: bool = True
+ cache_path: str = DEFAULT_CACHE
+ daemon_command: str = "hyprsunset"
+
+ @classmethod
+ def load(cls, path: Path = SETTINGS_PATH) -> "Settings":
+ path = Path(path)
+ if not path.exists():
+ s = cls()
+ s.save(path)
+ return s
+ cp = configparser.ConfigParser()
+ cp.read(path)
+ return cls(
+ lat=cp.get("location", "lat", fallback=""),
+ lon=cp.get("location", "lon", fallback=""),
+ auto_detect=cp.getboolean("location", "auto_detect", fallback=True),
+ cache_path=cp.get("cache", "path", fallback=DEFAULT_CACHE),
+ daemon_command=cp.get("daemon", "command", fallback="hyprsunset"),
+ )
+
+ def save(self, path: Path = SETTINGS_PATH) -> None:
+ path = Path(path)
+ path.parent.mkdir(parents=True, exist_ok=True)
+ cp = configparser.ConfigParser()
+ cp["location"] = {
+ "lat": self.lat,
+ "lon": self.lon,
+ "auto_detect": str(self.auto_detect).lower(),
+ }
+ cp["cache"] = {"path": self.cache_path}
+ cp["daemon"] = {"command": self.daemon_command}
+ with path.open("w") as f:
+ cp.write(f)
+
+ def cache_path_expanded(self) -> Path:
+ return Path(self.cache_path).expanduser()