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: how to disable native and use "chrome"-style instead? #5299

Closed
importnil opened this issue Apr 26, 2016 · 7 comments
Closed

Comments

@importnil
Copy link

  • Electron version: 0.37.7
  • Operating system: Windows 10

So that's pretty much the whole question in topic.

Currently I got the notification system built in my app that's being opened as an external URL, but this way I don't know how to handle on click events (so when the window is hidden it's shown up when clicked on) - since the code is in the app, not main.js.

Also, is it possible to disable sounds for native notifications and use HTML5 audio api instead, custom sounds?

Sorry, I'm new to Electron.

@MarshallOfSound
Copy link
Member

MarshallOfSound commented Apr 26, 2016

Currently I got the notification system built in my app that's being opened as an external URL, but this way I don't know how to handle on click events (so when the window is hidden it's shown up when clicked on) - since the code is in the app, not main.js.

This doesn't make much sense to me, can you rephrase? This might be relevant https://developer.mozilla.org/en-US/docs/Web/API/Notification/onclick

Also, is it possible to disable sounds for native notifications and use HTML5 audio api instead, custom sounds?

Silent Notification --> https://developer.mozilla.org/en-US/docs/Web/API/Notification/silent
Custom Sounds --> https://developer.mozilla.org/en-US/docs/Web/API/notification/sound

@importnil
Copy link
Author

As for the first question, I've already managed to handle onclick event through IPC messages. I needed to call show() event on browser window if it's minimized, by clicking on a notification (the code from renderer can't call the code from main so...). Didn't find a better solution.

As for sounds, great! I'll test it out.

@MarshallOfSound
Copy link
Member

IPC messages would probably be the best way to go. There are however methods such as

require('remote').getCurrentWindow().show();

Which will work if the window you want to show is the window that launched the notification.

Or if the window you want to show is stored as a global variable in the main process you can call

require('remote').getGlobal('variableName').show();

@importnil
Copy link
Author

importnil commented Apr 26, 2016

Thanks.

Seems like custom sounds aren't supported yet in Windows? Cause again it's an HTML5 API that's noted in docs only is supported from renderer. I tried declaring the sound path in different ways, didn't work.

@MarshallOfSound
Copy link
Member

Check if it is supported in the latest Chrome

@importnil
Copy link
Author

Ok I'm blind, "sound" property doesn't work in Chrome as stated on that page, but silent - works. So I've disabled the system's notification sound and just went with audio.play(). Flawless!

@zcbenz
Copy link
Member

zcbenz commented Apr 27, 2016

On the original question, we only implemented native notifications, and we don't have plan to port the chrome-style one.

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

3 participants