diff --git a/mediahive/config.py b/mediahive/config.py index c74f98d..e8b4a24 100644 --- a/mediahive/config.py +++ b/mediahive/config.py @@ -1,17 +1,19 @@ r"""Platform-appropriate config persistence for MediaHive. -Config file location: - Windows: %APPDATA%\mediahive\config.toml - macOS: ~/Library/Application Support/mediahive/config.toml - Linux: $XDG_CONFIG_HOME/mediahive/config.toml (~/.config/mediahive/config.toml) +Locations (via platformdirs): + Config — Windows: %LOCALAPPDATA%\mediahive\config.toml + macOS: ~/Library/Application Support/mediahive/config.toml + Linux: $XDG_CONFIG_HOME/mediahive/config.toml + Logs — Windows: %LOCALAPPDATA%\mediahive\mediahive.log + macOS: ~/Library/Logs/mediahive/mediahive.log + Linux: $XDG_STATE_HOME/mediahive/mediahive.log """ -import os -import sys from pathlib import Path import msgspec import msgspec.toml +from platformdirs import user_config_path, user_log_path class Config(msgspec.Struct, omit_defaults=True): @@ -20,13 +22,13 @@ class Config(msgspec.Struct, omit_defaults=True): def config_dir() -> Path: - if sys.platform == "win32": - base = Path(os.environ.get("APPDATA") or Path.home()) - elif sys.platform == "darwin": - base = Path.home() / "Library" / "Application Support" - else: - base = Path(os.environ.get("XDG_CONFIG_HOME") or (Path.home() / ".config")) - return base / "mediahive" + # Local (non-roaming) on Windows: config is machine-specific state, + # not something to sync across a domain profile. + return user_config_path("mediahive", roaming=False) + + +def log_dir() -> Path: + return user_log_path("mediahive", opinion=False) def config_path() -> Path: diff --git a/pyproject.toml b/pyproject.toml index 619d5c4..ec76456 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,6 +13,7 @@ dependencies = [ "httpx[http2]>=0.28.1", "msgspec>=0.19", "parse-torrent-title>=2.8.1", + "platformdirs>=4.0", "tomli-w>=1.2.0", "uvicorn[standard]>=0.40.0", ]