Electron with node-notifier display windows 10 notification

后端 未结 5 884
灰色年华
灰色年华 2021-01-03 05:56

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

相关标签:
5条回答
  • 2021-01-03 06:14

    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.

    • use Notification at renderer process.
    • 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.

    0 讨论(0)
  • 2021-01-03 06:19

    You can do this, it works for me even on windows 10.

    1. in package.json
     "build": {
     "appId": "your.custom.app.id",
     }
    
    1. in main.js
    app.setAppUserModelId("your.custom.app.id");
    
    0 讨论(0)
  • 2021-01-03 06:20

    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)

    0 讨论(0)
  • 2021-01-03 06:28

    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')
    }
    
    0 讨论(0)
  • 2021-01-03 06:37

    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.

    0 讨论(0)
提交回复
热议问题