'How to toggle Notification.permission in electron application?
I have developed a desktop application based on electron framework. I have loaded my website inside the browser window. The website will display notifications to the user. In chrome I have an option to request permission from the user to display notification or not. By using Notification.requestPermission() I can display a popup to request permission from the user for notification to display or not.
The same way I need to display the same popup to toggle notification permission from "granted" to "denied".
Suggest me how to enable this feature in electron application.
Solution 1:[1]
From my experience with Electron default browser notifications don't work very well (On some platforms they didn't even send).
Instead I recommend you use a node-js notification package called node-notifier.
I've been using it for about a year now in my Electron app and I would recommend it to all users of Electron.
Node notifier works on every platform and you don't need to ask for permission to send notifications.
Solution 2:[2]
Try and create an empty notification without showing it. This will trigger the permission ask:
//Modules
const { Notification } = require('electron');
//On ready
app.on('ready', () => {
new Notification();
});
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Joshua |
| Solution 2 | Apostol Voicu |
