From 0d95071fc2b41b653e2004365888ea3406768cc3 Mon Sep 17 00:00:00 2001 From: huchenlei Date: Thu, 12 Dec 2024 11:03:21 -0800 Subject: [PATCH] Make port and host configurable with setting.launchArgs --- src/main-process/appWindow.ts | 3 ++- src/main-process/comfyServer.ts | 1 + src/main.ts | 10 +++++++--- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main-process/appWindow.ts b/src/main-process/appWindow.ts index 5dcb9ff6..dbb07a9f 100644 --- a/src/main-process/appWindow.ts +++ b/src/main-process/appWindow.ts @@ -104,7 +104,8 @@ export class AppWindow { } public loadComfyUI(serverArgs: ServerArgs) { - this.window.loadURL(`http://${serverArgs.host}:${serverArgs.port}`); + const host = serverArgs.host === '0.0.0.0' ? 'localhost' : serverArgs.host; + this.window.loadURL(`http://${host}:${serverArgs.port}`); } public openDevTools(): void { diff --git a/src/main-process/comfyServer.ts b/src/main-process/comfyServer.ts index 3064fe9e..a63dfd6e 100644 --- a/src/main-process/comfyServer.ts +++ b/src/main-process/comfyServer.ts @@ -75,6 +75,7 @@ export class ComfyServer { 'front-end-root': this.webRootPath, 'extra-model-paths-config': ComfyServerConfig.configPath, port: this.serverArgs.port.toString(), + listen: this.serverArgs.host, }; } diff --git a/src/main.ts b/src/main.ts index 9a2889fa..b77c3841 100644 --- a/src/main.ts +++ b/src/main.ts @@ -73,14 +73,18 @@ async function startApp() { SentryLogging.comfyDesktopApp = comfyDesktopApp; const useExternalServer = process.env.USE_EXTERNAL_SERVER === 'true'; - const host = process.env.COMFY_HOST || DEFAULT_SERVER_ARGS.host; - const targetPort = process.env.COMFY_PORT ? parseInt(process.env.COMFY_PORT) : DEFAULT_SERVER_ARGS.port; - const port = useExternalServer ? targetPort : await findAvailablePort(host, targetPort, targetPort + 1000); const cpuOnly: Record = process.env.COMFYUI_CPU_ONLY === 'true' ? { cpu: '' } : {}; const extraServerArgs: Record = { ...comfyDesktopApp.comfySettings.get('Comfy.Server.LaunchArgs'), ...cpuOnly, }; + const host = process.env.COMFY_HOST ?? extraServerArgs.listen ?? DEFAULT_SERVER_ARGS.host; + const targetPort = Number(process.env.COMFY_PORT ?? extraServerArgs.port ?? DEFAULT_SERVER_ARGS.port); + const port = useExternalServer ? targetPort : await findAvailablePort(host, targetPort, targetPort + 1000); + + // Remove listen and port from extraServerArgs so core launch args are used instead. + delete extraServerArgs.listen; + delete extraServerArgs.port; if (!useExternalServer) { await comfyDesktopApp.startComfyServer({ host, port, extraServerArgs });