LCOV - code coverage report
Current view: top level - src/stores - workspaceStore.ts Coverage Total Hit
Test: ComfyUI E2E Coverage Lines: 76.7 % 43 33
Test Date: 2026-11-17 04:17:53

            Line data    Source code
       1              : import { useMagicKeys } from '@vueuse/core'
       2              : import { defineStore } from 'pinia'
       3              : import { computed, ref } from 'vue'
       4              : 
       5              : import { useToast } from '@/components/ui/toast/toastStore'
       6              : import { useSettingStore } from '@/platform/settings/settingStore'
       7              : import { reportError } from '@comfyorg/telemetry/reportError'
       8              : import { useWorkflowStore } from '@/platform/workflow/management/stores/workflowStore'
       9              : import type { Settings } from '@comfyorg/settings-core/types'
      10              : import { useLegacyColorPaletteService } from '@/platform/theme/themeService'
      11              : import { useExtensionDialogService } from '@/services/dialogService'
      12              : import type {
      13              :   SidebarTabExtension,
      14              :   ToastManager,
      15              :   ToastMessageOptions
      16              : } from '@/types/extensionTypes'
      17              : import { renderMarkdownToHtml } from '@/utils/markdownRendererUtil'
      18              : 
      19              : import { useApiKeyAuthStore } from './apiKeyAuthStore'
      20              : import { useCommandStore } from '@/platform/keybindings/commandStore'
      21              : import { useExecutionErrorStore } from './executionErrorStore'
      22              : import { useAuthStore } from './authStore'
      23              : import { useQueueSettingsStore } from './queueSettingsStore'
      24              : import { useBottomPanelStore } from './workspace/bottomPanelStore'
      25              : import { useSidebarTabStore } from './workspace/sidebarTabStore'
      26              : 
      27         2356 : const legacySeverityKinds = new Map<
      28              :   string,
      29              :   'error' | 'info' | 'success' | 'warning'
      30              : >([
      31              :   ['contrast', 'info'],
      32              :   ['error', 'error'],
      33              :   ['info', 'info'],
      34              :   ['secondary', 'info'],
      35              :   ['success', 'success'],
      36              :   ['warn', 'warning'],
      37              :   ['warning', 'warning']
      38              : ])
      39              : 
      40         2355 : function workspaceStoreSetup() {
      41         2355 :   const spinner = ref(false)
      42         2355 :   const { shift: shiftDown } = useMagicKeys()
      43              :   /**
      44              :    * Whether the workspace is in focus mode.
      45              :    * When in focus mode, only the graph editor is visible.
      46              :    */
      47         2355 :   const focusMode = ref(false)
      48              : 
      49         2355 :   const toastStore = useToast()
      50         2355 :   let reportedWarningSeverity = false
      51            0 :   function reportWarningSeverity() {
      52            0 :     if (reportedWarningSeverity) return
      53            0 :     reportedWarningSeverity = true
      54            0 :     reportError(new Error('toast.add received severity "warning"'), {
      55              :       surface: 'platform',
      56              :       errorType: 'deprecated_toast_warning_severity',
      57              :       level: 'warning'
      58              :     })
      59              :   }
      60         2355 :   const toast: ToastManager = {
      61              :     add: (message: ToastMessageOptions) => {
      62            1 :       const severity: string = message.severity ?? 'info'
      63            1 :       if (severity === 'warning') reportWarningSeverity()
      64            1 :       const kind = legacySeverityKinds.get(severity)
      65            1 :       if (!kind) {
      66            0 :         console.error(`toast.add: unsupported severity "${severity}"`)
      67            0 :         return
      68              :       }
      69            1 :       toastStore[kind](message.summary ?? message.detail ?? '', {
      70              :         closable: message.closable,
      71              :         description: message.summary === undefined ? undefined : message.detail,
      72              :         duration: message.life || undefined
      73              :       })
      74              :     },
      75              :     addAlert: (message) => toastStore.warning(message),
      76              :     dismiss: toastStore.dismiss,
      77              :     dismissAll: toastStore.dismissAll,
      78              :     error: toastStore.error,
      79              :     info: toastStore.info,
      80              :     loading: toastStore.loading,
      81              :     success: toastStore.success,
      82              :     warning: toastStore.warning
      83              :   }
      84         2355 :   const queueSettings = computed(() => useQueueSettingsStore())
      85         2355 :   const command = computed(() => ({
      86              :     commands: useCommandStore().commands,
      87              :     execute: useCommandStore().execute
      88              :   }))
      89         2355 :   const sidebarTab = computed(() => useSidebarTabStore())
      90         2355 :   const setting = computed(() => ({
      91              :     settings: useSettingStore().settingsById,
      92              :     // Allow generic key access to settings as custom nodes may add their
      93              :     // own settings which is not tracked by the `Setting` schema.
      94              :     // oxlint-disable-next-line typescript/no-unnecessary-type-parameters
      95              :     get: <T = unknown>(key: string): T | undefined =>
      96              :       useSettingStore().get(key as keyof Settings) as T | undefined,
      97              :     set: (key: string, value: unknown) =>
      98              :       useSettingStore().set(
      99              :         key as keyof Settings,
     100              :         value as Settings[keyof Settings]
     101              :       )
     102              :   }))
     103         2355 :   const workflow = computed(() => useWorkflowStore())
     104         2355 :   const colorPalette = useLegacyColorPaletteService()
     105         2355 :   const dialog = computed(() => useExtensionDialogService())
     106         2355 :   const bottomPanel = useBottomPanelStore()
     107              : 
     108         2355 :   const authStore = useAuthStore()
     109         2355 :   const apiKeyStore = useApiKeyAuthStore()
     110              : 
     111         2355 :   const isApiKeyLogin = computed(() => apiKeyStore.isAuthenticated)
     112              :   const isLoggedIn = computed(
     113              :     () => isApiKeyLogin.value || authStore.isAuthenticated
     114              :   )
     115         2355 :   const partialUserStore = {
     116              :     isLoggedIn
     117              :   }
     118              : 
     119              :   /**
     120              :    * Registers a sidebar tab.
     121              :    * @param tab The sidebar tab to register.
     122              :    * @deprecated Use `sidebarTab.registerSidebarTab` instead.
     123              :    */
     124            2 :   function registerSidebarTab(tab: SidebarTabExtension) {
     125            2 :     sidebarTab.value.registerSidebarTab(tab)
     126              :   }
     127              : 
     128            0 :   function registerSidebarTabForExtension(
     129              :     tab: SidebarTabExtension,
     130              :     extensionName: string
     131              :   ) {
     132            0 :     sidebarTab.value.registerSidebarTab(tab, undefined, extensionName)
     133              :   }
     134              : 
     135              :   /**
     136              :    * Unregisters a sidebar tab.
     137              :    * @param id The id of the sidebar tab to unregister.
     138              :    * @deprecated Use `sidebarTab.unregisterSidebarTab` instead.
     139              :    */
     140            0 :   function unregisterSidebarTab(id: string) {
     141            0 :     sidebarTab.value.unregisterSidebarTab(id)
     142              :   }
     143              : 
     144              :   /**
     145              :    * Gets all registered sidebar tabs.
     146              :    * @returns All registered sidebar tabs.
     147              :    * @deprecated Use `sidebarTab.sidebarTabs` instead.
     148              :    */
     149         2097 :   function getSidebarTabs(): SidebarTabExtension[] {
     150         2097 :     return sidebarTab.value.sidebarTabs
     151              :   }
     152              : 
     153         2355 :   const executionErrorStore = useExecutionErrorStore()
     154              : 
     155         2355 :   return {
     156              :     spinner,
     157              :     shiftDown,
     158              :     focusMode,
     159              :     toggleFocusMode: () => {
     160            3 :       focusMode.value = !focusMode.value
     161              :     },
     162              :     toast,
     163              :     queueSettings,
     164              :     command,
     165              :     sidebarTab,
     166              :     setting,
     167              :     workflow,
     168              :     colorPalette,
     169              :     dialog,
     170              :     bottomPanel,
     171              :     user: partialUserStore,
     172              : 
     173              :     // Execution error state (read-only, exposed for custom extensions)
     174              :     lastNodeErrors: computed(() => executionErrorStore.lastNodeErrors),
     175              :     lastExecutionError: computed(() => executionErrorStore.lastExecutionError),
     176              : 
     177              :     registerSidebarTab,
     178              :     registerSidebarTabForExtension,
     179              :     unregisterSidebarTab,
     180              :     getSidebarTabs,
     181              :     renderMarkdownToHtml
     182              :   }
     183              : }
     184              : 
     185         2356 : export const useWorkspaceStore = defineStore('workspace', workspaceStoreSetup)
        

Generated by: LCOV version 2.0-1