From bc0360291fd3c603b44a54d31ddb37eef40c016b Mon Sep 17 00:00:00 2001 From: TomoyukiMizuma Date: Fri, 18 Aug 2023 02:23:07 +0900 Subject: [PATCH] multiple workflows --- web/scripts/app.js | 27 +++++++++++++++++++++++++++ web/scripts/ui.js | 11 +++++++++++ web/style.css | 5 +++++ 3 files changed, 43 insertions(+) diff --git a/web/scripts/app.js b/web/scripts/app.js index 1c95c765c..15ce036d4 100644 --- a/web/scripts/app.js +++ b/web/scripts/app.js @@ -1084,12 +1084,16 @@ export class ComfyApp { // Load previous workflow let restored = false; + this.workflow_current_id = 0; try { const json = localStorage.getItem("workflow"); if (json) { const workflow = JSON.parse(json); this.loadGraphData(workflow); restored = true; + const workflow_id = localStorage.getItem("workflow_current_id"); + if (workflow_id) + this.workflow_current_id = workflow_id; } } catch (err) { console.error("Error loading previous workflow", err); @@ -1597,6 +1601,29 @@ export class ComfyApp { this.lastExecutionError = null; this.runningNodeId = null; } + + switchWorkflow() { + const workflow_count = 3; + + try { + let current_workflow = "workflow_" + this.workflow_current_id; + this.workflow_current_id += 1; + this.workflow_current_id %= workflow_count; + let next_workflow = "workflow_" + this.workflow_current_id; + + localStorage.setItem("workflow_current_id", this.workflow_current_id); + localStorage.setItem(current_workflow, JSON.stringify(this.graph.serialize())); + + const json = localStorage.getItem(next_workflow); + if (json) { + const workflow = JSON.parse(json); + this.loadGraphData(workflow); + localStorage.setItem("workflow", json); + } + } catch (err) { + console.error("Error loading workflow", err); + } + } } export const app = new ComfyApp(); diff --git a/web/scripts/ui.js b/web/scripts/ui.js index 86e2a1c41..59d4a0bbc 100644 --- a/web/scripts/ui.js +++ b/web/scripts/ui.js @@ -756,6 +756,12 @@ export class ComfyUI { } } }), + $el("button", { + id: "comfy-switch-workflow-button", textContent: "Workflow", onclick: () => { + app.switchWorkflow(); + document.getElementById("comfy-switch-workflow-button").textContent = "Workflow " + app.workflow_current_id; + } + }), ]); const devMode = this.settings.addSetting({ @@ -773,7 +779,9 @@ export class ComfyUI { setStatus(status) { this.queueSize.textContent = "Queue size: " + (status ? status.exec_info.queue_remaining : "ERR"); + const switch_btn = document.getElementById("comfy-switch-workflow-button"); if (status) { + switch_btn.disabled = status.exec_info.queue_remaining ? true : false; if ( this.lastQueueSize != 0 && status.exec_info.queue_remaining == 0 && @@ -783,5 +791,8 @@ export class ComfyUI { } this.lastQueueSize = status.exec_info.queue_remaining; } + else { + switch_btn.disabled = false; + } } } diff --git a/web/style.css b/web/style.css index 5b6b9ec57..52b71f312 100644 --- a/web/style.css +++ b/web/style.css @@ -142,6 +142,11 @@ body { cursor: pointer; } +button#comfy-switch-workflow-button:disabled { + filter: brightness(1.0); + cursor: not-allowed; +} + .comfy-menu span.drag-handle { width: 10px; height: 20px;