From 38ab2833ebd236ad8ce99cf03db821ef5d3b701d Mon Sep 17 00:00:00 2001 From: bymyself Date: Wed, 9 Apr 2025 09:52:06 -0700 Subject: [PATCH] migrate manager menu items --- src/composables/useCoreCommands.ts | 82 ++++-------------------------- src/constants/coreMenuCommands.ts | 15 ++---- src/constants/coreSettings.ts | 7 +++ src/locales/en/main.json | 13 +---- src/schemas/apiSchema.ts | 3 +- src/scripts/api.ts | 81 ++++------------------------- 6 files changed, 36 insertions(+), 165 deletions(-) diff --git a/src/composables/useCoreCommands.ts b/src/composables/useCoreCommands.ts index 2b7f904b3..8a70895fe 100644 --- a/src/composables/useCoreCommands.ts +++ b/src/composables/useCoreCommands.ts @@ -15,11 +15,9 @@ import { t } from '@/i18n' import { api } from '@/scripts/api' import { app } from '@/scripts/app' import { addFluxKontextGroupNode } from '@/scripts/fluxKontextEditNode' -import { useComfyManagerService } from '@/services/comfyManagerService' import { useDialogService } from '@/services/dialogService' import { useLitegraphService } from '@/services/litegraphService' import { useWorkflowService } from '@/services/workflowService' -import type { ComfyCommand } from '@/stores/commandStore' import { useCommandStore } from '@/stores/commandStore' import { useExecutionStore } from '@/stores/executionStore' import { useCanvasStore, useTitleEditorStore } from '@/stores/graphStore' @@ -686,54 +684,12 @@ export function useCoreCommands(): ComfyCommand[] { } }, { - id: 'Comfy.Manager.CustomNodesManager.ShowCustomNodesMenu', - icon: 'pi pi-objects-column', - label: 'Custom Nodes Manager', + id: 'Comfy.Manager.CustomNodesManager', + icon: 'pi pi-puzzle', + label: 'Toggle the Custom Nodes Manager', versionAdded: '1.12.10', - function: async () => { - const { is_legacy_manager_ui } = - (await useComfyManagerService().isLegacyManagerUI()) ?? {} - - if (is_legacy_manager_ui === true) { - try { - await useCommandStore().execute( - 'Comfy.Manager.Menu.ToggleVisibility' // This command is registered by legacy manager FE extension - ) - } catch (error) { - console.error('error', error) - useToastStore().add({ - severity: 'error', - summary: t('g.error'), - detail: t('manager.legacyMenuNotAvailable'), - life: 3000 - }) - dialogService.showManagerDialog() - } - } else { - dialogService.showManagerDialog() - } - } - }, - { - id: 'Comfy.Manager.ShowUpdateAvailablePacks', - icon: 'pi pi-sync', - label: 'Check for Custom Node Updates', - versionAdded: '1.17.0', function: () => { - dialogService.showManagerDialog({ - initialTab: ManagerTab.UpdateAvailable - }) - } - }, - { - id: 'Comfy.Manager.ShowMissingPacks', - icon: 'pi pi-exclamation-circle', - label: 'Install Missing Custom Nodes', - versionAdded: '1.17.0', - function: () => { - dialogService.showManagerDialog({ - initialTab: ManagerTab.Missing - }) + dialogService.toggleManagerDialog() } }, { @@ -822,6 +778,7 @@ export function useCoreCommands(): ComfyCommand[] { }) return } + const { node } = res canvas.select(node) } @@ -831,9 +788,9 @@ export function useCoreCommands(): ComfyCommand[] { icon: 'pi pi-bars', label: 'Custom Nodes (Legacy)', versionAdded: '1.16.4', - function: async () => { + function: () => { try { - await useCommandStore().execute( + void useCommandStore().execute( 'Comfy.Manager.CustomNodesManager.ToggleVisibility' ) } catch (error) { @@ -851,9 +808,9 @@ export function useCoreCommands(): ComfyCommand[] { icon: 'mdi mdi-puzzle', label: 'Manager Menu (Legacy)', versionAdded: '1.16.4', - function: async () => { + function: () => { try { - await useCommandStore().execute('Comfy.Manager.Menu.ToggleVisibility') + void useCommandStore().execute('Comfy.Manager.Menu.ToggleVisibility') } catch (error) { useToastStore().add({ severity: 'error', @@ -881,27 +838,6 @@ export function useCoreCommands(): ComfyCommand[] { }) return } - await api.freeMemory({ freeExecutionCache: false }) - } - }, - { - id: 'Comfy.Memory.UnloadModelsAndExecutionCache', - icon: 'mdi mdi-vacuum-outline', - label: 'Unload Models and Execution Cache', - versionAdded: '1.16.4', - function: async () => { - if (!useSettingStore().get('Comfy.Memory.AllowManualUnload')) { - useToastStore().add({ - severity: 'error', - summary: t('g.error'), - detail: t('g.commandProhibited', { - command: 'Comfy.Memory.UnloadModelsAndExecutionCache' - }), - life: 3000 - }) - return - } - await api.freeMemory({ freeExecutionCache: true }) } } ] diff --git a/src/constants/coreMenuCommands.ts b/src/constants/coreMenuCommands.ts index 46fb6265e..9fc0561eb 100644 --- a/src/constants/coreMenuCommands.ts +++ b/src/constants/coreMenuCommands.ts @@ -11,22 +11,17 @@ export const CORE_MENU_COMMANDS = [ ] ], [['Edit'], ['Comfy.Undo', 'Comfy.Redo']], - [ - ['Edit'], - [ - 'Comfy.RefreshNodeDefinitions', - 'Comfy.Memory.UnloadModels', - 'Comfy.Memory.UnloadModelsAndExecutionCache' - ] - ], + [['Edit'], ['Comfy.RefreshNodeDefinitions']], [['Edit'], ['Comfy.ClearWorkflow']], [['Edit'], ['Comfy.OpenClipspace']], [ ['Manager'], [ + 'Comfy.Manager.ShowLegacyManagerMenu', + 'Comfy.Manager.CustomNodesManager.ShowLegacyCustomNodesMenu', 'Comfy.Manager.CustomNodesManager.ShowCustomNodesMenu', - 'Comfy.Manager.ShowMissingPacks', - 'Comfy.Manager.ShowUpdateAvailablePacks' + 'Comfy.Memory.UnloadModels', + 'Comfy.Memory.UnloadModelsAndExecutionCache' ] ], [ diff --git a/src/constants/coreSettings.ts b/src/constants/coreSettings.ts index b53933bd5..25ca0e9a8 100644 --- a/src/constants/coreSettings.ts +++ b/src/constants/coreSettings.ts @@ -899,5 +899,12 @@ export const CORE_SETTINGS: SettingParams[] = [ name: 'Release seen timestamp', type: 'hidden', defaultValue: 0 + }, + { + id: 'Comfy.Memory.AllowManualUnload', + name: 'Allow manual unload of models and execution cache via user command', + type: 'hidden', + defaultValue: true, + versionAdded: '1.18.0' } ] diff --git a/src/locales/en/main.json b/src/locales/en/main.json index f036d9dbd..a217d85a9 100644 --- a/src/locales/en/main.json +++ b/src/locales/en/main.json @@ -149,9 +149,7 @@ }, "manager": { "title": "Custom Nodes Manager", - "legacyMenuNotAvailable": "Legacy manager menu is not available, defaulting to the new manager menu.", - "legacyManagerUI": "Use Legacy UI", - "legacyManagerUIDescription": "To use the legacy Manager UI, start ComfyUI with --enable-manager-legacy-ui", + "legacyMenuNotAvailable": "Legacy manager menu is not available in this version of ComfyUI. Please use the new manager menu instead.", "failed": "Failed ({count})", "noNodesFound": "No nodes found", "noNodesFoundDescription": "The pack's nodes either could not be parsed, or the pack is a frontend extension only and doesn't have any nodes.", @@ -934,7 +932,6 @@ "menuLabels": { "Workflow": "Workflow", "Edit": "Edit", - "Manager": "Manager", "Help": "Help", "Check for Updates": "Check for Updates", "Open Custom Nodes Folder": "Open Custom Nodes Folder", @@ -988,17 +985,11 @@ "ComfyUI Issues": "ComfyUI Issues", "Interrupt": "Interrupt", "Load Default Workflow": "Load Default Workflow", - "Custom Nodes Manager": "Custom Nodes Manager", - "Custom Nodes (Legacy)": "Custom Nodes (Legacy)", - "Manager Menu (Legacy)": "Manager Menu (Legacy)", - "Install Missing Custom Nodes": "Install Missing Custom Nodes", - "Check for Custom Node Updates": "Check for Custom Node Updates", + "Toggle the Custom Nodes Manager": "Toggle the Custom Nodes Manager", "Toggle the Custom Nodes Manager Progress Bar": "Toggle the Custom Nodes Manager Progress Bar", "Decrease Brush Size in MaskEditor": "Decrease Brush Size in MaskEditor", "Increase Brush Size in MaskEditor": "Increase Brush Size in MaskEditor", "Open Mask Editor for Selected Node": "Open Mask Editor for Selected Node", - "Unload Models": "Unload Models", - "Unload Models and Execution Cache": "Unload Models and Execution Cache", "New": "New", "Clipspace": "Clipspace", "Open": "Open", diff --git a/src/schemas/apiSchema.ts b/src/schemas/apiSchema.ts index 9fe4bc26f..1f7c640e8 100644 --- a/src/schemas/apiSchema.ts +++ b/src/schemas/apiSchema.ts @@ -511,7 +511,8 @@ const zSettings = z.object({ 'main.sub.setting.name': z.any(), 'single.setting': z.any(), 'LiteGraph.Node.DefaultPadding': z.boolean(), - 'LiteGraph.Pointer.TrackpadGestures': z.boolean() + 'LiteGraph.Pointer.TrackpadGestures': z.boolean(), + 'Comfy.Memory.AllowManualUnload': z.boolean() }) export type EmbeddingsResponse = z.infer diff --git a/src/scripts/api.ts b/src/scripts/api.ts index 7cfa96d6c..8ac138c5d 100644 --- a/src/scripts/api.ts +++ b/src/scripts/api.ts @@ -1,6 +1,5 @@ import axios from 'axios' -import defaultClientFeatureFlags from '@/config/clientFeatureFlags.json' import type { DisplayComponentWsMessage, EmbeddingsResponse, @@ -12,7 +11,6 @@ import type { ExecutionStartWsMessage, ExecutionSuccessWsMessage, ExtensionsResponse, - FeatureFlagsWsMessage, HistoryTaskItem, LogsRawResponse, LogsWsMessage, @@ -116,7 +114,6 @@ interface BackendApiCalls { progress_text: ProgressTextWsMessage progress_state: ProgressStateWsMessage display_component: DisplayComponentWsMessage - feature_flags: FeatureFlagsWsMessage } /** Dictionary of all api calls */ @@ -246,19 +243,6 @@ export class ComfyApi extends EventTarget { reportedUnknownMessageTypes = new Set() - /** - * Get feature flags supported by this frontend client. - * Returns a copy to prevent external modification. - */ - getClientFeatureFlags(): Record { - return { ...defaultClientFeatureFlags } - } - - /** - * Feature flags received from the backend server. - */ - serverFeatureFlags: Record = {} - /** * The auth token for the comfy org account if the user is logged in. * This is only used for {@link queuePrompt} now. It is not directly @@ -400,15 +384,6 @@ export class ComfyApi extends EventTarget { this.socket.addEventListener('open', () => { opened = true - - // Send feature flags as the first message - this.socket!.send( - JSON.stringify({ - type: 'feature_flags', - data: this.getClientFeatureFlags() - }) - ) - if (isReconnect) { this.dispatchCustomEvent('reconnected') } @@ -530,14 +505,6 @@ export class ComfyApi extends EventTarget { case 'b_preview': this.dispatchCustomEvent(msg.type, msg.data) break - case 'feature_flags': - // Store server feature flags - this.serverFeatureFlags = msg.data - console.log( - 'Server feature flags received:', - this.serverFeatureFlags - ) - break default: if (this.#registered.has(msg.type)) { // Fallback for custom types - calls super direct. @@ -1002,7 +969,17 @@ export class ComfyApi extends EventTarget { return (await axios.get(this.internalURL('/folder_paths'))).data } - /* Frees memory by unloading models and optionally freeing execution cache + /** + * Gets the custom nodes i18n data from the server. + * + * @returns The custom nodes i18n data + */ + async getCustomNodesI18n(): Promise> { + return (await axios.get(this.apiURL('/i18n'))).data + } + + /** + * Frees memory by unloading models and optionally freeing execution cache * @param {Object} options - The options object * @param {boolean} options.freeExecutionCache - If true, also frees execution cache */ @@ -1051,42 +1028,6 @@ export class ComfyApi extends EventTarget { }) } } - - /** - * Gets the custom nodes i18n data from the server. - * - * @returns The custom nodes i18n data - */ - async getCustomNodesI18n(): Promise> { - return (await axios.get(this.apiURL('/i18n'))).data - } - - /** - * Checks if the server supports a specific feature. - * @param featureName The name of the feature to check - * @returns true if the feature is supported, false otherwise - */ - serverSupportsFeature(featureName: string): boolean { - return this.serverFeatureFlags[featureName] === true - } - - /** - * Gets a server feature flag value. - * @param featureName The name of the feature to get - * @param defaultValue The default value if the feature is not found - * @returns The feature value or default - */ - getServerFeature(featureName: string, defaultValue?: T): T { - return (this.serverFeatureFlags[featureName] ?? defaultValue) as T - } - - /** - * Gets all server feature flags. - * @returns Copy of all server feature flags - */ - getServerFeatures(): Record { - return { ...this.serverFeatureFlags } - } } export const api = new ComfyApi()