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

Notifications do not display #33

Open
PfisterFactor opened this issue Jan 13, 2022 · 20 comments
Open

Notifications do not display #33

PfisterFactor opened this issue Jan 13, 2022 · 20 comments

Comments

@PfisterFactor
Copy link

PfisterFactor commented Jan 13, 2022

I made a minimal test program from one of the examples:

# Cargo.toml
[dependencies]
mac-notification-sys = "0.3"
// main.rs
use mac_notification_sys::*;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    set_application("com.apple.Terminal")?;

    send_notification(
        "Danger",
        &Some("Will Robinson"),
        "Run away as fast as you can",
        &None,
    )?;

    Ok(())
}

Running the program doesn't produce a notification, on both debug and release mode. It does not crash.
I'm on a M1 Macbook Pro (2021, 14-inch) on MacOS Monterey with Rust 1.58.
Compiling on stable-aarch64-apple-darwin or stable-x86_64-apple-darwin produces the same results.

@PfisterFactor
Copy link
Author

PfisterFactor commented Jan 13, 2022

I saw this issue #10 and tried testing it with https://github.com/Pandawan/mac-notification-sys/tree/usernotifications and got the same result.

[dependencies]
mac-notification-sys = { git = "https://github.com/Pandawan/mac-notification-sys.git", branch= "usernotifications" }

@Pandawan
Copy link
Contributor

Haven’t looked into your issue specifically, but the repo I linked in #10 (which you mentioned above) isn’t finished and still uses old notification system for the out-facing API.

(i.e. the behavior should be the same between the two right now).

@Pandawan
Copy link
Contributor

Pandawan commented Jan 17, 2022

Hmmm, strange, the code you sent works fine for me on my Intel Macbook Pro (2019, 13-inch) on macOS Monterey 12.1 with Rust 1.58 (stable-x86_64-apple-darwin).

It seems like the only difference between our two cases is the M1 vs Intel, but I don't think the Notification API should be affected by this. Could you make sure that you don't have notifications disabled for terminal, or some kind of setting that could block notifications? If not this, I'm not sure how to test/reproduce this issue.

@PfisterFactor
Copy link
Author

Notification

These are my notification settings for both Terminal and iTerm2 (I tried on both these terminal clients). I tried switching the type of notification to alerts to see if that made any difference as well but still no success.

I can get a notification to appear with this command however:
osascript -e 'display notification "hello world!"

@h4llow3En
Copy link
Owner

There are two possible ways why there are no notifications displayed.

  1. Was the notification application in your example the one with "com.apple.Terminal" as an identifier active? If the window is active in foreground no notifications are shown
  2. I have no idea, if m1 still has access to the deprecated NSNotification APIs

@gandaldf
Copy link

gandaldf commented Mar 8, 2022

Same problem as @PfisterFactor, here with a Macbook Pro M1 2021 16" Monteray 12.1 and Rust 1.59.
I enabled everything in my Notification Settings but nothing changed, I can also get a notification runnning osascript -e 'display notification "hello world!"
It doesn't work on a Macbook Pro Intel 2012 15" Catalina 10.15.7 either, so I don't think it something architecture-releated (the osascript also works here).

@Pandawan
Copy link
Contributor

Pandawan commented Mar 9, 2022

Are you sure you are not in Do Not Disturb (or other focus mode)? The notification isn't showing up at all on Notification Center either?

I re-ran the exact code given in a new project with Rust 1.59 and macOS 12.2.1 and have no issues. It's strange that osascript is able to do it but not mac-notification-sys though...

Perhaps we could look into modifying the objc part to have some debugging/logging to see what's happening...

@gandaldf
Copy link

I double checked everything and I think everything is ok... Do Not Disturb isn't active and my Notification Center remains empty.
I just updated MacOS to 12.2.1 and rebooted a couple of times but nothing changed.
I don't know if it helps but I use VSCode and I have not installed XCode... anyway the problems persist even if I run the compiled version.
If you would like to add some logging code I voluteer to test it.

@KSBilodeau
Copy link

KSBilodeau commented Jul 24, 2022

I'm on 12.4 at the moment, and I am also unable to produce any notifications.

My hardware:

Hardware Overview:

  Model Name:	MacBook Pro
  Model Identifier:	MacBookPro15,2
  Processor Name:	Quad-Core Intel Core i7
  Processor Speed:	2.8 GHz
  Number of Processors:	1
  Total Number of Cores:	4
  L2 Cache (per Core):	256 KB
  L3 Cache:	8 MB
  Hyper-Threading Technology:	Enabled
  Memory:	16 GB
  System Firmware Version:	1731.120.10.0.0 (iBridge: 19.16.15071.0.0,0)
  OS Loader Version:	540.120.3~6
  Serial Number (system):	C02ZT04JP4G2
  Hardware UUID:	9678EC89-6B02-50FB-84B6-CA859359FB50
  Provisioning UDID:	9678EC89-6B02-50FB-84B6-CA859359FB50
  Activation Lock Status:	Enabled

rustup show:

Default host: x86_64-apple-darwin
rustup home:  /Users/ksbilodeau/.rustup

installed toolchains
--------------------

stable-x86_64-apple-darwin
nightly-2022-03-23-x86_64-apple-darwin
nightly-x86_64-apple-darwin (default)
nightly-x86_64-unknown-linux-gnu
miri

installed targets for active toolchain
--------------------------------------

x86_64-apple-darwin
x86_64-unknown-linux-gnu
x86_64-unknown-linux-musl

active toolchain
----------------

nightly-x86_64-apple-darwin (default)
rustc 1.64.0-nightly (2f3ddd9f5 2022-06-27)

@h4llow3En
Copy link
Owner

h4llow3En commented Aug 5, 2022

Very strange.

@PfisterFactor were you able to run the examples in this repo? Maybe there is a little more output since they are throwing deprecated warnings all over the place...

Just tried to reproduce this issue again. Your example works fine for me on M1 and Intel...

stable-aarch64-apple-darwin (default)
rustc 1.62.1 (e092d0b6b 2022-07-16)

and

stable-x86_64-apple-darwin (default)
rustc 1.62.1 (e092d0b6b 2022-07-16)

@a5huynh
Copy link

a5huynh commented Mar 16, 2023

For those who are running into this issue as well, pretty sure the issue (at least on macOS 12.0+) is that the NSUserNotificationCenter APIs are deprecated.

My hacky workaround which works on the latest macOS has been to call out to osascript like so:
osascript -e display notification "{body}" with title "{title}"

@Pandawan
Copy link
Contributor

@a5huynh
Although deprecated, the API should still work (macOS must still support older apps). I’m on latest macOS and can get it to work fine.

Still, it’d be nice to figure out what the root of the problem is.

@rstefanic
Copy link

I had the same problem reported here as @PfisterFactor, @a5huynh, @gandaldf, and @KSBilodeau. All of the tests would pass, and I could compile every example just fine. Every example would run without any errors, but I would never get any notifications. The examples would just exit without any errors.

I was running the "sound" example and using Console.app, I traced the problem to a kernel error.

System Policy: usernoted(427) deny(1) file-read-data /Users/robert/Documents/Code/Repositories/mac-notification-sys/target/debug/examples/sound

usernoted is the process responsible for macOS notifications.

According to this, macOS version 10.15 and later introduced additional access control for the Desktop and Documents directory. The problem is that I was running the program from my ~/Documents directory. Once I moved the binary out of the ~/Documents directory, it worked.

If you're compiling and running this in your ~/Documents or ~/Desktop directory, then that may be why it's not working for you.

@a5huynh
Copy link

a5huynh commented Mar 23, 2023

Thanks for digging into that @rstefanic.

Just wanted to confirm that moving the folder outside of Documents did indeed do the trick.

@hoodie
Copy link
Collaborator

hoodie commented Jul 4, 2023

I can now reproduce that notifications don't show on M1/M2 devices. Still not able to pinpoint the issue (only spent about an hour or two at it). My first attempt was using @Pandawan's updated branch and then also playing around with codesigning. So far I no improvement. I'm still totally out of my comfort-zone here so, I can't tell whether there is some minutia to codesigning that I haven't considered yet.
Also moving the binary into my /Applications folder afterward did not do the trick.

@Pandawan
Copy link
Contributor

Pandawan commented Jul 4, 2023

Fwiw, I have been able to get it codesigning and working when using a .app wrapper, but I seem to be unable to add the proper entitlements when embedding the Info.plist directly into the binary. (Or at least they don’t seem to be recognized/accepted)

EDIT: I guess this response belongs more in #10 but w/e

@Pandawan
Copy link
Contributor

Pandawan commented Jul 4, 2023

Anyway, things to check when it’s not working:

  • Are you in do not disturb? Or other focus mode?
  • Did you allow notifications (in Settings) for Terminal/whatever app it shows up as?
  • Is your program stored in a protected directory? (like Documents, Downloads, Desktop, etc.)

If none of these, then I have absolutely no idea

@hoodie
Copy link
Collaborator

hoodie commented Jul 4, 2023

@Pandawan did you ever see it work on an M1/M2 mac?

@Pandawan
Copy link
Contributor

Pandawan commented Jul 4, 2023

I believe some people mentioned it working on M1/M2 but I am still on intel so I can’t verify.

@locustbaby
Copy link

locustbaby commented Mar 1, 2024

@Pandawan did you ever see it work on an M1/M2 mac?

After moving the binary to the ~/ directory, it works.
M1 , os version 14.0

Adding a tip in the README can help save time.

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

No branches or pull requests

9 participants