Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Launch comfy server with extra args specified in setting json #331

Merged
merged 4 commits into from
Nov 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"main": ".vite/build/main.js",
"packageManager": "[email protected]",
"config": {
"frontendVersion": "1.4.5",
"frontendVersion": "1.4.9",
"comfyVersion": "0.3.2",
"managerCommit": "1ab304bfbcfd7f550fc5adbb75a4e3b24861b947",
"uvVersion": "0.5.2"
Expand Down
2 changes: 2 additions & 0 deletions src/config/comfySettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ export const DEFAULT_SETTINGS: ComfySettingsData = {
'Comfy.UseNewMenu': 'Top',
'Comfy.Workflow.WorkflowTabsPosition': 'Topbar',
'Comfy.Workflow.ShowMissingModelsWarning': true,
'Comfy.Server.LaunchArgs': {},
} as const;

export interface ComfySettingsData {
'Comfy-Desktop.AutoUpdate': boolean;
'Comfy-Desktop.SendStatistics': boolean;
'Comfy.Server.LaunchArgs': Record<string, string | boolean>;
[key: string]: unknown;
}

Expand Down
2 changes: 1 addition & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export const DEFAULT_SERVER_ARGS = {
/** The port to use for the ComfyUI server. */
port: 8000,
// Extra arguments to pass to the ComfyUI server.
extraServerArgs: {} as Record<string, string>,
extraServerArgs: {} as Record<string, string | boolean>,
};

export type ServerArgs = typeof DEFAULT_SERVER_ARGS;
Expand Down
16 changes: 9 additions & 7 deletions src/main-process/comfyServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ export class ComfyServer {
*/
get coreLaunchArgs() {
return {
'--user-directory': this.userDirectoryPath,
'--input-directory': this.inputDirectoryPath,
'--output-directory': this.outputDirectoryPath,
'--front-end-root': this.webRootPath,
'--extra-model-paths-config': ComfyServerConfig.configPath,
'--port': this.serverArgs.port.toString(),
'user-directory': this.userDirectoryPath,
'input-directory': this.inputDirectoryPath,
'output-directory': this.outputDirectoryPath,
'front-end-root': this.webRootPath,
'extra-model-paths-config': ComfyServerConfig.configPath,
port: this.serverArgs.port.toString(),
};
}

Expand All @@ -75,8 +75,10 @@ export class ComfyServer {
...this.serverArgs.extraServerArgs,
...this.coreLaunchArgs,
})
.map(([key, value]) => [`--${key}`, value])
.flat()
.filter((value: string) => !!value)
// Boolean true values are ignored. e.g. { '--cpu': true } => '--cpu'
.filter((value: string | boolean) => typeof value === 'string' && value !== '')
);
}

Expand Down
7 changes: 6 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,12 @@ if (!gotTheLock) {
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 extraServerArgs: Record<string, string> = process.env.COMFYUI_CPU_ONLY === 'true' ? { '--cpu': '' } : {};
const cpuOnly: Record<string, string | boolean> =
process.env.COMFYUI_CPU_ONLY === 'true' ? { '--cpu': true } : {};
const extraServerArgs: Record<string, string | boolean> = {
...comfyDesktopApp.comfySettings.get('Comfy.Server.LaunchArgs'),
...cpuOnly,
};

if (!useExternalServer) {
await comfyDesktopApp.startComfyServer({ host, port, extraServerArgs });
Expand Down
Loading