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

Add support for Notification Actions (added in Chrome 48) #4424

Closed
bengotow opened this issue Feb 9, 2016 · 9 comments
Closed

Add support for Notification Actions (added in Chrome 48) #4424

bengotow opened this issue Feb 9, 2016 · 9 comments

Comments

@bengotow
Copy link
Contributor

bengotow commented Feb 9, 2016

It would be really great if Electron supported the "notification actions" feature added in Chrome 48:

https://www.chromestatus.com/features/5906566364528640
https://developers.google.com/web/updates/2016/01/notification-actions?hl=en

Essentially, you say:

new Notification("123", {title: "123", silent: true, actions: [{action: 'A', title: 'A'}, {action: 'B', title: 'B'}]})

To show the notification, and then listen for 'notificationclick' DOM event, which gives you the name of the chosen action.

@bengotow
Copy link
Contributor Author

bengotow commented Feb 9, 2016

It's worth noting that the Chromium implementation uses their own notification UX and not the system notification center. Mac OS X has the equivalent of notification actions (up to two actions), so the existing API could be mapped onto Mac OS X. I'm not sure about other platforms!

image

@anaisbetts
Copy link
Contributor

@bengotow:

Windows 10: Yes
Windows 8: No
Windows 7: lol
Unity (i.e. Ubuntu): No
non-Unity (i.e. Fedora): Yes

Also, totally into this idea

@felixrieseberg
Copy link
Member

I'm also super into this, but I'd say that the implementation on both OS X and Windows is not trivial. For starters, the Windows 10 UWP Notification API is super rich and can do all kinds of fancy things, but it doesn't use callbacks, but instead activation arguments (which is cool, because one can launch other apps via notification, but the model makes it hard to implement in Electron). Good news: Code is available.

On OS X, things are a little bit less difficult, but still annoying (the model is super-limiting, as @bengotow already pointed out). However, if we conform to the limits, a callback is fairly simple: We already ask the userNotificationCenter for the activation; and the notification object has a activationType property. The whole thing is a bit silly, but simple enough - it's basically 'that one action clicked' or 'that other action clicked' ;-)

Basically, if somebody wants to have a coffee/beer session with me (Nylas? Slack? GitHub?), we could probably hack this out in three hours or so.

@bengotow
Copy link
Contributor Author

Hey! I've started playing with this, and it looks like it may be more of a mess than I imagined. I was able to add a libchromiumcontent patch to remove an assertion which blocked calls to new Notification... with an actions array, and extend brightray to display Mac OS X notifications with the action titles:

image

It looks like we may be blocked on the event-handling side, though. Chromium calls PlatformNotificationService.DisplayNotification with an instance of content::DesktopNotificationDelegate, not the (way more robust) message_center::NotificationDelegate. It looks like the notifications API is unified on the JavaScript side but platform notifications and the "message center" are disconnected concepts?

Any ideas? I'm just beginning to source-dive Chromium so I may be wrong—I haven't traced far enough back to see where they become separated. Haha @felixrieseberg I think some beers might definitely be in order...

One other caveat I discovered:

On Mac OS X, notifications with actions are "Alerts", which are sticky. To show "Alert"-style notifications, the app needs to be code-signed and include an item in it's Info.plist. Beyond being a bit of a pain, this means that effectively re-producing native behaviors might require additional APIs for programmatically dismissing notifications, which I don't think exist.

@aluxian
Copy link

aluxian commented Apr 17, 2016

@bengotow If it helps, this is how I currently display native notifications on OS X (using nodobjc): https://github.com/Aluxian/Whatsie/blob/master/src/scripts/browser/components/native-notifier/impl-darwin.js

@koush
Copy link

koush commented Aug 24, 2016

Ah, I'd like this as well!

I attempted to get the serviceworker APIs working on electron, but notifications from a service worker do not show up.

Alternatively, chrome APP platform implements chrome.notifications.create (which allows actions), and may be worth looking at. Not sure if that is implemented differently from the serviceworker.newNotification.

@davies147
Copy link

"I attempted to get the serviceworker APIs working on electron, but notifications from a service worker do not show up."

+1

Even if it could fall-back to the standard Notification system, it would be helpful?

@codebytere
Copy link
Member

Closing with merge of @sethlu's above PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants