Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] Notifications not working in MacOS #2143

Open
Kakamotobi opened this issue Aug 17, 2022 · 18 comments
Open

[bug] Notifications not working in MacOS #2143

Kakamotobi opened this issue Aug 17, 2022 · 18 comments
Labels
bug Something isn't working platform: macos macOS specific issues plugin: notification

Comments

@Kakamotobi
Copy link

Kakamotobi commented Aug 17, 2022

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

  1. npm create tauri-app and initiate with Svelte.
  2. cd into directory and npm install.
  3. Add in notifications logic to script.
  4. npm run tauri dev.
  5. 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/[email protected]",
        "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"
  }
}
@Kakamotobi
Copy link
Author

I also tried cloning the tauri api example and tried sending the test notification but doesn't work.

I'm not sure but maybe it has something to do with the fact that I cannot find the folder (named by identifier) in Application Support like $HOME/Library/Application\ Support/com.your.bundleid/.tauri-settings.

I'm not getting any errors. It just doesn't do anything.

@FabianLars
Copy link
Member

The .tauri-settings file doesn't exist anymore, that one was for our own permissions prompt (which lead to duplicate prompts and was therefore removed)

@Kakamotobi
Copy link
Author

Oh ok. Do you have any idea what might be the problem?

Using either the Notification Web API or Tauri's Notification API, the permission is always "granted" for some reason, and requesting permission and sending notification don't do anything.

@FabianLars
Copy link
Member

Nope, the permissions/notifications on macos are generally quite wonky (in a tauri context), and for some reason it seems to be gotten worse in recent tauri versions.
I don't have a mac so i can't really look into it and all the others currently work on mobile support to get people to alpha test asap.

@Kakamotobi
Copy link
Author

I see. I hope this issue also gets handled asap amidst your progressions with tauri. Thanks.

@FabianLars
Copy link
Member

This sounds like the most relevant upstream issue h4llow3En/mac-notification-sys#33

@Moon1102
Copy link

@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...)

图片

@FabianLars
Copy link
Member

Oh! Nice finding!

Can you check in the system permissions settings if you disabled Notifications for the Terminal application?

@Moon1102
Copy link

Sure. I'll try it right away

@Moon1102
Copy link

Moon1102 commented Aug 19, 2022

@FabianLars
图片
It seems that the notification can be triggered without opening the button. After installation, the permission button is closed by default, but the notification can pop up at the first time

@Kakamotobi
Copy link
Author

@Moon1102 Nice. Thanks for letting me know. I just checked and yes, the notifications are working as expected in production.

@HuakunShen
Copy link

Notification doesn't show up for me on Mac recently even in production mode. Did anyone have the same problem?

@yarrichar
Copy link

Yeah, in production mode it popped up with the permission window. But won't displayed any actual notifications.

@zilahir
Copy link

zilahir commented Dec 10, 2023

in production, the notifications are working. however, in dev mode, they are not. quite the bummer.

@stancl
Copy link

stancl commented Jan 17, 2024

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.

@battleoverflow
Copy link

I recently came across this issue on MacOS. It seems when working in dev mode, I'm unable to receive notifications, but once I've built a release or test in production with the proper permissions set, it all works as expected. A quick workaround for this is to run the application within a browser, which does limit some functionality. This is a good way to test notifications in a dev environment without needing to build, but obviously a bug nonetheless.

I assume this is because the notification channel is using the browser's permissions instead of the application's direct permissions, which are correctly configured in this scenario. Not sure how helpful this is, but I wanted to include it here to help with remediation in the future.

@tyfiero
Copy link

tyfiero commented Nov 26, 2024

Has there been any progress on this? Or are we stuck only testing notifications in prod on mac?

@FabianLars
Copy link
Member

FabianLars commented Dec 4, 2024

For those having issues in development. First of all, please make sure that the Terminal has Notification permissions in the OS settings
perms

If that doesn't help, please try the api-example from this repo https://github.com/tauri-apps/plugins-workspace/ so we can check if it's project specific (this repo works on my machine)

Edit: Also for testing, please run tauri dev in the macos native terminal and not some third party terminal.

@FabianLars FabianLars added bug Something isn't working platform: macos macOS specific issues plugin: notification labels Dec 5, 2024
@FabianLars FabianLars transferred this issue from tauri-apps/tauri Dec 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working platform: macos macOS specific issues plugin: notification
Projects
Status: 📬Proposal
Development

No branches or pull requests

9 participants