Skip to content

Commit

Permalink
Make port and host configurable with setting.launchArgs (#472)
Browse files Browse the repository at this point in the history
  • Loading branch information
huchenlei authored Dec 12, 2024
1 parent a376211 commit bc6bc31
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/main-process/appWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions src/main-process/comfyServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
}

Expand Down
10 changes: 7 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string> = process.env.COMFYUI_CPU_ONLY === 'true' ? { cpu: '' } : {};
const extraServerArgs: Record<string, string> = {
...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 });
Expand Down

0 comments on commit bc6bc31

Please sign in to comment.