Fix bypass/mute mode values (bypass=4, mute=2 per ComfyUI NodeMode) + per-mode toggle state keys

This commit is contained in:
solidlime
2026-08-02 19:45:25 +09:00
parent f5332038e8
commit f3b67a46f4
+19 -9
View File
@@ -48,12 +48,12 @@ function currentRealValue(target, mode) {
if (typeof g.recomputeInsideNodes === "function") g.recomputeInsideNodes();
const members = g._nodes || [];
if (members.length === 0) return false;
const m = mode === "bypass" ? 2 : 4;
const m = mode === "bypass" ? 4 : 2;
return members.every((n) => n.mode === m);
}
const targetNode = target.ref;
if (mode === "bypass") return targetNode.mode === 2;
if (mode === "mute") return targetNode.mode === 4;
if (mode === "bypass") return targetNode.mode === 4;
if (mode === "mute") return targetNode.mode === 2;
// widgets: first boolean widget value
const bw = (targetNode.widgets || []).find(
(w) => w.type === "BOOLEAN" || w.type === "toggle" || (w.options && w.options.type === "boolean")
@@ -74,16 +74,16 @@ function applyValue(target, mode, value) {
if (mode === "widgets") return; // groups are never included in widgets mode
const g = target.ref;
if (typeof g.recomputeInsideNodes === "function") g.recomputeInsideNodes();
const m = value ? (mode === "bypass" ? 2 : 4) : 0;
const m = value ? (mode === "bypass" ? 4 : 2) : 0;
(g._nodes || []).forEach((n) => { n.mode = m; });
app.graph.setDirtyCanvas(true, true);
return;
}
const targetNode = target.ref;
if (mode === "bypass") {
targetNode.mode = value ? 2 : 0;
} else if (mode === "mute") {
targetNode.mode = value ? 4 : 0;
} else if (mode === "mute") {
targetNode.mode = value ? 2 : 0;
} else {
// widgets
const bw = (targetNode.widgets || []).find(
@@ -166,6 +166,14 @@ function buildPanel(panelNode) {
if (!panelNode.properties.switches) {
panelNode.properties.switches = {};
}
// State was previously keyed by name only (shared across modes). Drop
// legacy single-name keys; current keys are "<mode>:<name>".
{
const legacy = panelNode.properties.switches;
for (const k of Object.keys(legacy)) {
if (!k.includes(":")) delete legacy[k];
}
}
const container = document.createElement("div");
container.style.cssText =
@@ -264,9 +272,11 @@ function buildPanel(panelNode) {
}
row.appendChild(label);
// Toggle
// Toggle — state is persisted per (mode, name) so bypass/mute/widgets
// never share each other's on/off state.
const toggle = createToggle(disabled);
const saved = switches[name];
const stateKey = mode + ":" + name;
const saved = switches[stateKey];
let isOn;
if (saved !== undefined) {
isOn = !!saved;
@@ -281,7 +291,7 @@ function buildPanel(panelNode) {
if (disabled) return;
const nowOn = !toggle.classList.contains("on");
toggle.classList.toggle("on", nowOn);
switches[name] = nowOn;
switches[stateKey] = nowOn;
applyValue(t, mode, nowOn);
});