Electron with node-notifier display windows 10 notification

后端 未结 5 883
灰色年华
灰色年华 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: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.

提交回复
热议问题