-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoggle.mjs
More file actions
34 lines (30 loc) · 941 Bytes
/
Copy pathtoggle.mjs
File metadata and controls
34 lines (30 loc) · 941 Bytes
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
import { spawnSync } from "node:child_process";
import {
loadDotEnv,
modeEnabled,
modePath,
setMode,
} from "./lib.mjs";
loadDotEnv();
const requested = process.argv[2]?.trim().toLowerCase();
const enabled =
requested === "on" || requested === "enable" || requested === "enabled"
? true
: requested === "off" || requested === "disable" || requested === "disabled"
? false
: !modeEnabled();
setMode(enabled);
const label = enabled ? "enabled" : "disabled";
console.log(`Webhook notifications ${label}.`);
console.log(`State: ${modePath()}`);
const herdrBin = process.env.HERDR_BIN_PATH ?? "herdr";
const notice = spawnSync(
herdrBin,
["notification", "show", "Webhook notify", "--body", `Notifications ${label}`],
{ encoding: "utf8" },
);
if (notice.status !== 0) {
console.error(
`notification show failed (${notice.status}): ${notice.stderr ?? notice.stdout ?? "unknown error"}`.trim(),
);
}