From 86b2e1aa6c2f5ef451f8a62b07b4b8e1eac9b049 Mon Sep 17 00:00:00 2001 From: Chenlei Hu Date: Thu, 14 Nov 2024 19:57:09 -0500 Subject: [PATCH] Add electron adapter extension (#1538) --- src/extensions/core/electronAdapter.ts | 138 +++++++++++++++++++++++++ src/extensions/core/index.ts | 1 + 2 files changed, 139 insertions(+) create mode 100644 src/extensions/core/electronAdapter.ts diff --git a/src/extensions/core/electronAdapter.ts b/src/extensions/core/electronAdapter.ts new file mode 100644 index 000000000..50c58d3d2 --- /dev/null +++ b/src/extensions/core/electronAdapter.ts @@ -0,0 +1,138 @@ +import { app } from '@/scripts/app' +import { electronAPI as getElectronAPI, isElectron } from '@/utils/envUtil' +;(async () => { + if (!isElectron()) return + + const electronAPI = getElectronAPI() + const desktopAppVersion = await electronAPI.getElectronVersion() + app.registerExtension({ + name: 'Comfy.ElectronAdapter', + settings: [ + { + id: 'Comfy-Desktop.AutoUpdate', + category: ['Comfy-Desktop', 'General', 'AutoUpdate'], + name: 'Automatically check for updates', + type: 'boolean', + defaultValue: true, + onChange(newValue, oldValue) { + if (oldValue !== undefined && newValue !== oldValue) { + electronAPI.restartApp( + 'Restart ComfyUI to apply changes.', + 1500 // add delay to allow changes to take effect before restarting. + ) + } + } + } + ], + + commands: [ + { + id: 'Comfy-Desktop.Folders.OpenLogsFolder', + label: 'Open Logs Folder', + icon: 'pi pi-folder-open', + function() { + electronAPI.openLogsFolder() + } + }, + { + id: 'Comfy-Desktop.Folders.OpenModelsFolder', + label: 'Open Models Folder', + icon: 'pi pi-folder-open', + function() { + electronAPI.openModelsFolder() + } + }, + { + id: 'Comfy-Desktop.Folders.OpenOutputsFolder', + label: 'Open Outputs Folder', + icon: 'pi pi-folder-open', + function() { + electronAPI.openOutputsFolder() + } + }, + { + id: 'Comfy-Desktop.Folders.OpenInputsFolder', + label: 'Open Inputs Folder', + icon: 'pi pi-folder-open', + function() { + electronAPI.openInputsFolder() + } + }, + { + id: 'Comfy-Desktop.Folders.OpenCustomNodesFolder', + label: 'Open Custom Nodes Folder', + icon: 'pi pi-folder-open', + function() { + electronAPI.openCustomNodesFolder() + } + }, + { + id: 'Comfy-Desktop.Folders.OpenModelConfig', + label: 'Open extra_model_paths.yaml', + icon: 'pi pi-file', + function() { + electronAPI.openModelConfig() + } + }, + { + id: 'Comfy-Desktop.OpenDevTools', + label: 'Open DevTools', + icon: 'pi pi-code', + function() { + electronAPI.openDevTools() + } + }, + { + id: 'Comfy-Desktop.OpenFeedbackPage', + label: 'Feedback', + icon: 'pi pi-envelope', + function() { + window.open('https://forum.comfy.org/c/v1-feedback/', '_blank') + } + }, + { + id: 'Comfy-Desktop.Reinstall', + label: 'Reinstall', + icon: 'pi pi-refresh', + function() { + // TODO(huchenlei): Add a confirmation dialog. + electronAPI.reinstall() + } + } + ], + + menuCommands: [ + { + path: ['Help'], + commands: ['Comfy-Desktop.OpenFeedbackPage'] + }, + { + path: ['Help'], + commands: ['Comfy-Desktop.OpenDevTools'] + }, + { + path: ['Help', 'Open Folder'], + commands: [ + 'Comfy-Desktop.Folders.OpenLogsFolder', + 'Comfy-Desktop.Folders.OpenModelsFolder', + 'Comfy-Desktop.Folders.OpenOutputsFolder', + 'Comfy-Desktop.Folders.OpenInputsFolder', + 'Comfy-Desktop.Folders.OpenCustomNodesFolder', + 'Comfy-Desktop.Folders.OpenModelConfig' + ] + }, + { + path: ['Help'], + commands: ['Comfy-Desktop.Reinstall'] + } + ], + + aboutPageBadges: [ + { + label: 'ComfyUI_Desktop ' + desktopAppVersion, + url: 'https://github.com/Comfy-Org/electron', + icon: 'pi pi-github' + } + ] + }) +})() diff --git a/src/extensions/core/index.ts b/src/extensions/core/index.ts index 3365531af..7e7c355e4 100644 --- a/src/extensions/core/index.ts +++ b/src/extensions/core/index.ts @@ -20,3 +20,4 @@ import './uploadImage' import './webcamCapture' import './widgetInputs' import './uploadAudio' +import './electronAdapter'