From 11c46ea62d75bab801f59a3e9b7cef9b2445f7e3 Mon Sep 17 00:00:00 2001 From: christian-byrne Date: Sat, 18 Jan 2025 13:04:22 -0700 Subject: [PATCH] Refactor Comfy version retrieval and update changelog version description --- src/components/graph/GraphCanvas.vue | 18 +++++------------- src/constants/coreSettings.ts | 2 +- src/utils/envUtil.ts | 11 ++++++++++- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/components/graph/GraphCanvas.vue b/src/components/graph/GraphCanvas.vue index b1ee27945..4fdbc8bfe 100644 --- a/src/components/graph/GraphCanvas.vue +++ b/src/components/graph/GraphCanvas.vue @@ -73,12 +73,11 @@ import { } from '@/stores/modelToNodeStore' import { ComfyNodeDefImpl, useNodeDefStore } from '@/stores/nodeDefStore' import { useSettingStore } from '@/stores/settingStore' -import { useSystemStatsStore } from '@/stores/systemStatsStore' import { useWorkflowStore } from '@/stores/workflowStore' import { useColorPaletteStore } from '@/stores/workspace/colorPaletteStore' import { useWorkspaceStore } from '@/stores/workspaceStore' import type { RenderedTreeExplorerNode } from '@/types/treeExplorerTypes' -import { electronAPI, isElectron, isVersionLessThan } from '@/utils/envUtil' +import { getComfyVersion, isVersionLessThan } from '@/utils/envUtil' const emit = defineEmits(['ready']) const canvasRef = ref(null) @@ -282,28 +281,21 @@ const persistCurrentWorkflow = () => { } } -const getComfyVersion = () => { - if (isElectron()) return electronAPI().getComfyUIVersion() - return useSystemStatsStore()?.systemStats?.system?.comfyui_version ?? '' -} - const stopWatchChangeLog = watch( () => workflowStore.activeWorkflow, - () => { + async () => { if (!comfyAppReady.value) return - - const isDisabled = settingStore.get('Comfy.ShowChangeLog') === false - if (isDisabled || !changelog) { + if (!changelog || settingStore.get('Comfy.ShowChangeLog') === false) { stopWatchChangeLog() return } const workflow = workflowStore.activeWorkflow const activeState = workflow?.activeState - const comfyVersion = getComfyVersion() + const comfyVersion = getComfyVersion() // TODO: initialize/fetch somewhere else if (!workflow || !activeState || !comfyVersion) return - // Just checking if temporary is not enough bc doesn't account for duplicate feature + // Just checking if workflow temporary is not enough bc of Duplicate feature const isBlank = !workflow.isPersisted && activeState.nodes?.length === 0 if (!isBlank) return diff --git a/src/constants/coreSettings.ts b/src/constants/coreSettings.ts index 636d9376d..58a982172 100644 --- a/src/constants/coreSettings.ts +++ b/src/constants/coreSettings.ts @@ -719,7 +719,7 @@ export const CORE_SETTINGS: SettingParams[] = [ }, { id: 'Comfy.LastChangelogVersion', - name: 'The version of ComfyUI on which the last changelog was shown', + name: 'Last shown changelog version', type: 'hidden', defaultValue: '0.0.0', versionAdded: '1.7.15' diff --git a/src/utils/envUtil.ts b/src/utils/envUtil.ts index 08abb5446..104689ec7 100644 --- a/src/utils/envUtil.ts +++ b/src/utils/envUtil.ts @@ -3,6 +3,8 @@ import { ElectronContextMenuOptions } from '@comfyorg/comfyui-electron-types' +import { useSystemStatsStore } from '@/stores/systemStatsStore' + export function isElectron() { return 'electronAPI' in window && window.electronAPI !== undefined } @@ -19,7 +21,7 @@ const normalizeVersion = (version: string) => { return version .split('.') .map(Number) - .filter((v) => !Number.isNaN(v)) + .filter((n): n is number => !Number.isNaN(n)) } export function isVersionLessThan(versionA: string, versionB: string) { @@ -38,3 +40,10 @@ export function isVersionLessThan(versionA: string, versionB: string) { return false } + +export function getComfyVersion() { + if (isElectron()) return electronAPI().getComfyUIVersion() + const store = useSystemStatsStore() + store.fetchSystemStats() + return store.systemStats?.system?.comfyui_version ?? '' +}