diff --git a/js/assets/notify.mp3 b/js/assets/notify.mp3 new file mode 100644 index 0000000..5e3fdab Binary files /dev/null and b/js/assets/notify.mp3 differ diff --git a/js/playSound.js b/js/playSound.js new file mode 100644 index 0000000..318f54a --- /dev/null +++ b/js/playSound.js @@ -0,0 +1,24 @@ +import { app } from "/scripts/app.js"; + +app.registerExtension({ + name: "pysssss.PlaySound", + async beforeRegisterNodeDef(nodeType, nodeData, app) { + if (nodeData.name === "PlaySound|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; + } + } + const url = new URL(`assets/notify.mp3`, import.meta.url); + const audio = new Audio(url); + audio.play(); + }; + } + }, +}); diff --git a/py/play_sound.py b/py/play_sound.py new file mode 100644 index 0000000..5fa0700 --- /dev/null +++ b/py/play_sound.py @@ -0,0 +1,39 @@ +# 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_NODE = True + RETURN_TYPES = () + + CATEGORY = "utils" + + def IS_CHANGED(self, **kwargs): + return float("NaN") + + def nop(self, any, mode): + return {"ui": {"a":[]}, "result": ()} + + +NODE_CLASS_MAPPINGS = { + "PlaySound|pysssss": PlaySound, +} + +NODE_DISPLAY_NAME_MAPPINGS = { + "PlaySound|pysssss": "PlaySound 🐍", +}