tauri: [bug] Notifications not working in MacOS
Describe the bug
I’m using Tauri with Svelte on a MacOS. But I’m having trouble with the notification module.
All Tauri APIs are allowlisted in tauri.conf.json.
The code below runs and prints permissionGranted as true but the sendNotifications seem to have no effect.
const notify = async () => {
let permissionGranted = await isPermissionGranted();
if (!permissionGranted) {
const permission = await requestPermission();
permissionGranted = permission === "granted";
}
if (permissionGranted) {
sendNotification("Tauri is awesome!");
sendNotification({ title: "TAURI", body: "Tauri is awesome!" });
console.log(permissionGranted);
}
}
notify();
I also tried using the Notifications API in the Tauri console itself but nothing happens and the created Notification object has no properties.
Notification.permission; // "granted"
const n = new Notification("New Message", { body: "hello" }); // {} empty object
Reproduction
npm create tauri-appand initiate with Svelte.cdinto directory andnpm install.- Add in notifications logic to script.
npm run tauri dev.- Notifications are not sent.
Expected behavior
Notification sent to MacOS.
Platform and versions
Environment › OS: Mac OS 12.4.0 X64 › Node.js: 17.2.0 › npm: 8.13.2 › pnpm: 6.11.0 › yarn: 1.22.15 › rustup: 1.25.1 › rustc: 1.62.0 › cargo: 1.62.0 › Rust toolchain: stable-x86_64-apple-darwin
Packages › @tauri-apps/cli [NPM]: 1.0.5 › @tauri-apps/api [NPM]: 1.0.2 › tauri [RUST]: 1.0.5, › tauri-build [RUST]: 1.0.4, › tao [RUST]: 0.12.2, › wry [RUST]: 0.19.0,
App › build-type: bundle › CSP: unset › distDir: …/public › devPath: http://localhost:8080/ › framework: Svelte › bundler: Rollup
Stack trace
No response
Additional context
tauri.conf.json
{
"$schema": "../node_modules/@tauri-apps/cli/schema.json",
"build": {
"beforeBuildCommand": "npm run build",
"beforeDevCommand": "npm run dev",
"devPath": "http://localhost:8080",
"distDir": "../public"
},
"package": {
"productName": "d",
"version": "0.1.0"
},
"tauri": {
"allowlist": {
"all": true
},
"bundle": {
"active": true,
"category": "DeveloperTool",
"copyright": "",
"deb": {
"depends": []
},
"externalBin": [],
"icon": [
"icons/32x32.png",
"icons/128x128.png",
"icons/128x128@2x.png",
"icons/icon.icns",
"icons/icon.ico"
],
"identifier": "com.tauri.dev",
"longDescription": "",
"macOS": {
"entitlements": null,
"exceptionDomain": "",
"frameworks": [],
"providerShortName": null,
"signingIdentity": null
},
"resources": [],
"shortDescription": "",
"targets": "all",
"windows": {
"certificateThumbprint": null,
"digestAlgorithm": "sha256",
"timestampUrl": ""
}
},
"security": {
"csp": null
},
"updater": {
"active": false
},
"windows": [
{
"fullscreen": false,
"height": 600,
"resizable": true,
"title": "d",
"width": 800
}
]
}
}
package.json
{
"name": "tauri-notification-test",
"version": "1.0.0",
"private": true,
"scripts": {
"build": "rollup -c",
"dev": "rollup -c -w",
"start": "sirv public --no-clear",
"tauri": "tauri"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^17.0.0",
"@rollup/plugin-node-resolve": "^11.0.0",
"@tauri-apps/cli": "^1.0.5",
"rollup": "^2.3.4",
"rollup-plugin-css-only": "^3.1.0",
"rollup-plugin-livereload": "^2.0.0",
"rollup-plugin-svelte": "^7.0.0",
"rollup-plugin-terser": "^7.0.0",
"svelte": "^3.0.0"
},
"dependencies": {
"@tauri-apps/api": "^1.0.2",
"sirv-cli": "^2.0.0"
}
}
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 3
- Comments: 16 (4 by maintainers)
@Kakamotobi @FabianLars
After my attempts (env : MacOS 11.4 , Apple Silicon M1), I found that this API cannot work on dev mode, but the production environment behaves normally.
Locate the source code and find possible reasons is: if we have
feature = "custom-protocol"then we use the app’s identifier,otherwise use system’s identifier(I’m not sure if that’s right?)BUT the keypoint is:
(attach the successful pictrue like this…)
@Moon1102 Nice. Thanks for letting me know. I just checked and yes, the notifications are working as expected in production.
In my case, notifications work in dev mode (though I haven’t been able to figure out how to get sounds working) and they show up as coming from Terminal.
With prod builds, they seemingly didn’t work at all but then I noticed that some of the notifications showed way later when a notification from another app arrived. This made me check the notification center and there I saw all of the notifications I sent. Meaning, they didn’t show up on the screen, they went directly into the notification center. Without any DND/focus mode enabled.
I then went into the notification settings for the app and changed the style from Banners to Alerts, and that did make the notifications appear on the screen. They need to be manually dismissed, but at least they show up.