multiple workflows

This commit is contained in:
TomoyukiMizuma 2023-08-18 02:23:07 +09:00
parent c28db1f315
commit bc0360291f
3 changed files with 43 additions and 0 deletions

View File

@ -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();

View File

@ -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;
}
}
}

View File

@ -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;