📜  windows 10 toast 通知 nodejs - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:01:51.059000             🧑  作者: Mango

代码示例1
// use node notifier -> https://www.npmjs.com/package/node-notifier
// npm install node-notifier

const WindowsToaster = require('node-notifier').WindowsToaster; // import the module node-notifier.windowsToaster

// declare the notifier 

var notifier = new WindowsToaster({
    withFallback: false, // Fallback to Growl or Balloons?
    customPath: "Relative" // Relative/Absolute path if you want to use your fork of SnoreToast.exe
});

// send notification, accept javascript objects

notifier.notify({
    title: `hello world`, // the title
    message: `annoying popup`, // the message below the title
    icon: path.join(__dirname, "avatar.png") // optional: the icon
})

// listen to when the user click on the notification
notifier.on("click", (window) => {
    // enter here the script that will execute when someone clicks on the notification
    const { exec } = require("child_process");
    exec(`cd C:\\Program Files (x86)\\Google\\Chrome\\Application && chrome.exe https://c.tenor.com/RvBPEdvCqHkAAAAd/social-credit.gif`)
})