LCOV - code coverage report
Current view: top level - src/composables - useBrowserTabTitle.ts Coverage Total Hit
Test: ComfyUI E2E Coverage Lines: 97.2 % 36 35
Test Date: 2026-11-17 04:17:53

            Line data    Source code
       1              : import { useTitle } from '@vueuse/core'
       2              : import { computed } from 'vue'
       3              : 
       4              : import { t } from '@/i18n'
       5              : import { useSettingStore } from '@/platform/settings/settingStore'
       6              : import { useWorkflowStore } from '@/platform/workflow/management/stores/workflowStore'
       7              : import { useExecutionStore } from '@/stores/executionStore'
       8              : import { useBrowserTabTitleStore } from '@/stores/browserTabTitleStore'
       9              : import { useWorkspaceStore } from '@/stores/workspaceStore'
      10              : 
      11         2355 : const TITLE_SUFFIX = ' - ComfyUI'
      12              : 
      13         2355 : export const useBrowserTabTitle = () => {
      14         2355 :   const defaultTitle = document.title || 'ComfyUI'
      15         2355 :   const executionStore = useExecutionStore()
      16         2355 :   const settingStore = useSettingStore()
      17         2355 :   const workflowStore = useWorkflowStore()
      18         2355 :   const workspaceStore = useWorkspaceStore()
      19         2355 :   const titlePrefixes = useBrowserTabTitleStore()
      20              : 
      21         2355 :   const executionText = computed(() =>
      22              :     executionStore.isIdle
      23              :       ? ''
      24              :       : `[${Math.round(executionStore.executionProgress * 100)}%]`
      25              :   )
      26              : 
      27         2355 :   const newMenuEnabled = computed(
      28              :     () => settingStore.get('Comfy.UseNewMenu') !== 'Disabled'
      29              :   )
      30              : 
      31         2355 :   const isAutoSaveEnabled = computed(
      32              :     () => settingStore.get('Comfy.Workflow.AutoSave') === 'after delay'
      33              :   )
      34              : 
      35         2355 :   const isActiveWorkflowModified = computed(
      36              :     () => !!workflowStore.activeWorkflow?.isModified
      37              :   )
      38         2355 :   const isActiveWorkflowPersisted = computed(
      39              :     () => !!workflowStore.activeWorkflow?.isPersisted
      40              :   )
      41              : 
      42         2355 :   const shouldShowUnsavedIndicator = computed(() => {
      43         2277 :     if (workspaceStore.shiftDown) return false
      44         2277 :     if (isAutoSaveEnabled.value) return false
      45         2237 :     if (!isActiveWorkflowPersisted.value) return true
      46          459 :     if (isActiveWorkflowModified.value) return true
      47          156 :     return false
      48              :   })
      49              : 
      50         2355 :   const isUnsavedText = computed(() =>
      51              :     shouldShowUnsavedIndicator.value ? ' *' : ''
      52              :   )
      53         2355 :   const workflowNameText = computed(() => {
      54         5499 :     const workflowName = workflowStore.activeWorkflow?.filename
      55         5499 :     return workflowName
      56              :       ? isUnsavedText.value + workflowName + TITLE_SUFFIX
      57              :       : defaultTitle
      58              :   })
      59              : 
      60         2355 :   const nodeExecutionTitle = computed(() => {
      61              :     const nodeProgressEntries = Object.entries(
      62              :       executionStore.nodeProgressStates
      63              :     )
      64         6361 :     const runningNodes = nodeProgressEntries.filter(
      65              :       ([_, state]) => state.state === 'running'
      66              :     )
      67              : 
      68         6361 :     if (runningNodes.length === 0) {
      69         6270 :       return ''
      70              :     }
      71              : 
      72         2499 :     if (runningNodes.length > 1) {
      73            0 :       return `${executionText.value}[${runningNodes.length} ${t('g.nodesRunning', 'nodes running')}]`
      74              :     }
      75              : 
      76           91 :     const [, state] = runningNodes[0]
      77           91 :     const progress = Math.round((state.value / state.max) * 100)
      78         6361 :     const nodeLabel =
      79              :       executionStore.executingNode?.type?.trim() ||
      80              :       executionStore.executingNode?.title?.trim() ||
      81              :       'Node'
      82              : 
      83         6361 :     return `${executionText.value}[${progress}%] ${nodeLabel}`
      84              :   })
      85              : 
      86         2355 :   const workflowTitle = computed(
      87              :     () =>
      88              :       executionText.value +
      89              :       (newMenuEnabled.value ? workflowNameText.value : defaultTitle)
      90              :   )
      91              : 
      92         2355 :   const title = computed(
      93              :     () =>
      94              :       titlePrefixes.prefix + (nodeExecutionTitle.value || workflowTitle.value)
      95              :   )
      96         2355 :   useTitle(title)
      97              : }
        

Generated by: LCOV version 2.0-1