-
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathpreferences.py
More file actions
62 lines (50 loc) · 1.83 KB
/
Copy pathpreferences.py
File metadata and controls
62 lines (50 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
"""
App-wide user preferences for Doza Assist.
Stored at ~/Library/Application Support/Doza Assist/preferences.json.
Currently tracks the user's default editing platform (FCP / Premiere / Resolve).
All IO is best-effort — if the file is unreadable or the directory can't be
created, we fall back to the in-memory default rather than breaking the app.
"""
import os
import json
import tempfile
PREFS_DIR = os.path.expanduser("~/Library/Application Support/Doza Assist")
PREFS_PATH = os.path.join(PREFS_DIR, "preferences.json")
VALID_PLATFORMS = ("fcp", "premiere", "resolve")
DEFAULT_PLATFORM = "fcp"
def load_preferences() -> dict:
"""Load preferences. Returns {} on any error."""
try:
with open(PREFS_PATH, "r") as f:
data = json.load(f)
return data if isinstance(data, dict) else {}
except (OSError, json.JSONDecodeError):
return {}
def save_preferences(prefs: dict) -> bool:
"""Atomic write. Returns True on success, False otherwise."""
try:
os.makedirs(PREFS_DIR, exist_ok=True)
fd, tmp_path = tempfile.mkstemp(prefix=".prefs-", dir=PREFS_DIR)
try:
with os.fdopen(fd, "w") as f:
json.dump(prefs, f, indent=2)
os.replace(tmp_path, PREFS_PATH)
return True
except Exception:
try:
os.unlink(tmp_path)
except OSError:
pass
return False
except OSError:
return False
def get_default_platform() -> str:
prefs = load_preferences()
p = prefs.get("default_platform")
return p if p in VALID_PLATFORMS else DEFAULT_PLATFORM
def set_default_platform(platform: str) -> bool:
if platform not in VALID_PLATFORMS:
return False
prefs = load_preferences()
prefs["default_platform"] = platform
return save_preferences(prefs)