Skip to content

Commit 725a9f4

Browse files
committed
Update auth.py
1 parent 0d3aed8 commit 725a9f4

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

auth.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,29 @@
11
# auth.py
2-
import json, os, time
2+
import json, os, time, sys
33
from msal import PublicClientApplication, SerializableTokenCache
4+
from pathlib import Path
45

5-
CFG_PATH = "config.json"
6+
# Resolve config.json both in dev and in PyInstaller .app bundles
7+
if getattr(sys, "frozen", False) and hasattr(sys, "_MEIPASS"):
8+
BASE_DIR = Path(sys._MEIPASS)
9+
else:
10+
BASE_DIR = Path(__file__).parent
11+
12+
CFG_PATH = str((BASE_DIR / "config.json").resolve())
613

714
def load_config():
8-
with open(CFG_PATH, "r", encoding="utf-8") as f:
9-
return json.load(f)
15+
try:
16+
with open(CFG_PATH, "r", encoding="utf-8") as f:
17+
return json.load(f)
18+
except FileNotFoundError:
19+
raise RuntimeError(f"Missing config.json at {CFG_PATH}. If running as .app, ensure --add-data 'config.json:.' during build.")
1020

1121
cfg = load_config()
1222
CLIENT_ID = cfg["client_id"]
1323
SCOPES = cfg.get("scopes", ["Files.ReadWrite.All"])
14-
CACHE_FILE = cfg.get("token_cache_file", "token_cache.bin")
24+
# 使用 Application Support 路径保存 token 缓存
25+
CACHE_FILE = str(Path.home() / "Library/Application Support/OneDriveUploader/token_cache.bin")
26+
Path(CACHE_FILE).parent.mkdir(parents=True, exist_ok=True)
1527

1628
def _load_cache():
1729
cache = SerializableTokenCache()

0 commit comments

Comments
 (0)