Adds node for sending system notifications.
This commit is contained in:
@@ -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 🐍",
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user