notify-rust icon indicating copy to clipboard operation
notify-rust copied to clipboard

Notification Listeners for Mac and Windows

Open cheeseblubber opened this issue 1 year ago • 17 comments

Problem

We are building a Slack/Discord like chat client (linen.dev) with Tauri. The problem is we don't have any notification listeners for Mac and windows so that we know which notification they click on so we can show the proper channel/thread.

Describe the solution you'd like

According to this windows and mac listeners are not implemented https://docs.rs/notify-rust/latest/notify_rust/#notificationhandle

Additional context

https://github.com/tauri-apps/tauri/issues/3698

For mac we ran into issue with https://github.com/h4llow3En/mac-notification-sys because was blocking which spiked cpu usage to 100% when we received a notification and it would stay at 100% until we closed the notification.

cheeseblubber avatar Jun 20 '23 15:06 cheeseblubber

💎 $300 bounty created by @cheeseblubber 👉 To claim this bounty, submit your pull request on Algora 📝 Before proceeding, please make sure you can receive payouts in your country 💵 Payment arrives in your account 2-5 days after the bounty is rewarded 💯 You keep 100% of the bounty award 🙏 Thank you for contributing to hoodie/notify-rust!

algora-pbc avatar Jun 20 '23 15:06 algora-pbc

Full Disclaimer: this library can only do what the underlying operating-system primitives actually provide.

hoodie avatar Jun 20 '23 18:06 hoodie

@cheeseblubber can you show what you were doing that cause the 100% CPU usage on macOS? AFAIK the sending should not block already.

hoodie avatar Jun 20 '23 19:06 hoodie

hi @hoodie, this is what we were doing https://github.com/Linen-dev/linen.dev/blob/51406feb8f27c95081d36f4ee2cc9139caec25c0/packages/spa/src-tauri/src/notifications.rs#L29 with was with the mac_notification_sys lib not notify-rust.

CPU went to 100% until we dismiss the notification. This is how we call the function https://github.com/Linen-dev/linen.dev/blob/51406feb8f27c95081d36f4ee2cc9139caec25c0/packages/spa/src-tauri/src/main.rs#L75

This was the only workaround we find to know in which notification the user clicked.

sandrodesouza avatar Jun 20 '23 23:06 sandrodesouza

Windows implementation blocked on this pull request to tauri-winrt-notification, a dependency of notify-rust.

tyush avatar Jun 22 '23 10:06 tyush

/attempt #186 . only macOS.

whizsid avatar Jul 11 '23 19:07 whizsid

mac-notification-sys is using the old foundation user notifications API which deprecated. Updating this crate is a huge change and breaking the BC. So I decided to write a crate by my own using the new User Notifications framework. I hope to manage notifications using a Stream like api. Currently the mac-notification-sys is using a loop to listen for notification changes.

Also the new notification framework is only supporting action buttons for notification categories. But I think we can internally manage those categories without changing the existing API of notify-rust.

UPDATE:- Updating to the new notification framework was already in the TO DO list of mac-notification-sys. So I decided to send a PR instead creating a new crate.

whizsid avatar Jul 12 '23 10:07 whizsid

@whizsid that sounds great. Looking forward to that. I was actually starting to rejuvenate mac-notification-sys a little. But I'm afraid we really ought to implement the new UNNotificationCenter api finally. Since I'm not a very experienced objective-c, nor macOS Desktop developer I appreciate any help and contribution I can get.

hoodie avatar Jul 12 '23 12:07 hoodie

/attempt #186

Rutik7066 avatar Dec 27 '23 12:12 Rutik7066

/attempt

mogery avatar Feb 11 '24 16:02 mogery

Hi, @cheeseblubber Submitted PR.

Rutik7066 avatar Feb 13 '24 04:02 Rutik7066

Is this solved or still open?

vivasvan1 avatar Apr 22 '24 08:04 vivasvan1

still open

hoodie avatar Apr 22 '24 09:04 hoodie

@hoodie i'll look into it for feasiblity and update you.

vivasvan1 avatar Apr 22 '24 12:04 vivasvan1

Looked into this one and it's very hard to do this without uprooting the whole library. For this to work on macOS, we would need to somehow ensure execution on the main thread, which is difficult without knowing whether the dependent project uses Tokio or not. It'd add a whole lot of hassle to using this library.

mogery avatar Apr 22 '24 17:04 mogery

Can we at least document a recommended alternative for Windows and macOS users?

ofek avatar Apr 22 '24 17:04 ofek

@mogery that's why I've avoided tackling this for so long. It's a tiny bit to complex to do on an on/off after-work kind of timeplan. Interestingly enough though it seems like the zed editor's implementation (native macos) might contain some good references on how to interact with the mac runtime in an async fashon.

hoodie avatar Apr 22 '24 18:04 hoodie