From 48fe14e2635aaa27bdf2de4d0a01bdcbf84f2523 Mon Sep 17 00:00:00 2001 From: Chenlei Hu Date: Tue, 17 Sep 2024 11:11:52 +0900 Subject: [PATCH] [Beta Menu] Show active workflow name on browser tab title (#857) --- src/components/BrowserTabTitle.vue | 17 ++++++++++++++++- src/scripts/workflows.ts | 21 ++++++++++++++++----- src/stores/workflowStore.ts | 11 +++++++++++ 3 files changed, 43 insertions(+), 6 deletions(-) create mode 100644 src/stores/workflowStore.ts diff --git a/src/components/BrowserTabTitle.vue b/src/components/BrowserTabTitle.vue index 05958a915..f5289dd2a 100644 --- a/src/components/BrowserTabTitle.vue +++ b/src/components/BrowserTabTitle.vue @@ -6,6 +6,8 @@ diff --git a/src/scripts/workflows.ts b/src/scripts/workflows.ts index bb7087220..124f2315a 100644 --- a/src/scripts/workflows.ts +++ b/src/scripts/workflows.ts @@ -5,20 +5,31 @@ import { ComfyAsyncDialog } from './ui/components/asyncDialog' import { getStorageValue, setStorageValue } from './utils' import { LGraphCanvas, LGraph } from '@comfyorg/litegraph' import { appendJsonExt, trimJsonExt } from '@/utils/formatUtil' +import { useWorkflowStore } from '@/stores/workflowStore' +import { markRaw, toRaw } from 'vue' export class ComfyWorkflowManager extends EventTarget { executionStore: any = null #unsavedCount = 0 - #activeWorkflow: ComfyWorkflow workflowLookup: Record = {} workflows: Array = [] openWorkflows: Array = [] app: ComfyApp + get _activeWorkflow() { + if (!this.app.vueAppReady) return null + return toRaw(useWorkflowStore().activeWorkflow) as ComfyWorkflow | null + } + + set _activeWorkflow(workflow: ComfyWorkflow | null) { + if (!this.app.vueAppReady) return + useWorkflowStore().activeWorkflow = workflow ? markRaw(workflow) : null + } + get activeWorkflow() { - return this.#activeWorkflow ?? this.openWorkflows[0] + return this._activeWorkflow ?? this.openWorkflows[0] } get activePromptId() { @@ -109,7 +120,7 @@ export class ComfyWorkflowManager extends EventTarget { this.openWorkflows.push(workflow) } - this.#activeWorkflow = workflow + this._activeWorkflow = workflow setStorageValue('Comfy.PreviousWorkflow', this.activeWorkflow.path ?? '') this.dispatchEvent(new CustomEvent('changeWorkflow')) @@ -157,8 +168,8 @@ export class ComfyWorkflowManager extends EventTarget { workflow.changeTracker = null this.openWorkflows.splice(this.openWorkflows.indexOf(workflow), 1) if (this.openWorkflows.length) { - this.#activeWorkflow = this.openWorkflows[0] - await this.#activeWorkflow.load() + this._activeWorkflow = this.openWorkflows[0] + await this._activeWorkflow.load() } else { // Load default await this.app.loadGraphData() diff --git a/src/stores/workflowStore.ts b/src/stores/workflowStore.ts new file mode 100644 index 000000000..ad81ae410 --- /dev/null +++ b/src/stores/workflowStore.ts @@ -0,0 +1,11 @@ +import { defineStore } from 'pinia' +import { ref } from 'vue' +import { ComfyWorkflow } from '@/scripts/workflows' + +export const useWorkflowStore = defineStore('workflow', () => { + const activeWorkflow = ref(null) + + return { + activeWorkflow + } +})