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

Fix reinstall breaks config #565

Merged
merged 2 commits into from
Dec 25, 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
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
Loading