-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNotifierNodeJS.js
47 lines (46 loc) · 1.6 KB
/
NotifierNodeJS.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
const notifier = require("node-notifier");
const opn = require("opn");
function notify(appName, title, content, icon, trigger) {
notifier.notify(
{
appName: appName,
title: title,
message: content,
icon: icon,
sound: true,
wait: true,
},
(error, response, metadata) => {
if (!error) {
if (response == "activate" && metadata.activationType == "clicked") {
console.log("clicked");
if (trigger != "SP:NOTRIGGER") { opn(trigger); }
} else if (response == undefined) {
console.log("undifined response -> clicked");
if (trigger != "SP:NOTRIGGER") { opn(trigger); }
} else {
console.log("response:", response);
console.log("metadata.activationType:", metadata.activationType);
}
} else {
console.error("Notification error:", error);
}
}
);
}
const args = require('minimist')(process.argv.slice(2));
if (
args['appName'] != undefined &&
args['title'] != undefined &&
args['content'] != undefined &&
args['icon'] != undefined
) {
if (args['trigger'] == undefined) {
notify (args['appName'], args['title'], args['content'], args['icon'], "SP:NOTRIGGER");
} else {
notify (args['appName'], args['title'], args['content'], args['icon'], args['trigger']);
}
} else {
console.error("Invalid arguments.");
console.error("Usage: programName --appName=appName(string) --title=title(string) --content=content(string) --icon=icon(string: pathToFile / \"undefined\") [--trigger=trigger(string: app/link)]");
}