Closed5
node-notifier について

目次
docs: https://www.npmjs.com/package/node-notifier
環境
- Windows10
結論
- (簡単に触った所感)Windowsではすぐ通知が消えてしまうため、インタラクティブにデスクトップアプリみたいなものを開発するのには向いてなさそう
- 通知のみで良い、通知を見逃さない自信がある、通知履歴を小まめに確認するという人は向いてそう

Quick Usage
下記画像は、下記コードで出力可能
notification.js
const notifier = require("node-notifier");
// String
notifier.notify("Message");
// Object
notifier.notify({
title: "My notification",
message: "Hello, there!",
});

Cross-Platform Advanced Usage
notification.js
const notifier = require("node-notifier");
const path = require("path");
notifier.notify(
{
title: "My awesome title",
message: "Hello from node, Mr. User!",
icon: path.join(__dirname, "coulson.jpg"), // Absolute path (doesn't work on balloons)
sound: true, // Only Notification Center or Windows Toasters
wait: true, // Wait with callback, until user action is taken against notification, does not apply to Windows Toasters as they always wait or notify-send as it does not support the wait option
},
function (err, response, metadata) {
// Response is response from notification
// Metadata contains activationType, activationAt, deliveredAt
}
);
notifier.on("click", function (notifierObject, options, event) {
// Triggers if `wait: true` and user clicks notification
});
notifier.on("timeout", function (notifierObject, options) {
// Triggers if `wait: true` and notification closes
});

オプション
notification.js
notifier.notify(
{
title: "My awesome title",
message: "Hello from node, Mr. User!",
icon: path.join(__dirname, "coulson.jpg"), // Absolute path (doesn't work on balloons)
sound: true, // 通知音を鳴らすかどうか
wait: true, // 何かしらのアクションがあるまで表示(ただしWindowsは適用外)
},
function (err, response, metadata) {
// 通知の情報を取得
console.log(err, "err");
console.log(response, "response");
console.log(metadata, "metadata");
// 下記情報を取得
// null err
// timeout response
// {
// action: 'timedout',
// notificationId: '18500',
// pipe: '\\\\.\\pipe\\notifierPipe-5532f88c-88bc-459a-8bb6-e6a6b636bfe8',
// version: '0.7.0',
// activationType: 'timedout'
// } metadata
}
);
notifier.on("click", function (notifierObject, options, event) {
// オプション `wait: true` かつ通知をクリックした場合に発火
});
notifier.on("timeout", function (notifierObject, options) {
// オプション `wait: true` かつ通知を閉じたときに発火
});
wait オプションについて
Wait with callback, until user action is taken against notification, does not apply to Windows Toasters as they always wait or notify-send as it does not support the wait option
Windowsは対象外みたい...

通知の種類
notification.js
const nn = require("node-notifier");
const options = {
title: "Hello",
message: "World",
};
new nn.WindowsToaster(options).notify(options);
new nn.WindowsBalloon(options).notify(options);
このスクラップは2024/04/11にクローズされました