const NEXT_AT_KEY = "peach_pro_nudge_next_at"; const DAY_MS = 24 * 60 * 60 * 1000; const FIRST_SIGHT_GRACE_MS = 14 * DAY_MS; const CADENCE_MS = 30 * DAY_MS; const SNOOZE_MS = 90 * DAY_MS; type NextAt = number | "never"; /** * Returns whether the Peach Pro nudge is due now, and if so records the * showing so a popup closed without a choice waits a full cadence window. */ export async function claimProNudge(now = Date.now()): Promise { let nextAt: NextAt | undefined; try { nextAt = (await chrome.storage.local.get(NEXT_AT_KEY))[NEXT_AT_KEY] as NextAt | undefined; } catch { return false; } if (nextAt === "never") return false; if (typeof nextAt !== "number") { await chrome.storage.local.set({ [NEXT_AT_KEY]: now + FIRST_SIGHT_GRACE_MS }); return false; } if (now < nextAt) return false; await chrome.storage.local.set({ [NEXT_AT_KEY]: now + CADENCE_MS }); return true; } export async function snoozeProNudge(now = Date.now()): Promise { await chrome.storage.local.set({ [NEXT_AT_KEY]: now + SNOOZE_MS }); } export async function silenceProNudge(): Promise { await chrome.storage.local.set({ [NEXT_AT_KEY]: "never" satisfies NextAt }); }