Skip to content

fix(notify): Rust-side unread toast fallback where the page never notifies - #24

Open
karem505 wants to merge 1 commit into
masterfrom
fix/issue-3-notify-fallback
Open

fix(notify): Rust-side unread toast fallback where the page never notifies#24
karem505 wants to merge 1 commit into
masterfrom
fix/issue-3-notify-fallback

Conversation

@karem505

Copy link
Copy Markdown
Owner

Closes #3 (Windows toasts never appearing on installs where the page never notifies).

Root cause (from the existing diagnostics)

The v0.3.3 file-based diagnostic build already isolated this: on the reporter's Windows 11 install the log showed session start + AUMID registered + SetCurrentProcessExplicitAppUserModelID ok, but no commands::notify line ever appeared when messages arrived — while a standalone PowerShell toast for our AUMID rendered fine. Two users confirmed still broken in v0.6.2/v0.6.3.

Conclusion: on some installs WhatsApp Web never calls window.Notification nor ServiceWorkerRegistration.prototype.showNotification (our two shimmed paths). The failure is upstream of the OS toast layer, and a page-injected script cannot reach the service worker's own context — so no amount of JS shimming can fully cover it.

What this PR does

Drives a toast from Rust using the one signal WhatsApp always updates: the unread count in the document <title>, already forwarded by bridge.js via set_unread on every change (plus a 2s poll).

  • set_unread: when an account's unread count rises, raise a Rust-side toast. Body is a generic count ("You have N unread messages.") — this layer never sees message content, so the no-PII rule holds.
  • notify (the page-driven path) now calls record_shim_notify(label); the fallback stays silent for 10s after any page-driven toast, so installs where the JS path works never see double toasts.
  • Additional gates mirroring commands::notify: suppressed while app-locked, when notifications are disabled, and when the account window is visible and focused. A same-count repeat within 90s is suppressed (title re-polls/re-renders).
  • Attribution matches the existing rule (account-name prefix with multi-account).

Verification

  • cargo test --lib: 85 passed (2 new constant-sanity tests)
  • bridge.js drop-injector tests + settings-ui hotkey/dialog tests all pass (no JS changes here, CI gate confirms)
  • The shim path itself is untouched; installs where notifications already work see zero behavior change.

Known limitation (documented in code)

The fallback knows that messages arrived (count), not who sent them, so its body is generic. On installs where the page's JS path works, real-content toasts continue to come from the shim. Fully content-rich toasts on broken installs would need the service-worker context, which a page-injected script cannot reach — happy to explore a dedicated injection route if this fallback proves the toast layer works on the affected machines.

Feedback from reporters on affected Windows 11 machines is what actually validates this — requesting it in the issue.

…age never notifies (#3)

The v0.3.3 diagnostic build proved that on some Windows 11 installs
WhatsApp Web never calls window.Notification NOR
ServiceWorkerRegistration.showNotification (log: session start + AUMID
registered, but no `commands::notify` when messages arrive), so the
JS-driven path silently produces no toast. A page-injected script cannot
reach the service worker's own context, so the fallback must live in Rust.

- set_unread: detect unread-count rises from the <title> and raise a
  Rust-side toast (count only, generic body — no PII)
- notify: record_shim_notify() marks a page-driven toast so the fallback
  stays quiet for 10s (SHIM_GRACE) — no double toast for the same message
- maybe_unread_toast gates: app locked -> suppress; notifications
  disabled -> suppress; account window focused -> suppress; shim fired
  within grace -> suppress; same count within 90s -> suppress
- attribution + logging follow the existing no-PII dlog rules
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Notification Doesn't Appear

1 participant