dashboard.ts: add local notify-send popups (desktop notifications) alongside NTFY/Apprise
This commit is contained in:
@@ -211,6 +211,19 @@ export default function (pi: ExtensionAPI) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function notify(title: string, body: string) {
|
function notify(title: string, body: string) {
|
||||||
|
// Desktop notification (local machine popup)
|
||||||
|
try {
|
||||||
|
const child = spawn(
|
||||||
|
"notify-send",
|
||||||
|
["-a", "Pi Dashboard", title, body],
|
||||||
|
{ stdio: "ignore", timeout: 3000 }
|
||||||
|
);
|
||||||
|
child.on("error", () => {});
|
||||||
|
child.unref();
|
||||||
|
} catch {
|
||||||
|
// notify-send unavailable (e.g. headless server)
|
||||||
|
}
|
||||||
|
|
||||||
// NTFY notification
|
// NTFY notification
|
||||||
const ntfyTopic = process.env.PI_NTFY_TOPIC;
|
const ntfyTopic = process.env.PI_NTFY_TOPIC;
|
||||||
if (ntfyTopic) {
|
if (ntfyTopic) {
|
||||||
@@ -236,16 +249,31 @@ export default function (pi: ExtensionAPI) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apprise notification
|
// Apprise notification (HTTP API on .35 — fans out to Telegram/ntfy/email/callmebot)
|
||||||
|
const appriseApi =
|
||||||
|
process.env.APPRISE_API_URL ||
|
||||||
|
"http://192.168.20.35:8210/notify/eaef201fc995964c8a4013892563ae79879df4ecddbabdc4f4af1e549d3366e1";
|
||||||
try {
|
try {
|
||||||
const child = spawn("apprise", ["-b", `${title}: ${body}`], {
|
const child = spawn(
|
||||||
stdio: "ignore",
|
"curl",
|
||||||
timeout: 3000,
|
[
|
||||||
});
|
"-s",
|
||||||
|
"-o",
|
||||||
|
"/dev/null",
|
||||||
|
"-X",
|
||||||
|
"POST",
|
||||||
|
"-H",
|
||||||
|
"Content-Type: application/json",
|
||||||
|
"-d",
|
||||||
|
JSON.stringify({ title, body }),
|
||||||
|
appriseApi,
|
||||||
|
],
|
||||||
|
{ stdio: "ignore", timeout: 5000 }
|
||||||
|
);
|
||||||
child.on("error", () => {});
|
child.on("error", () => {});
|
||||||
child.unref();
|
child.unref();
|
||||||
} catch {
|
} catch {
|
||||||
// Apprise not installed
|
// Apprise unavailable
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user