From 8149716a4039237a5fb4af52b03ef326f2c075c5 Mon Sep 17 00:00:00 2001 From: filtered <176114999+webfiltered@users.noreply.github.com> Date: Sat, 25 Jan 2025 09:46:00 +1100 Subject: [PATCH 1/4] Use base path from desktop config --- src/main-process/comfyInstallation.ts | 31 +-------------------------- 1 file changed, 1 insertion(+), 30 deletions(-) diff --git a/src/main-process/comfyInstallation.ts b/src/main-process/comfyInstallation.ts index 45657ce8..586c1902 100644 --- a/src/main-process/comfyInstallation.ts +++ b/src/main-process/comfyInstallation.ts @@ -111,7 +111,7 @@ export class ComfyInstallation { } // Validate base path - const basePath = await this.loadBasePath(); + const basePath = useDesktopConfig().get('basePath'); if (basePath && (await pathAccessible(basePath))) { validation.basePath = 'OK'; this.onUpdate?.(validation); @@ -175,35 +175,6 @@ export class ComfyInstallation { return validation.installState; } - /** - * Loads the base path from YAML config. If it is unreadable, warns the user and quits. - * @returns The base path if read successfully, or `undefined` - * @throws If the config file is present but not readable - */ - async loadBasePath(): Promise { - const readResult = await ComfyServerConfig.readBasePathFromConfig(ComfyServerConfig.configPath); - switch (readResult.status) { - case 'success': - // TODO: Check if config.json basePath different, then determine why it has changed (intentional?) - this.basePath = readResult.path; - return readResult.path; - case 'invalid': - // TODO: File was there, and was valid YAML. It just didn't have a valid base_path. - // Show path edit screen instead of reinstall. - return; - case 'notFound': - return; - default: - // 'error': Explain and quit - // TODO: Support link? Something? - throw new Error(`Unable to read the YAML configuration file. Please ensure this file is available and can be read: - -${ComfyServerConfig.configPath} - -If this problem persists, back up and delete the config file, then restart the app.`); - } - } - /** * Migrates the config file to the latest format, after an upgrade of the desktop app executables. * From ddedf143ca85f12712c0581066537b78ed59e680 Mon Sep 17 00:00:00 2001 From: filtered <176114999+webfiltered@users.noreply.github.com> Date: Sat, 25 Jan 2025 10:16:09 +1100 Subject: [PATCH 2/4] Remove unused code Removes former basePath workaround. --- src/main-process/comfyInstallation.ts | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/src/main-process/comfyInstallation.ts b/src/main-process/comfyInstallation.ts index 586c1902..32d16927 100644 --- a/src/main-process/comfyInstallation.ts +++ b/src/main-process/comfyInstallation.ts @@ -33,17 +33,6 @@ export class ComfyInstallation { virtualEnvironment: VirtualEnvironment; comfySettings: ComfySettings; - _basePath: string; - /** The base path of the desktop app. Models, nodes, and configuration are saved here by default. */ - get basePath() { - return this._basePath; - } - set basePath(value: string) { - // Duplicated in constructor to avoid non-nullable type assertions. - this._basePath = value; - this.virtualEnvironment = this.createVirtualEnvironment(value); - } - /** * Called during/after each step of validation * @param data The data to send to the renderer @@ -54,13 +43,11 @@ export class ComfyInstallation { /** Installation state, e.g. `started`, `installed`. See {@link DesktopSettings}. */ public state: DesktopInstallState, /** The base path of the desktop app. Models, nodes, and configuration are saved here by default. */ - basePath: string, + public basePath: string, /** The device type to use for the installation. */ public readonly telemetry: ITelemetry, public device?: TorchDeviceType ) { - // TypeScript workaround: duplication of basePath setter - this._basePath = basePath; this.comfySettings = new ComfySettings(basePath); this.virtualEnvironment = this.createVirtualEnvironment(basePath); } From 69e9bfcb747dc0fc703a92132f6222fd947b9915 Mon Sep 17 00:00:00 2001 From: filtered <176114999+webfiltered@users.noreply.github.com> Date: Wed, 29 Jan 2025 03:09:47 +1100 Subject: [PATCH 3/4] Update unit tests to reflect changes --- tests/unit/install/installationManager.test.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/tests/unit/install/installationManager.test.ts b/tests/unit/install/installationManager.test.ts index cb7d3e8a..4050908f 100644 --- a/tests/unit/install/installationManager.test.ts +++ b/tests/unit/install/installationManager.test.ts @@ -7,6 +7,7 @@ import type { AppWindow } from '@/main-process/appWindow'; import { ComfyInstallation } from '@/main-process/comfyInstallation'; import type { InstallValidation } from '@/preload'; import type { ITelemetry } from '@/services/telemetry'; +import { useDesktopConfig } from '@/store/desktopConfig'; import * as utils from '@/utils'; vi.mock('electron', () => ({ @@ -20,7 +21,14 @@ vi.mock('node:fs/promises', () => ({ rm: vi.fn(), })); -vi.mock('@/store/desktopConfig'); +vi.mock('@/store/desktopConfig', () => ({ + useDesktopConfig: vi.fn().mockReturnValue({ + get: vi.fn().mockImplementation((key: string) => { + if (key === 'installState') return 'installed'; + if (key === 'basePath') return 'valid/base'; + }), + }), +})); vi.mock('electron-log/main'); vi.mock('@/utils', async () => { @@ -123,9 +131,9 @@ describe('InstallationManager', () => { { scenario: 'detects invalid base path', mockSetup: () => { - vi.mocked(ComfyServerConfig.readBasePathFromConfig).mockResolvedValue({ - status: 'success', - path: 'invalid/base', + vi.mocked(useDesktopConfig().get).mockImplementation((key: string) => { + if (key === 'installState') return 'installed'; + if (key === 'basePath') return 'invalid/base'; }); }, expectedErrors: ['basePath'], From a72c1f569a56d89b036994e710c067aed4e2463e Mon Sep 17 00:00:00 2001 From: Chenlei Hu Date: Tue, 28 Jan 2025 10:04:00 -0800 Subject: [PATCH 4/4] Add readonly --- src/main-process/comfyInstallation.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main-process/comfyInstallation.ts b/src/main-process/comfyInstallation.ts index 32d16927..03294450 100644 --- a/src/main-process/comfyInstallation.ts +++ b/src/main-process/comfyInstallation.ts @@ -30,7 +30,7 @@ export class ComfyInstallation { return this.state === 'installed' && !this.hasIssues; } - virtualEnvironment: VirtualEnvironment; + readonly virtualEnvironment: VirtualEnvironment; comfySettings: ComfySettings; /** @@ -43,7 +43,7 @@ export class ComfyInstallation { /** Installation state, e.g. `started`, `installed`. See {@link DesktopSettings}. */ public state: DesktopInstallState, /** The base path of the desktop app. Models, nodes, and configuration are saved here by default. */ - public basePath: string, + public readonly basePath: string, /** The device type to use for the installation. */ public readonly telemetry: ITelemetry, public device?: TorchDeviceType