feat(agent): add opt-in push notifications

This commit is contained in:
2026-10-14 22:03:21 -07:00
parent 80748f764f
commit a1c0264d36
51 changed files with 4815 additions and 121 deletions
+13 -6
View File
@@ -1,12 +1,19 @@
export async function ensureServiceWorker(): Promise<ServiceWorkerRegistration> {
const registration = await navigator.serviceWorker.register("/sw.js", { updateViaCache: "none" });
// ready can otherwise remain pending forever after an install failure.
return new Promise((resolve, reject) => {
const timeout = setTimeout(() => reject(new Error("The notification worker did not become ready. Reload and try again.")), 15000);
void navigator.serviceWorker.ready.then(ready => { clearTimeout(timeout); resolve(ready); }, () => {
clearTimeout(timeout); reject(new Error("The notification worker is unavailable."));
});
void registration.update().catch(() => undefined);
});
}
export function registerServiceWorker() {
if (!import.meta.env.PROD || !("serviceWorker" in navigator)) return;
window.addEventListener("load", () => {
void navigator.serviceWorker
.register("/sw.js", { updateViaCache: "none" })
.then((registration) => registration.update())
.catch((error: unknown) => {
console.warn("Sybil service worker registration failed", error);
});
void ensureServiceWorker().catch(() => undefined);
});
}