From f837446d30e967fc03a9fd90ed266effdac5f37a Mon Sep 17 00:00:00 2001 From: tritant Date: Tue, 23 Sep 2025 11:17:20 +0200 Subject: [PATCH] Add files via upload --- js/orchestratormuter.js | 93 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 js/orchestratormuter.js diff --git a/js/orchestratormuter.js b/js/orchestratormuter.js new file mode 100644 index 0000000..a316e33 --- /dev/null +++ b/js/orchestratormuter.js @@ -0,0 +1,93 @@ +import { app } from "/scripts/app.js"; + +// This list now drives the creation of toggles. +const WORKFLOW_TAGS = ["FLUX", "QWEN", "WAN2.2", "SDXL", "SD1.5"]; + +// This function doesn't need to change at all. +function updateNodeStates(selectedWorkflow) { + const changesToApply = []; + + for (const targetNode of app.graph.nodes) { + if (targetNode.type === "OrchestratorNodeMuter") continue; + const title = targetNode.title || ""; + let isTaggedNode = false; + for (const tag of WORKFLOW_TAGS) { + if (title.startsWith(`[${tag}]`)) { + isTaggedNode = true; + break; + } + } + if (isTaggedNode) { + const newMode = title.startsWith(`[${selectedWorkflow}]`) ? 0 : 4; + if (targetNode.mode !== newMode) { + changesToApply.push({ node: targetNode, mode: newMode }); + } + } + } + + if (changesToApply.length > 0) { + for (const change of changesToApply) { + change.node.mode = change.mode; + } + app.graph.setDirtyCanvas(true, true); + } +} + +app.registerExtension({ + name: "Comfy.OrchestratorNodeMuter.Toggles", + + beforeRegisterNodeDef(nodeType, nodeData, app) { + if (nodeData.name === "OrchestratorNodeMuter") { + const onNodeCreated = nodeType.prototype.onNodeCreated; + nodeType.prototype.onNodeCreated = function () { + onNodeCreated?.apply(this, arguments); + + // --- NEW LOGIC TO CREATE TOGGLES --- + + // This function ensures only one toggle is active at a time. + const handleToggleClick = (toggledWidgetName, isTurningOn) => { + if (!isTurningOn) { + // Prevent the user from turning off the last active toggle. + const thisWidget = this.widgets.find(w => w.name === toggledWidgetName); + if (thisWidget) thisWidget.value = true; + return; + } + + // Turn off all other toggles. + for (const w of this.widgets) { + if (WORKFLOW_TAGS.includes(w.name) && w.name !== toggledWidgetName) { + w.value = false; + } + } + + // Update the graph state based on the selected toggle. + setTimeout(() => { + updateNodeStates(toggledWidgetName); + }, 0); + }; + + // Create one toggle for each tag in our list. + for (const tag of WORKFLOW_TAGS) { + this.addWidget( + "toggle", + tag, // The name of the widget is the tag itself + false, // Default to OFF + (value) => { handleToggleClick(tag, value); } + ); + } + + // --- SET INITIAL STATE --- + + // Find the first toggle and turn it ON by default. + const firstWidget = this.widgets.find(w => w.name === WORKFLOW_TAGS[0]); + if (firstWidget) { + firstWidget.value = true; + // Trigger the initial update. + setTimeout(() => { + updateNodeStates(firstWidget.name); + }, 200); + } + }; + } + }, +}); \ No newline at end of file