Adds node for sending system notifications.

This commit is contained in:
Royce Schultz
2024-04-30 00:17:58 -06:00
parent 3f2c021e50
commit 37a25c64dd
2 changed files with 86 additions and 0 deletions
+40
View File
@@ -0,0 +1,40 @@
# Hack: string type that is always equal in not equal comparisons
class AnyType(str):
def __ne__(self, __value: object) -> bool:
return False
# Our any instance wants to be a wildcard string
any = AnyType("*")
class PlaySound:
@classmethod
def INPUT_TYPES(s):
return {"required": {
"any": (any, {}),
"mode": (["always", "on empty queue"], {}),
}}
FUNCTION = "nop"
INPUT_IS_LIST = True
OUTPUT_IS_LIST = (True,)
OUTPUT_NODE = True
RETURN_TYPES = (any,)
CATEGORY = "utils"
def IS_CHANGED(self, **kwargs):
return float("NaN")
def nop(self, any, mode):
return {"ui": {"a": []}, "result": (any,)}
NODE_CLASS_MAPPINGS = {
"SystemNotification|pysssss": PlaySound,
}
NODE_DISPLAY_NAME_MAPPINGS = {
"SystemNotification|pysssss": "SystemNotification 🐍",
}
+46
View File
@@ -0,0 +1,46 @@
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;
}
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." })
};
const onNodeCreated = nodeType.prototype.onNodeCreated;
nodeType.prototype.onNodeCreated = function () {
onNodeCreated?.apply(this, arguments);
notificationSetup();
}
}
},
});