Skip to content

Commit

Permalink
Write comfy desktop install options to settings (#290)
Browse files Browse the repository at this point in the history
  • Loading branch information
huchenlei authored Nov 19, 2024
1 parent 6848467 commit 42837e4
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 33 deletions.
20 changes: 0 additions & 20 deletions src/config/comfyConfigManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,31 +47,11 @@ export class ComfyConfigManager {
],
];

private static readonly DEFAULT_CONFIG = {
'Comfy.ColorPalette': 'dark',
'Comfy.UseNewMenu': 'Top',
'Comfy.Workflow.WorkflowTabsPosition': 'Topbar',
'Comfy.Workflow.ShowMissingModelsWarning': true,
};

public static setUpComfyUI(localComfyDirectory: string) {
if (fs.existsSync(localComfyDirectory)) {
throw new Error(`Selected directory ${localComfyDirectory} already exists`);
}
this.createComfyDirectories(localComfyDirectory);
const userSettingsPath = path.join(localComfyDirectory, 'user', 'default');
this.createComfyConfigFile(userSettingsPath);
}

public static createComfyConfigFile(userSettingsPath: string): void {
const configFilePath = path.join(userSettingsPath, 'comfy.settings.json');

try {
fs.writeFileSync(configFilePath, JSON.stringify(this.DEFAULT_CONFIG, null, 2));
log.info(`Created new ComfyUI config file at: ${configFilePath}`);
} catch (error) {
log.error(`Failed to create new ComfyUI config file: ${error}`);
}
}

public static isComfyUIDirectory(directory: string): boolean {
Expand Down
7 changes: 6 additions & 1 deletion src/config/comfySettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@ import * as fs from 'fs';
import * as path from 'path';
import log from 'electron-log/main';

const DEFAULT_SETTINGS: ComfySettingsData = {
export const DEFAULT_SETTINGS: ComfySettingsData = {
'Comfy-Desktop.AutoUpdate': true,
'Comfy-Desktop.SendStatistics': true,
'Comfy.ColorPalette': 'dark',
'Comfy.UseNewMenu': 'Top',
'Comfy.Workflow.WorkflowTabsPosition': 'Topbar',
'Comfy.Workflow.ShowMissingModelsWarning': true,
} as const;

export interface ComfySettingsData {
'Comfy-Desktop.AutoUpdate': boolean;
'Comfy-Desktop.SendStatistics': boolean;
[key: string]: unknown;
}

/**
Expand Down
15 changes: 14 additions & 1 deletion src/main-process/comfyDesktopApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as Sentry from '@sentry/electron/main';
import { graphics } from 'systeminformation';
import todesktop from '@todesktop/runtime';
import { IPC_CHANNELS, ProgressStatus, ServerArgs } from '../constants';
import { ComfySettings } from '../config/comfySettings';
import { ComfySettings, DEFAULT_SETTINGS } from '../config/comfySettings';
import { AppWindow } from './appWindow';
import { ComfyServer } from './comfyServer';
import { ComfyServerConfig } from '../config/comfyServerConfig';
Expand Down Expand Up @@ -117,8 +117,21 @@ export class ComfyDesktopApp {
const migrationItemIds = new Set<string>(installOptions.migrationItemIds ?? []);

const basePath = path.join(installOptions.installPath, 'ComfyUI');
// Setup folder structures.
ComfyConfigManager.setUpComfyUI(basePath);

// Setup comfy.settings.json file
const settings = {
...DEFAULT_SETTINGS,
'Comfy-Desktop.AutoUpdate': installOptions.autoUpdate,
'Comfy-Desktop.SendStatistics': installOptions.allowMetrics,
};
const settingsJson = JSON.stringify(settings, null, 2);
const settingsPath = path.join(basePath, 'user', 'default', 'comfy.settings.json');
fs.writeFileSync(settingsPath, settingsJson);
log.info(`Wrote settings to ${settingsPath}: ${settingsJson}`);

// Setup extra_model_paths.yaml file
const { comfyui: comfyuiConfig, ...extraConfigs } = await ComfyServerConfig.getMigrationConfig(
migrationSource,
migrationItemIds
Expand Down
11 changes: 0 additions & 11 deletions tests/unit/comfyConfigManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,6 @@ describe('ComfyConfigManager', () => {
});
});

describe('createComfyConfigFile', () => {
it('should create new config file when none exists', () => {
(fs.existsSync as jest.Mock).mockReturnValue(false);

ComfyConfigManager.createComfyConfigFile('/fake/path');

expect(fs.writeFileSync).toHaveBeenCalledTimes(1);
expect(fs.renameSync).not.toHaveBeenCalled();
});
});

describe('createNestedDirectories', () => {
it('should create nested directory structure correctly', () => {
(fs.existsSync as jest.Mock).mockReturnValue(false);
Expand Down

0 comments on commit 42837e4

Please sign in to comment.