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

Override and display our own notification #4

Open
sujithv28 opened this issue Jul 1, 2016 · 15 comments
Open

Override and display our own notification #4

sujithv28 opened this issue Jul 1, 2016 · 15 comments

Comments

@sujithv28
Copy link

Can we do something like event.preventDefault() and then create our own notification to display with the msg parameter?

The main reason I want to do this is because I want to detect when the user taps on the notification so I can redirect to a different URL and unhide the app.

@seriema
Copy link
Owner

seriema commented Jul 4, 2016

Something like PR #3 ?

@sujithv28
Copy link
Author

Exactly, what would the code for that look like?

@seriema
Copy link
Owner

seriema commented Jul 5, 2016

Not sure, since I asked for documentation samples but haven't received any. I'll try to look at creating some myself soon.

@sujithv28
Copy link
Author

@seriema did you or anyone have any success implementing this in code?

@seriema
Copy link
Owner

seriema commented Jul 14, 2016

Honestly, I haven't tried yet. I'll try to do it soon.

@sujithv28
Copy link
Author

@seriema any luck?

@akashnimare
Copy link

@sujithv28 Did you mean override or hide the native notifications and then show them with your own styling?

@sujithv28
Copy link
Author

sujithv28 commented Jul 31, 2016

@akashnimare I mean override the notifications so I could add an on-click listener which currently isn't supported.

@sujithv28
Copy link
Author

@akashnimare @seriema Any updates on when this feature will be pushed?

@akashnimare
Copy link

Not yet.

@seriema
Copy link
Owner

seriema commented Aug 12, 2016

@sujithv28 you mean a click handler on the native event? Or on the Electron side? I think I could use some fake sample code of what you imagine you'd like to do, or at least some pretend screenshots/images.

@sujithv28
Copy link
Author

sujithv28 commented Aug 12, 2016

@seriema So lets say the website you loaded in electron receives an HTML5 notification. As intended, the notification-shim will intercept that and send out a native notification on the Mac with the content of the HTML5 notification sent from the web. The problem is, since that notification object is created by the notification-shim and we have no way of accessing it, I cant add a "onclick" listener to it to know when it was clicked on, or have an option to override it.

@seriema
Copy link
Owner

seriema commented Aug 21, 2016

@sujithv28 Sorry for the long delay on this. I've experimented with this and the PR #3. The problem is that adding a click handler to Notification is usually done by just assigning a method to the notification object, like this: notification.onclick = function () .... Since electron-notification-shim overrides the constructor any onclick handler it adds will be replaced immediately after. I did a sample branch for you to try if you'd like. Maybe you have some ideas?
https://github.com/seriema/electron-notification-shim/tree/notification-onclick-issue
(Check the last commit. Currently 5e3abfe)

Using a setTimeout would only solve some cases. If you control your web app then you can opt to attach an event handler instead of overriding onclick, but as a library I need to consider more cases. Thoughts?

The same goes for sending an ipc event. We need to override onclick to do that.

@sujithv28
Copy link
Author

sujithv28 commented Aug 25, 2016

@seriema What about supporting something like event.preventDefault() so we can choose when and when not to actually present the notification. By muting notification-shim from creating its own notification object and presenting it, I can create my own locally using the msg contents and add a listener on my side as well.

@seriema
Copy link
Owner

seriema commented Aug 27, 2016

@sujithv28 The notification goes out the moment it's created (new Notification()). The second parameter is the options (MDN) and it has things like silent. What I could do is that you can pass a setting to electron-notification-shim that will basically remove all native notifications so that you can use your own. Not sure yet how it would be nicely implemented. It does go beyond being a shim so I'm wondering if that wouldn't be better done in another library. My goal has always been for a "plug and play" approach for apps that have notifications working in Electron but want to support Windows.

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