I\'m trying to make a simple app that should display notification when button is clicked. The problem is that the notification does not show, but console.logs are showing. S
I've also tried many things, but sometimes it works or not.
At last, I've found a way. This works well for not only "npm run dev", but also package built.
register app id at package.json
"build": { "appId": "my app id", ...
call app.setAppUserModelId("my app id") at main process (https://electronjs.org/docs/api/app#appsetappusermodelidid-windows)
Here app id can be any type of string.
You can do this, it works for me even on windows 10.
"build": {
"appId": "your.custom.app.id",
}
app.setAppUserModelId("your.custom.app.id");
This error doesn't need any configuration all you have to do is go to your setting and enable notification Because in some cases on your computer you just switched off notifications.
System Setting ->Notification & Actions
Then turn on Notification By clicking the switch (problem solved)
You don't need to use IPC and send notifications from the main process, this is supported from the renderer process using the HTML5 notification API.
let myNotification = new Notification('Title', {
body: 'Lorem Ipsum Dolor Sit Amet'
})
myNotification.onclick = () => {
console.log('Notification clicked')
}
I've got it working now, thanks to all the people here :) https://github.com/mikaelbr/node-notifier/issues/144#issuecomment-319324058
Based on anthonyraymond
's comment, you need to have your app INSTALLED
in your windows machine with an appId. You can configure appId
in your package.json
like this.
{
"name": "myapp",
"version": "1.0.0",
"description": "test",
"main": "main.js",
"build": {
"appId": "com.myapp.id"
}
}
The appId
does not need to have that java/android
format, my app just have an appId
of elite-notifier
.
Then you can pass the appId
when calling the notify
function of notifier.
notifier.notify(
{
appName: "com.myapp.id", <-- yes, the key here is appName :)
title: "Hello",
message: "Hello world!",
wait: true
},
function(err, response) {
// Response is response from notification
console.log("responded...");
}
);
After installation, This will work even on development mode (by running electron .
command) provided that you'll not change the appId
of your app after installation since there will be a mismatch on the installed one and the development version of the app.