Installable app, push notifications about new mail, Install app entry

The webmail is now a PWA: web app manifest, icons (any + maskable, a status-bar
badge), theme-coloured title bar following the chosen theme, and an app-icon
badge with the unread Inbox count. The service worker is always installed;
offline access is on only when it is registered as /sw.js?offline=1, so
turning it on or off is an update that applies at once.

Notifications (Settings → Accounts → Notifications, per device) use Web Push.
Encryption (RFC 8291) and VAPID signing (RFC 8292) are implemented in
app/push/webpush.py — pywebpush needs a newer cryptography than we pin — and
checked against the RFC's worked example. The server makes its key pair on
first use (private half encrypted with MASTER_KEY). New mail found by the live
sync in an Inbox enqueues a job 5 s later that tells the user's devices about
messages still unread there, under 2 hours old and not from the user; more
than three become one "N new messages". A subscription belongs to the session
it was made under: signed out or revoked, nothing more is sent there. Endpoints
are limited to the known push services (no SSRF). Nothing shows while the app
is in front (except on Apple, which requires it). Tested with real pushes
through Google's service in Chromium and Opera.

The mobile drawer gets "Install app": Chrome's own install dialog where the
browser offers one, else short steps for iPhone/iPad, Opera and Firefox, with
"Don't show this again". docs/nas-install.md §5.3 covers installing,
notifications, Public URL and a later Android app (TWA).

Migration 0022: push_subscriptions, app_settings.vapid_*.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-08 18:52:26 +02:00
co-authored by Claude Opus 5.5
parent 0729dbb691
commit fda4cc6f16
37 changed files with 1765 additions and 42 deletions
+9
View File
@@ -20,6 +20,7 @@ import {
} from "../components/compose/windows";
import { DraftsList, ScheduledList } from "../components/list/DraftsList";
import { Icon } from "../components/Icon";
import { InstallAppEntry } from "../components/InstallApp";
import { MessageList } from "../components/list/MessageList";
import { Resizer } from "../components/Resizer";
import { ThemeToggle } from "../components/ThemeToggle";
@@ -34,6 +35,7 @@ import { useT } from "../i18n";
import type { MessageKey } from "../i18n/en";
import { api, isOfflineError } from "../lib/api";
import { clearOfflineData, useOffline } from "../lib/offline";
import { disablePush, setAppBadge } from "../lib/push";
import { flushLocal, useLocalMessages, wipeLocal } from "../lib/scheduled";
import { formatClock, getDateLocale, setTimeFormat } from "../lib/timeFormat";
import type { AccountOut, QuotaOut, SavedSearch, ThreadSummary } from "../lib/types";
@@ -283,6 +285,11 @@ export function MailLayout() {
}, [timeFormat]);
const quotaQuery = useQuery({ queryKey: ["quota"], queryFn: api.quota });
const countsQuery = useQuery({ queryKey: ["folder-counts"], queryFn: api.folderCounts });
// The installed app's icon shows unread Inbox mail (notifications set it too).
const inboxUnread = countsQuery.data?.inbox_unread;
useEffect(() => {
if (inboxUnread !== undefined) setAppBadge(inboxUnread);
}, [inboxUnread]);
// Folder/inbox views paginate server-side with an accurate grand total; search
// results (a single fetched page of hits) still paginate client-side.
@@ -985,6 +992,7 @@ export function MailLayout() {
<Icon name="settings" size={22} />
{!collapsed && t("nav.settings")}
</Link>
{mobile && <InstallAppEntry onDone={() => setDrawerOpen(false)} />}
<button
className={`wm-online-only flex w-full items-center gap-2.5 rounded-lg py-2 text-left text-app-muted hover:bg-app-hover hover:text-app-fg ${
collapsed ? "justify-center px-0" : "px-3"
@@ -994,6 +1002,7 @@ export function MailLayout() {
// Anything still waiting in Scheduled goes out first: what is
// kept on this device is wiped with the session.
await flushLocal().catch(() => []);
await disablePush(); // while still signed in, so the server forgets this device
await api.logout();
await clearOfflineData();
await wipeLocal();