LCOV - code coverage report
Current view: top level - src/extensions/core - electronAdapter.ts Coverage Total Hit
Test: ComfyUI E2E Coverage Lines: 100.0 % 2 2
Test Date: 2026-11-17 04:17:53

            Line data    Source code
       1              : import log from 'loglevel'
       2              : 
       3              : import { useExternalLink } from '@/composables/useExternalLink'
       4              : import { PYTHON_MIRROR } from '@/constants/uvMirrors'
       5              : import { t } from '@/i18n'
       6              : import { useToast } from '@/components/ui/toast/toastStore'
       7              : import { useWorkflowStore } from '@/platform/workflow/management/stores/workflowStore'
       8              : import { app } from '@/scripts/app'
       9              : import { useDialogService } from '@/services/dialogService'
      10              : import { checkMirrorReachable } from '@/utils/electronMirrorCheck'
      11              : import { isDesktop } from '@/platform/distribution/types'
      12              : import { electronAPI as getElectronAPI } from '@/utils/envUtil'
      13              : import { reportError } from '@comfyorg/telemetry/reportError'
      14              : 
      15         2355 : export async function registerElectronAdapterExtension(): Promise<boolean> {
      16         2355 :   if (!isDesktop) return false
      17              : 
      18              :   const electronAPI = getElectronAPI()
      19              :   const desktopAppVersion = await electronAPI
      20              :     .getElectronVersion()
      21              :     .catch((error: unknown) => {
      22              :       reportError(error, {
      23              :         surface: 'platform',
      24              :         errorType: 'failure_reading_desktop_app_version'
      25              :       })
      26              :       return undefined
      27              :     })
      28              :   if (desktopAppVersion === undefined) return false
      29              : 
      30              :   const workflowStore = useWorkflowStore()
      31              :   const toast = useToast()
      32              :   const { staticUrls, buildDocsUrl } = useExternalLink()
      33              : 
      34              :   const onChangeRestartApp = async (newValue: unknown, oldValue: unknown) => {
      35              :     if (oldValue !== undefined && newValue !== oldValue) {
      36              :       await electronAPI.restartApp('Restart ComfyUI to apply changes.', 1500)
      37              :     }
      38              :   }
      39              : 
      40              :   app.registerExtension({
      41              :     name: 'Comfy.ElectronAdapter',
      42              :     settings: [
      43              :       {
      44              :         id: 'Comfy-Desktop.AutoUpdate',
      45              :         category: ['Comfy-Desktop', 'General', 'AutoUpdate'],
      46              :         name: 'Automatically check for updates',
      47              :         type: 'boolean',
      48              :         defaultValue: true,
      49              :         onChange: onChangeRestartApp
      50              :       },
      51              :       {
      52              :         id: 'Comfy-Desktop.SendStatistics',
      53              :         category: ['Comfy-Desktop', 'General', 'Send Statistics'],
      54              :         name: 'Send anonymous usage metrics',
      55              :         type: 'boolean',
      56              :         defaultValue: true,
      57              :         onChange: onChangeRestartApp
      58              :       },
      59              :       {
      60              :         id: 'Comfy-Desktop.WindowStyle',
      61              :         category: ['Comfy-Desktop', 'General', 'Window Style'],
      62              :         name: 'Window Style',
      63              :         tooltip: "Custom: Replace the system title bar with ComfyUI's Top menu",
      64              :         type: 'combo',
      65              :         experimental: true,
      66              :         defaultValue: 'default',
      67              :         options: ['default', 'custom'],
      68              :         onChange: async (
      69              :           newValue: 'default' | 'custom',
      70              :           oldValue?: 'default' | 'custom'
      71              :         ) => {
      72              :           if (!oldValue) return
      73              : 
      74              :           await electronAPI.Config.setWindowStyle(newValue)
      75              :         }
      76              :       },
      77              :       {
      78              :         id: 'Comfy-Desktop.UV.PythonInstallMirror',
      79              :         name: 'Python Install Mirror',
      80              :         tooltip: `Managed Python installations are downloaded from the Astral python-build-standalone project. This variable can be set to a mirror URL to use a different source for Python installations. The provided URL will replace https://github.com/astral-sh/python-build-standalone/releases/download in, e.g., https://github.com/astral-sh/python-build-standalone/releases/download/20240713/cpython-3.12.4%2B20240713-aarch64-apple-darwin-install_only.tar.gz. Distributions can be read from a local directory by using the file:// URL scheme.`,
      81              :         type: 'url',
      82              :         defaultValue: '',
      83              :         attrs: {
      84              :           validateUrlFn(mirror: string) {
      85              :             return checkMirrorReachable(
      86              :               mirror + PYTHON_MIRROR.validationPathSuffix
      87              :             )
      88              :           }
      89              :         }
      90              :       },
      91              :       {
      92              :         id: 'Comfy-Desktop.UV.PypiInstallMirror',
      93              :         name: 'Pypi Install Mirror',
      94              :         tooltip: `Default pip install mirror`,
      95              :         type: 'url',
      96              :         defaultValue: '',
      97              :         attrs: {
      98              :           validateUrlFn: checkMirrorReachable
      99              :         }
     100              :       },
     101              :       {
     102              :         id: 'Comfy-Desktop.UV.TorchInstallMirror',
     103              :         name: 'Torch Install Mirror',
     104              :         tooltip: `Pip install mirror for pytorch`,
     105              :         type: 'url',
     106              :         defaultValue: '',
     107              :         attrs: {
     108              :           validateUrlFn: checkMirrorReachable
     109              :         }
     110              :       }
     111              :     ],
     112              : 
     113              :     commands: [
     114              :       {
     115              :         id: 'Comfy-Desktop.Folders.OpenLogsFolder',
     116              :         label: 'Open Logs Folder',
     117              :         icon: 'icon-[lucide--folder-open]',
     118              :         function() {
     119              :           electronAPI.openLogsFolder()
     120              :         }
     121              :       },
     122              :       {
     123              :         id: 'Comfy-Desktop.Folders.OpenModelsFolder',
     124              :         label: 'Open Models Folder',
     125              :         icon: 'icon-[lucide--folder-open]',
     126              :         async function() {
     127              :           await electronAPI.openModelsFolder()
     128              :         }
     129              :       },
     130              :       {
     131              :         id: 'Comfy-Desktop.Folders.OpenOutputsFolder',
     132              :         label: 'Open Outputs Folder',
     133              :         icon: 'icon-[lucide--folder-open]',
     134              :         async function() {
     135              :           await electronAPI.openOutputsFolder()
     136              :         }
     137              :       },
     138              :       {
     139              :         id: 'Comfy-Desktop.Folders.OpenInputsFolder',
     140              :         label: 'Open Inputs Folder',
     141              :         icon: 'icon-[lucide--folder-open]',
     142              :         async function() {
     143              :           await electronAPI.openInputsFolder()
     144              :         }
     145              :       },
     146              :       {
     147              :         id: 'Comfy-Desktop.Folders.OpenCustomNodesFolder',
     148              :         label: 'Open Custom Nodes Folder',
     149              :         icon: 'icon-[lucide--folder-open]',
     150              :         async function() {
     151              :           await electronAPI.openCustomNodesFolder()
     152              :         }
     153              :       },
     154              :       {
     155              :         id: 'Comfy-Desktop.Folders.OpenModelConfig',
     156              :         label: 'Open extra_model_paths.yaml',
     157              :         icon: 'icon-[lucide--file]',
     158              :         async function() {
     159              :           await electronAPI.openModelConfig()
     160              :         }
     161              :       },
     162              :       {
     163              :         id: 'Comfy-Desktop.OpenDevTools',
     164              :         label: 'Open DevTools',
     165              :         icon: 'icon-[lucide--code]',
     166              :         function() {
     167              :           electronAPI.openDevTools()
     168              :         }
     169              :       },
     170              :       {
     171              :         id: 'Comfy-Desktop.OpenUserGuide',
     172              :         label: 'Desktop User Guide',
     173              :         icon: 'icon-[lucide--book]',
     174              :         function() {
     175              :           window.open(
     176              :             buildDocsUrl('/installation/desktop', {
     177              :               includeLocale: true,
     178              :               platform: true
     179              :             }),
     180              :             '_blank'
     181              :           )
     182              :         }
     183              :       },
     184              :       {
     185              :         id: 'Comfy-Desktop.CheckForUpdates',
     186              :         label: 'Check for Updates',
     187              :         icon: 'icon-[lucide--refresh-cw]',
     188              :         async function() {
     189              :           try {
     190              :             const updateInfo = await electronAPI.checkForUpdates({
     191              :               disableUpdateReadyAction: true
     192              :             })
     193              : 
     194              :             if (!updateInfo.isUpdateAvailable) {
     195              :               toast.info(t('desktopUpdate.noUpdateFound'), {
     196              :                 duration: 5_000
     197              :               })
     198              :               return
     199              :             }
     200              : 
     201              :             const proceed = await useDialogService().confirm({
     202              :               title: t('desktopUpdate.updateFoundTitle', {
     203              :                 version: updateInfo.version
     204              :               }),
     205              :               message: t('desktopUpdate.updateAvailableMessage'),
     206              :               type: 'default'
     207              :             })
     208              :             if (proceed) {
     209              :               try {
     210              :                 await electronAPI.restartAndInstall()
     211              :               } catch (error) {
     212              :                 log.error('Error installing update:', error)
     213              :                 toast.error(t('g.error'), {
     214              :                   description: t('desktopUpdate.errorInstallingUpdate')
     215              :                 })
     216              :               }
     217              :             }
     218              :           } catch (error) {
     219              :             log.error('Error checking for updates:', error)
     220              :             toast.error(t('g.error'), {
     221              :               description: t('desktopUpdate.errorCheckingUpdate')
     222              :             })
     223              :           }
     224              :         }
     225              :       },
     226              :       {
     227              :         id: 'Comfy-Desktop.Reinstall',
     228              :         label: 'Reinstall',
     229              :         icon: 'icon-[lucide--rotate-cw]',
     230              :         async function() {
     231              :           const proceed = await useDialogService().confirm({
     232              :             message: t('desktopMenu.confirmReinstall'),
     233              :             title: t('desktopMenu.reinstall'),
     234              :             type: 'reinstall'
     235              :           })
     236              : 
     237              :           if (proceed) await electronAPI.reinstall()
     238              :         }
     239              :       },
     240              :       {
     241              :         id: 'Comfy-Desktop.Restart',
     242              :         label: 'Restart',
     243              :         icon: 'icon-[lucide--rotate-cw]',
     244              :         async function() {
     245              :           await electronAPI.restartApp()
     246              :         }
     247              :       },
     248              :       {
     249              :         id: 'Comfy-Desktop.Quit',
     250              :         label: 'Quit',
     251              :         icon: 'icon-[lucide--log-out]',
     252              :         async function() {
     253              :           if (workflowStore.modifiedWorkflows.length > 0) {
     254              :             const confirmed = await useDialogService().confirm({
     255              :               message: t('desktopMenu.confirmQuit'),
     256              :               title: t('desktopMenu.quit'),
     257              :               type: 'default'
     258              :             })
     259              : 
     260              :             if (!confirmed) return
     261              :           }
     262              : 
     263              :           await electronAPI.quit()
     264              :         }
     265              :       }
     266              :     ],
     267              : 
     268              :     menuCommands: [
     269              :       {
     270              :         path: ['Help'],
     271              :         commands: ['Comfy-Desktop.OpenUserGuide']
     272              :       },
     273              :       {
     274              :         path: ['Help'],
     275              :         commands: ['Comfy-Desktop.OpenDevTools']
     276              :       },
     277              :       {
     278              :         path: ['Help', 'Open Folder'],
     279              :         commands: [
     280              :           'Comfy-Desktop.Folders.OpenLogsFolder',
     281              :           'Comfy-Desktop.Folders.OpenModelsFolder',
     282              :           'Comfy-Desktop.Folders.OpenOutputsFolder',
     283              :           'Comfy-Desktop.Folders.OpenInputsFolder',
     284              :           'Comfy-Desktop.Folders.OpenCustomNodesFolder',
     285              :           'Comfy-Desktop.Folders.OpenModelConfig'
     286              :         ]
     287              :       },
     288              :       {
     289              :         path: ['Help'],
     290              :         commands: ['Comfy-Desktop.CheckForUpdates', 'Comfy-Desktop.Reinstall']
     291              :       }
     292              :     ],
     293              : 
     294              :     keybindings: [
     295              :       {
     296              :         commandId: 'Workspace.CloseWorkflow',
     297              :         combo: {
     298              :           key: 'w',
     299              :           ctrl: true
     300              :         }
     301              :       }
     302              :     ],
     303              : 
     304              :     aboutPageBadges: [
     305              :       {
     306              :         label: 'ComfyUI_desktop v' + desktopAppVersion,
     307              :         url: staticUrls.githubElectron,
     308              :         icon: 'icon-[lucide--github]'
     309              :       }
     310              :     ]
     311              :   })
     312              :   return true
     313              : }
        

Generated by: LCOV version 2.0-1