Skip to content

Commit 2af96b4

Browse files
committed
Pharos again
1 parent 7a1bc15 commit 2af96b4

2 files changed

Lines changed: 28 additions & 3 deletions

File tree

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version = "1.0.6"
1+
version = "1.0.7"

buildtools/pharos/app/daemon.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@
4646
os.environ.setdefault("SSL_CERT_FILE", certifi.where())
4747
os.environ.setdefault("REQUESTS_CA_BUNDLE", certifi.where())
4848

49+
# Ignore SIGHUP at import time. Python's default disposition is SIG_DFL
50+
# (terminate), so an ES game-end SIGHUP arriving before daemon_loop()'s
51+
# signal.signal(SIGHUP, _on_wake) call kills the process. daemon_loop
52+
# replaces this with the real handler once it's ready.
53+
signal.signal(signal.SIGHUP, signal.SIG_IGN)
54+
4955
# ----------------------------------------------------------------------
5056
# Paths
5157
# ----------------------------------------------------------------------
@@ -361,12 +367,30 @@ def format_message(outdated: Iterable[str], titles: dict[str, str]) -> str:
361367
return f"[PHAROS] {len(items)} updates available"
362368

363369
# ----------------------------------------------------------------------
364-
# Notify-state dedup (process-local; daemon restart wipes it)
370+
# Notify-state dedup (tmpfs-backed; survives in-session daemon restarts
371+
# but cleared on reboot — so the "reboot re-shows the toast" semantic is
372+
# preserved while spurious mid-session respawns stay silent)
365373
# ----------------------------------------------------------------------
366374
def _outdated_hash(items: Iterable[str]) -> str:
367375
return hashlib.sha256(",".join(sorted(items)).encode("utf-8")).hexdigest()
368376

369-
_state_cache: dict = {}
377+
STATE_FILE = Path("/tmp/pharos-daemon.state")
378+
379+
def _load_state() -> dict:
380+
try:
381+
return json.loads(STATE_FILE.read_text("utf-8"))
382+
except (OSError, json.JSONDecodeError):
383+
return {}
384+
385+
def _save_state(state: dict) -> None:
386+
tmp = STATE_FILE.with_suffix(".tmp")
387+
try:
388+
tmp.write_text(json.dumps(state), encoding="utf-8")
389+
os.replace(tmp, STATE_FILE)
390+
except OSError as e:
391+
log("WARN", f"state save failed: {e}")
392+
393+
_state_cache: dict = _load_state()
370394

371395
# ----------------------------------------------------------------------
372396
# Main check
@@ -421,6 +445,7 @@ def run_check() -> tuple[bool, bool]:
421445
for attempt in range(1, 7):
422446
if notify(cfw, msg):
423447
_state_cache["last_outdated_hash"] = h
448+
_save_state(_state_cache)
424449
return True, network_failed
425450
time.sleep(backoff)
426451
backoff = min(backoff * 2, RETRY_BACKOFF_MAX)

0 commit comments

Comments
 (0)