fix(desktop): stop treating the Windows notification shim's startup "denied" as final - #7275
Open
Jakub-tupy wants to merge 1 commit into
Open
Jakub-tupy wants to merge 1 commit into
Jakub-tupy wants to merge 1 commit into
Conversation
…denied" as final On Windows, tauri-plugin-notification's init script replaces `window.Notification` with a shim and then decides the initial permission by comparing its own freshly initialised "default" against "granted" instead of asking the backend. The comparison is always false, so every launch stamps `permission = "denied"` without any OS decision behind it. Buzz trusted that value: the settings card showed "Desktop notifications are blocked. Enable them in your system settings.", `requestPermission()` was never called (the hooks only request from "default"), no toast was ever sent, and Windows never listed the app under Settings > Notifications. Reinstalling cannot help because the value is recomputed on each start. The desktop backend grants unconditionally on every platform, so a shim "denied" carries no information on Windows. Report it as "default" there: the existing auto-request in `use-feed-desktop-notifications` (and the settings toggle) then call `requestPermission()`, which the shim answers by writing the backend's real "granted" into its cached state. Linux/macOS and non-Tauri browsers are untouched — a real "denied" stays authoritative. Adds `isWindowsPlatform()` (anchored so "Darwin" never matches) and a regression test against the production seam; the Windows case fails without the guard. Fixes block#2445 Signed-off-by: Jakub Tupý <melltupy@gmail.com>
🔐 Codex Security Review
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
On Windows, desktop notifications could never be enabled: the Notifications settings card always showed "Desktop notifications are blocked. Enable them in your system settings.", the toggle snapped back off, and Buzz never appeared under Windows Settings → Notifications.
Root cause is in the
window.Notificationshim thattauri-plugin-notification(2.3.3, unchanged in 2.4.0) injects at startup. On Windows only, itsisPermissionGranted()takes a shortcut that compares the shim's own freshly-initialised"default"against"granted"instead of asking the backend — always false — and stampspermission = "denied"on every launch. Buzz trusted that value, sorequestPermission()was never called (the hooks only request from"default"), no toast was ever sent, and Windows never registered the app. Reinstalling cannot help because the value is recomputed on each start.The desktop backend grants unconditionally on every platform, so a shim
"denied"carries no information on Windows. This PR reports it as"default"there. The existing auto-request inuse-feed-desktop-notifications(and the settings toggle) then callrequestPermission(), which the shim answers by writing the backend's real"granted"into its cached state. Linux/macOS and non-Tauri browsers are untouched — a real"denied"stays authoritative.Changes:
shared/lib/platform.ts: addisWindowsPlatform()(anchored^winso"Darwin"never matches).notifications/lib/desktop.ts:getDesktopNotificationPermissionState()treats a Windows shim"denied"as"default", with the reasoning documented inline.notifications/lib/desktopWindowsPermission.test.mjs: regression test bound to the production seam — the Windows case fails without the guard; Linux and browser (non-Tauri) cases pin that"denied"stays"denied"there.Related issue
Fixes #2445 (same diagnosis, reporter offered a PR but none was opened).
Testing
desktopunit tests forfeatures/notifications/**andshared/lib/*: 422 passed. Removing the guard makes the new Windows test fail (verified).tsc --noEmitclean, Biome clean,check:px-textclean.notificationsentry inpermission_actions, and Buzz is absent from Windows' per-app notification list — consistent with the shim never asking the OS. Not yet verified end-to-end with a rebuilt Windows binary; happy to do so if a maintainer can point me at the Windows build recipe used for the alpha installers.