Skip to content

Commit

Permalink
Use app settings store for install state
Browse files Browse the repository at this point in the history
  • Loading branch information
webfiltered committed Dec 2, 2024
1 parent 7f198a9 commit 45c3748
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
16 changes: 11 additions & 5 deletions src/main-process/comfyDesktopApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ import { DownloadManager } from '../models/DownloadManager';
import { VirtualEnvironment } from '../virtualEnvironment';
import { InstallWizard } from '../install/installWizard';
import { Terminal } from '../terminal';
import { useDesktopStore } from '../store/store';
import { restoreCustomNodes } from '../services/backup';
import Store from 'electron-store';

export class ComfyDesktopApp {
public comfyServer: ComfyServer | null = null;
private terminal: Terminal | null = null; // Only created after server starts.
Expand Down Expand Up @@ -144,7 +145,11 @@ export class ComfyDesktopApp {
return new Promise<string>((resolve) => {
ipcMain.on(IPC_CHANNELS.INSTALL_COMFYUI, async (event, installOptions: InstallOptions) => {
const installWizard = new InstallWizard(installOptions);
const { store } = useDesktopStore();
store.set('basePath', installWizard.basePath);

await installWizard.install();
store.set('installState', 'installed');
resolve(installWizard.basePath);
});
});
Expand Down Expand Up @@ -181,7 +186,7 @@ export class ComfyDesktopApp {
this.appWindow.send(IPC_CHANNELS.LOG_MESSAGE, data);
},
});
const store = new Store();
const { store } = useDesktopStore();
if (!store.get('Comfy-Desktop.RestoredCustomNodes', false)) {
try {
await restoreCustomNodes(virtualEnvironment, this.appWindow);
Expand All @@ -199,9 +204,10 @@ export class ComfyDesktopApp {
}

static async create(appWindow: AppWindow): Promise<ComfyDesktopApp> {
const basePath = ComfyServerConfig.exists()
? await ComfyServerConfig.readBasePathFromConfig(ComfyServerConfig.configPath)
: await this.install(appWindow);
const { store } = useDesktopStore();

const installed = store.get('installState') === 'installed';
const basePath = installed ? store.get('basePath') : await this.install(appWindow);

if (!basePath) {
throw new Error(`Base path not found! ${ComfyServerConfig.configPath} is probably corrupted.`);
Expand Down
5 changes: 3 additions & 2 deletions src/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ export type AppWindowSettings = {
};

export type DesktopSettings = {
installState: 'started' | 'installed' | undefined;
}
basePath?: string;
installState?: 'started' | 'installed';
};

0 comments on commit 45c3748

Please sign in to comment.