diff --git a/src/config/comfyServerConfig.ts b/src/config/comfyServerConfig.ts index 344d8493..160fbb8f 100644 --- a/src/config/comfyServerConfig.ts +++ b/src/config/comfyServerConfig.ts @@ -219,6 +219,18 @@ export class ComfyServerConfig { /** @deprecated Do not use. Tempoary workaround for validation only. */ public static async setBasePathInDefaultConfig(basePath: string): Promise { const parsedConfig = await ComfyServerConfig.readConfigFile(ComfyServerConfig.configPath); + // TODO: Prompt user to attempt this as a troubleshooting option. + if (parsedConfig === null) { + // File does not exist. Just create default. + log.warn("Extra model paths config file doesn't exist. Creating default."); + + const comfyDesktopConfig = ComfyServerConfig.getBaseConfig(); + comfyDesktopConfig['base_path'] = basePath; + + return await ComfyServerConfig.createConfigFile(ComfyServerConfig.configPath, { + comfyui_desktop: comfyDesktopConfig, + }); + } if (!parsedConfig) return false; parsedConfig.comfyui_desktop ??= {}; diff --git a/src/main-process/comfyDesktopApp.ts b/src/main-process/comfyDesktopApp.ts index 37616a90..0a01db42 100644 --- a/src/main-process/comfyDesktopApp.ts +++ b/src/main-process/comfyDesktopApp.ts @@ -8,7 +8,6 @@ import { ComfySettings } from '../config/comfySettings'; import { AppWindow } from './appWindow'; import { ComfyServer } from './comfyServer'; import { ComfyServerConfig } from '../config/comfyServerConfig'; -import fs from 'node:fs'; import { type ElectronContextMenuOptions } from '../preload'; import path from 'node:path'; import { ansiCodes, getModelsDirectory } from '../utils'; @@ -18,6 +17,7 @@ import { Terminal } from '../shell/terminal'; import { DesktopConfig, useDesktopConfig } from '../store/desktopConfig'; import { restoreCustomNodes } from '../services/backup'; import { CmCli } from '../services/cmCli'; +import { rm } from 'node:fs/promises'; export class ComfyDesktopApp { public comfyServer: ComfyServer | null = null; @@ -116,10 +116,9 @@ export class ComfyDesktopApp { ipcMain.handle(IPC_CHANNELS.IS_FIRST_TIME_SETUP, () => { return !ComfyServerConfig.exists(); }); - // eslint-disable-next-line @typescript-eslint/require-await ipcMain.handle(IPC_CHANNELS.REINSTALL, async () => { log.info('Reinstalling...'); - this.reinstall(); + await this.reinstall(); }); type SentryErrorDetail = { error: string; @@ -238,12 +237,13 @@ export class ComfyDesktopApp { return new ComfyDesktopApp(basePath, new ComfySettings(basePath), appWindow); } - uninstall(): void { - fs.rmSync(ComfyServerConfig.configPath); + async uninstall(): Promise { + await rm(ComfyServerConfig.configPath); + await useDesktopConfig().permanentlyDeleteConfigFile(); } - reinstall(): void { - this.uninstall(); + async reinstall(): Promise { + await this.uninstall(); this.restart(); } diff --git a/src/store/desktopConfig.ts b/src/store/desktopConfig.ts index e26f33f6..41351b8e 100644 --- a/src/store/desktopConfig.ts +++ b/src/store/desktopConfig.ts @@ -39,6 +39,10 @@ export class DesktopConfig { this.#store.delete(key); } + async permanentlyDeleteConfigFile() { + await fs.rm(path.join(app.getPath('userData'), 'config.json')); + } + /** * Static factory method. Loads the config from disk. * @param shell Shell environment that can open file and folder views for the user