diff --git a/py/system_notification.py b/py/system_notification.py index d20db94..e9a29c9 100644 --- a/py/system_notification.py +++ b/py/system_notification.py @@ -8,10 +8,11 @@ class AnyType(str): any = AnyType("*") -class PlaySound: +class SystemNotification: @classmethod def INPUT_TYPES(s): return {"required": { + "message": ("STRING", {"default": "Your notification has triggered."}), "any": (any, {}), "mode": (["always", "on empty queue"], {}), }} @@ -27,12 +28,12 @@ class PlaySound: def IS_CHANGED(self, **kwargs): return float("NaN") - def nop(self, any, mode): + def nop(self, any, **kwargs): return {"ui": {"a": []}, "result": (any,)} NODE_CLASS_MAPPINGS = { - "SystemNotification|pysssss": PlaySound, + "SystemNotification|pysssss": SystemNotification, } NODE_DISPLAY_NAME_MAPPINGS = { diff --git a/web/js/systemNotification.js b/web/js/systemNotification.js index 34499fb..2cc93ba 100644 --- a/web/js/systemNotification.js +++ b/web/js/systemNotification.js @@ -1,46 +1,49 @@ import { app } from "../../../scripts/app.js"; const notificationSetup = () => { - if (!("Notification" in window)) { - console.log("This browser does not support notifications."); - alert("This browser does not support notifications."); - return; - } - if (Notification.permission === "denied") { - console.log("Notifications are blocked. Please enable them in your browser settings."); - alert("Notifications are blocked. Please enable them in your browser settings."); - return; - } - if (Notification.permission !== "granted") { - Notification.requestPermission() - } - return true; -} + if (!("Notification" in window)) { + console.log("This browser does not support notifications."); + alert("This browser does not support notifications."); + return; + } + if (Notification.permission === "denied") { + console.log("Notifications are blocked. Please enable them in your browser settings."); + alert("Notifications are blocked. Please enable them in your browser settings."); + return; + } + if (Notification.permission !== "granted") { + Notification.requestPermission(); + } + return true; +}; app.registerExtension({ - name: "pysssss.SystemNotification", - async beforeRegisterNodeDef(nodeType, nodeData, app) { - if (nodeData.name === "SystemNotification|pysssss") { - const onExecuted = nodeType.prototype.onExecuted; - nodeType.prototype.onExecuted = async function () { - onExecuted?.apply(this, arguments); - if (this.widgets[0].value === "on empty queue") { - if (app.ui.lastQueueSize !== 0) { - await new Promise((r) => setTimeout(r, 500)); - } - if (app.ui.lastQueueSize !== 0) { - return; - } - } - if(!notificationSetup()) return; - const notification = new Notification("ComfyUI", { body: "Your notification has triggered." }) - }; + name: "pysssss.SystemNotification", + async beforeRegisterNodeDef(nodeType, nodeData, app) { + if (nodeData.name === "SystemNotification|pysssss") { + const onExecuted = nodeType.prototype.onExecuted; + nodeType.prototype.onExecuted = async function () { + onExecuted?.apply(this, arguments); + const mode = this.widgets.find((w) => w.name === "mode"); + const message = this.widgets.find((w) => w.name === "message"); - const onNodeCreated = nodeType.prototype.onNodeCreated; - nodeType.prototype.onNodeCreated = function () { - onNodeCreated?.apply(this, arguments); - notificationSetup(); - } - } - }, + if (mode.value === "on empty queue") { + if (app.ui.lastQueueSize !== 0) { + await new Promise((r) => setTimeout(r, 500)); + } + if (app.ui.lastQueueSize !== 0) { + return; + } + } + if (!notificationSetup()) return; + const notification = new Notification("ComfyUI", { body: message.value ?? "Your notification has triggered." }); + }; + + const onNodeCreated = nodeType.prototype.onNodeCreated; + nodeType.prototype.onNodeCreated = function () { + onNodeCreated?.apply(this, arguments); + notificationSetup(); + }; + } + }, });