feat(electron): native notification bridge over contextBridge/IPC

Phase 1 step 3 of VNCprodbuild. electron/preload.ts's contextBridge now
exposes window.vnc.showNotification(title, options), routed via
ipcRenderer.invoke("vnc:show-notification") to a new ipcMain.handle in
electron/main.ts that calls Electron's own Notification API. This is the
desktop shell's native notification path - it sits alongside, not in place
of, the browser/PWA's service-worker push path (public/sw.js's push/
notificationclick handlers + lib/web-push.ts), which is untouched.

lib/electron-bridge.ts gives the renderer a `isElectronShell()` +
`showElectronNotification()` wrapper so app code can detect the shell and
use the native path instead of/alongside SW push - not wired to any real
mail-delivery trigger yet, that's Phase 1 steps 4-6 (JMAP realtime
capability investigation, the background/foreground strategy decision, and
implementing it).

Extended e2e/electron-smoke.spec.ts to prove the IPC plumbing actually
fires end-to-end: calls window.vnc.showNotification from the renderer and
asserts the round-trip resolves (not that a real OS toast appears - not
observable in CI). Verified locally: the call resolves {"shown":true} on
this machine, confirming it genuinely reaches Electron's Notification API
and back, not just that window.vnc exists.

Also fixes a real bug caught by this step's typecheck: the smoke test's
Playwright Page variable was named `window`, shadowing the DOM global
inside every evaluate() callback and silently breaking their types. Renamed
to `appWindow`.

All 4 smoke-test assertions green: npm run build:electron && npm run
test:electron.
This commit is contained in:
Bernd Rodler
2026-08-04 12:48:30 +02:00
parent 9254a7fa20
commit b8f668d25a
4 changed files with 134 additions and 12 deletions
+34 -6
View File
@@ -19,7 +19,11 @@ const projectRoot = path.resolve(__dirname, '..');
test.describe('Electron desktop shell', () => {
let electronApp: ElectronApplication;
let window: Page;
// Named `appWindow`, not `window` - the latter would shadow the DOM
// global inside every `appWindow.evaluate(() => window...)` callback
// below, silently breaking their typing (evaluate() callbacks run in the
// browser context, where `window` must resolve to the DOM global).
let appWindow: Page;
const pageErrors: Error[] = [];
test.beforeAll(async () => {
@@ -38,11 +42,11 @@ test.describe('Electron desktop shell', () => {
},
});
window = await electronApp.firstWindow();
window.on('pageerror', (error) => {
appWindow = await electronApp.firstWindow();
appWindow.on('pageerror', (error) => {
pageErrors.push(error);
});
await window.waitForLoadState('domcontentloaded');
await appWindow.waitForLoadState('domcontentloaded');
});
test.afterAll(async () => {
@@ -52,11 +56,35 @@ test.describe('Electron desktop shell', () => {
test('boots the standalone server and renders the login screen', async () => {
// Same selectors as e2e/login.spec.ts's browser-based check - the
// shell should render the identical login form, not a different view.
await expect(window.locator('input[type="text"]')).toBeVisible({ timeout: 20000 });
await expect(window.locator('input[type="password"]')).toBeVisible();
await expect(appWindow.locator('input[type="text"]')).toBeVisible({ timeout: 20000 });
await expect(appWindow.locator('input[type="password"]')).toBeVisible();
});
test('exposes the contextBridge API to the renderer', async () => {
const isElectron = await appWindow.evaluate(() => window.vnc?.isElectron);
expect(isElectron).toBe(true);
});
test('produces zero uncaught page errors', () => {
expect(pageErrors).toEqual([]);
});
test('the native notification bridge round-trips through IPC', async () => {
// Not asserting a real OS toast appears - that isn't observable in CI
// (headless runners/CI accounts routinely have no notification
// permission, and Notification.isSupported() can legitimately be
// false). What matters is that window.vnc.showNotification (exposed by
// electron/preload.ts's contextBridge) actually reaches the main
// process's ipcMain.handle("vnc:show-notification", ...) and resolves -
// proving the renderer -> preload -> main -> Electron Notification API
// plumbing is wired, not just that `window.vnc` exists.
const result = await appWindow.evaluate(async () => {
return window.vnc?.showNotification('Electron smoke test', {
body: 'IPC round-trip check',
});
});
expect(result).toBeDefined();
expect(typeof result?.shown).toBe('boolean');
});
});