Skip to content

Commit 4c120d4

Browse files
committed
fix(notification/windows): Grant permission without invoking backend
1 parent 8824a24 commit 4c120d4

File tree

4 files changed

+17
-8
lines changed

4 files changed

+17
-8
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
notification: patch
3+
---
4+
5+
Fixed an issue that caused the `notification` plugin's initialization script to cause the WebView on Windows to throw a `STATUS_ACCESS_VIOLATION` error on remote websites.

plugins/notification/guest-js/init.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,17 @@ import type { Options } from "./index";
1010
let permissionValue = "default";
1111

1212
async function isPermissionGranted(): Promise<boolean> {
13-
if (window.Notification.permission !== "default") {
13+
// @ts-expect-error __TEMPLATE_windows__ will be replaced in rust before it's injected.
14+
if (window.Notification.permission !== "default" || __TEMPLATE_windows__) {
1415
return await Promise.resolve(
15-
window.Notification.permission === "granted",
16+
window.Notification.permission === "granted"
1617
);
1718
}
1819
return await invoke("plugin:notification|is_permission_granted");
1920
}
2021

2122
function setNotificationPermission(
22-
value: "granted" | "denied" | "default",
23+
value: "granted" | "denied" | "default"
2324
): void {
2425
permissionSettable = true;
2526
// @ts-expect-error we can actually set this value on the webview
@@ -31,10 +32,10 @@ import type { Options } from "./index";
3132
"default" | "denied" | "granted" | "prompt"
3233
> {
3334
return await invoke<"prompt" | "default" | "granted" | "denied">(
34-
"plugin:notification|request_permission",
35+
"plugin:notification|request_permission"
3536
).then((permission) => {
3637
setNotificationPermission(
37-
permission === "prompt" ? "default" : permission,
38+
permission === "prompt" ? "default" : permission
3839
);
3940
return permission;
4041
});
@@ -64,7 +65,7 @@ import type { Options } from "./index";
6465
Object.assign(opts, {
6566
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
6667
title,
67-
}),
68+
})
6869
);
6970
};
7071

plugins/notification/src/init-iife.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/notification/src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,10 @@ pub fn init<R: Runtime>() -> TauriPlugin<R> {
227227
commands::request_permission,
228228
commands::is_permission_granted
229229
])
230-
.js_init_script(include_str!("init-iife.js").to_string())
230+
.js_init_script(include_str!("init-iife.js").replace(
231+
"__TEMPLATE_windows__",
232+
if cfg!(windows) { "true" } else { "false" },
233+
))
231234
.setup(|app, api| {
232235
#[cfg(mobile)]
233236
let notification = mobile::init(app, api)?;

0 commit comments

Comments
 (0)