From 46db5de0f48c1418cb8fb56d92aa61ae2c2053ab Mon Sep 17 00:00:00 2001 From: TomoyukiMizuma Date: Wed, 23 Aug 2023 22:22:52 +0900 Subject: [PATCH] Fixed a bug that occurred when working on workflows in more than one browser tab. --- web/scripts/app.js | 6 +++++- web/scripts/ui.js | 12 +++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/web/scripts/app.js b/web/scripts/app.js index d05d6cc02..b980e2882 100644 --- a/web/scripts/app.js +++ b/web/scripts/app.js @@ -1108,7 +1108,11 @@ export class ComfyApp { } // Save current workflow automatically - setInterval(() => localStorage.setItem("workflow", JSON.stringify(this.graph.serialize())), 1000); + setInterval(() => { + if (document.visibilityState === "visible") { + localStorage.setItem("workflow", JSON.stringify(this.graph.serialize())); + } + }, 1000); this.#addDrawNodeHandler(); this.#addDrawGroupsHandler(); diff --git a/web/scripts/ui.js b/web/scripts/ui.js index 54270f4d2..33aed7e72 100644 --- a/web/scripts/ui.js +++ b/web/scripts/ui.js @@ -777,6 +777,13 @@ export class ComfyUI { ]); this.is_launchTiming = true; + this.switch_workflow_combo = document.getElementById("comfy-switch-workflow-combo"); + document.addEventListener("visibilitychange", () => { + if (document.visibilityState === "visible") { + localStorage.setItem("workflow_current_id", this.switch_workflow_combo.selectedIndex); + } + }); + const id_renameWorkflow = "Comfy.RenameWorkflowDialog"; const renameWorkflow = this.settings.addSetting({ id: id_renameWorkflow, @@ -839,11 +846,10 @@ export class ComfyUI { } if (this.is_launchTiming && typeof app != "undefined") { - const switch_workflow_combo = document.getElementById("comfy-switch-workflow-combo"); - switch_workflow_combo.selectedIndex = app.workflow_current_id; + this.switch_workflow_combo.selectedIndex = app.workflow_current_id; const workflow_names = app.getWorkflowNames(); - const options = switch_workflow_combo.options; + const options = this.switch_workflow_combo.options; console.assert(options.length === workflow_names.length, "workflow_count != the count of $el(option ~ )");