Skip to content

Commit

Permalink
Fix reinstall breaks config (#565)
Browse files Browse the repository at this point in the history
* Remove desktop config before reinstall

* Regenerate default extra_models_config from config.json
  • Loading branch information
webfiltered authored Dec 25, 2024
1 parent 8a0dfe1 commit a420b01
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
12 changes: 12 additions & 0 deletions src/config/comfyServerConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,18 @@ export class ComfyServerConfig {
/** @deprecated Do not use. Tempoary workaround for validation only. */
public static async setBasePathInDefaultConfig(basePath: string): Promise<boolean> {
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 ??= {};
Expand Down
14 changes: 7 additions & 7 deletions src/main-process/comfyDesktopApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -238,12 +237,13 @@ export class ComfyDesktopApp {
return new ComfyDesktopApp(basePath, new ComfySettings(basePath), appWindow);
}

uninstall(): void {
fs.rmSync(ComfyServerConfig.configPath);
async uninstall(): Promise<void> {
await rm(ComfyServerConfig.configPath);
await useDesktopConfig().permanentlyDeleteConfigFile();
}

reinstall(): void {
this.uninstall();
async reinstall(): Promise<void> {
await this.uninstall();
this.restart();
}

Expand Down
4 changes: 4 additions & 0 deletions src/store/desktopConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a420b01

Please sign in to comment.