diff options
| author | Adam Soltys <[email protected]> | 2026-08-01 18:47:47 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2026-08-01 18:47:47 -0700 |
| commit | 2a7a825ce5850a2a836effae820adbae0b66d093 (patch) | |
| tree | c0c4d07d1be9995921382c7d7d41e1ae6e5abd61 | |
| parent | cbc3a5907c55c20c248fa80fa14528cb483688ad (diff) | |
| download | coinosv3-2a7a825ce5850a2a836effae820adbae0b66d093.tar.gz coinosv3-2a7a825ce5850a2a836effae820adbae0b66d093.zip | |
Refresh the push-notifier registration whenever connections change
The notifier only wakes a device for service pubkeys it was told about
at registration time, so recreating a connection silently killed
background wake-ups — the registration kept watching the revoked key
forever. Re-register (debounced; the server replaces by endpoint) on
init, create, revoke, and sync-merge whenever background alerts are on.
Co-Authored-By: Claude Fable 5 <[email protected]>
| -rw-r--r-- | src/features/nwc.js | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/src/features/nwc.js b/src/features/nwc.js index adafb06..51c0fd6 100644 --- a/src/features/nwc.js +++ b/src/features/nwc.js @@ -122,6 +122,7 @@ export function nwcFeature(ctx) { try { wallet.saveCache(); } catch {} // share it with the user's other devices publishInfo(c).catch(() => {}); listen(); + refreshRegistration(); // the notifier must learn the new service pubkey return c; } @@ -170,6 +171,7 @@ export function nwcFeature(ctx) { st.conns = merged; save(st); listen(); + refreshRegistration(); // connection set changed under us via sync render(); }, }); @@ -451,6 +453,31 @@ export function nwcFeature(ctx) { return true; } + // Keep the notifier's view of our service pubkeys current. It can only + // wake this device for connections it was told about, and a registration + // made before a connection existed (or after one was revoked) watches the + // wrong keys — background wake-ups silently die the first time a + // connection is recreated. Debounced; the server replaces by endpoint. + let regTimer = null; + function refreshRegistration() { + if (!load().background) return; + if (typeof navigator === 'undefined' || !('serviceWorker' in navigator)) return; + clearTimeout(regTimer); + regTimer = setTimeout(async () => { + try { + const reg = await navigator.serviceWorker.ready; + const sub = await reg.pushManager.getSubscription(); + if (!sub) return; + const list = conns(); + if (!list.length) return; + await fetch(`${NOTIFIER}/register`, { + method: 'POST', headers: { 'content-type': 'application/json' }, + body: JSON.stringify({ subscription: sub.toJSON(), servicePubkeys: list.map((c) => c.servicePk) }), + }); + } catch (e) { console.warn('nwc: notifier re-register failed', e.message); } + }, 1500); + } + async function disableBackground() { try { const reg = await navigator.serviceWorker.ready; @@ -533,6 +560,7 @@ export function nwcFeature(ctx) { h('span', {}, c.name), h('span', { class: 'linklike small', onClick: () => { updateConn(c.id, { revoked: true }); listen(); + refreshRegistration(); // stop waking this device for a dead key try { wallet.saveCache(); } catch {} // propagate the revocation render(); toast(t('nwcRevoked', { name: c.name })); @@ -583,7 +611,7 @@ export function nwcFeature(ctx) { return { id: 'nwc', - init() { listen(); startWatchdog(); }, + init() { listen(); startWatchdog(); refreshRegistration(); }, stop() { stop(); if (watchdog) { clearInterval(watchdog); watchdog = null; } }, settingsCards() { return [nwcCard()]; }, }; |
