fix(webui): refine browser notifications (NAN-227)

Reconcile the original notification fix with the integrated main snapshot.

Group notification settings and simplify localized copy and documentation.
Preserve permission opt-out and notification click routing across app transitions.
Suppress late completion notifications for discarded temporary chats and align
notification settings skeletons with the loaded layout.
This commit is contained in:
chengyongru authored and chengyongru committed 2026-10-20 13:45:04 +08:00
1 parent 7b2af031c0
commit 11152626f8
34 files changed
+728 -289

No files matched your search

+13 -7
View File
@@ -26,7 +26,8 @@ function notificationTarget(value) {
const url = new URL(value);
if (url.origin !== self.location.origin || url.username || url.password || url.search || url.pathname !== "/") return null;
return /^#\/(?:chat|temporary)\/[^?]+$/.test(url.hash)
|| url.hash === "#/settings?section=appearance" ? url.href : null;
|| url.hash === "#/settings?section=appearance"
|| url.hash === "#/settings?section=notifications" ? url.href : null;
} catch { return null; }
}
@@ -59,8 +60,12 @@ async function notifyClient(source, data) {
}
self.addEventListener("message", (event) => {
if (event.data?.type !== "nanobot:notify" || !event.source?.url
|| new URL(event.source.url).origin !== self.location.origin) return;
if (!event.source?.url || new URL(event.source.url).origin !== self.location.origin) return;
if (event.data?.type === "nanobot:notification-probe") {
event.ports[0]?.postMessage(typeof self.registration.showNotification === "function" ? "ready" : "workerUnavailable");
return;
}
if (event.data?.type !== "nanobot:notify") return;
const work = noticeQueue.then(() => notifyClient(event.source, event.data));
noticeQueue = work.then(() => undefined, () => undefined);
event.waitUntil(work.then(
@@ -77,11 +82,12 @@ self.addEventListener("notificationclick", (event) => {
const windows = await self.clients.matchAll({ type: "window", includeUncontrolled: true });
const source = windows.find((client) => client.id === event.notification.data.clientId);
const temporary = new URL(url).hash.startsWith("#/temporary/");
const target = source || (!temporary && windows.find((client) => client.frameType === "top-level"));
if (target) {
target.postMessage({ type: "nanobot:notification-click", url });
await target.focus();
if (source) {
source.postMessage({ type: "nanobot:notification-click", url });
await source.focus();
} else {
// Other tabs may run older code without the click receiver. Open the
// destination normally instead of silently focusing an unrelated page.
// Temporary chats belong to their original connection, not another tab.
await self.clients.openWindow(temporary ? "/#/new" : url);
}