diff --git a/src/handlers/appInfoHandlers.ts b/src/handlers/appInfoHandlers.ts index 2b1f57ce..4af71bf6 100644 --- a/src/handlers/appInfoHandlers.ts +++ b/src/handlers/appInfoHandlers.ts @@ -1,11 +1,12 @@ import { app, ipcMain } from 'electron'; import { IPC_CHANNELS } from '../constants'; +import { useDesktopConfig } from '../store/desktopConfig'; +import type { TorchDeviceType } from '../preload'; + /** - * Handles static information about the app in IPC channels. + * Handles information about the app and current state in IPC channels. */ export class AppInfoHandlers { - constructor() {} - registerHandlers() { ipcMain.handle(IPC_CHANNELS.IS_PACKAGED, () => { return app.isPackaged; @@ -14,5 +15,10 @@ export class AppInfoHandlers { ipcMain.handle(IPC_CHANNELS.GET_ELECTRON_VERSION, () => { return app.getVersion(); }); + + // Config + ipcMain.handle(IPC_CHANNELS.GET_GPU, async (): Promise => { + return await useDesktopConfig().getAsync('detectedGpu'); + }); } } diff --git a/src/main-process/comfyDesktopApp.ts b/src/main-process/comfyDesktopApp.ts index 353d8fcc..e94034f7 100644 --- a/src/main-process/comfyDesktopApp.ts +++ b/src/main-process/comfyDesktopApp.ts @@ -142,10 +142,6 @@ export class ComfyDesktopApp { } } ); - // Config - ipcMain.handle(IPC_CHANNELS.GET_GPU, async (): Promise => { - return await useDesktopConfig().getAsync('detectedGpu'); - }); // Restart core ipcMain.handle(IPC_CHANNELS.RESTART_CORE, async (): Promise => { if (!this.comfyServer) return false; @@ -159,8 +155,11 @@ export class ComfyDesktopApp { * Install ComfyUI and return the base path. */ static async install(appWindow: AppWindow): Promise { + const config = useDesktopConfig(); + if (!config.get('installState')) config.set('installState', 'started'); + const validation = await validateHardware(); - if (typeof validation?.gpu === 'string') useDesktopConfig().set('detectedGpu', validation.gpu); + if (typeof validation?.gpu === 'string') config.set('detectedGpu', validation.gpu); if (!validation.isValid) { await appWindow.loadRenderer('not-supported'); diff --git a/tests/unit/handlers/appinfoHandlers.test.ts b/tests/unit/handlers/appinfoHandlers.test.ts index 508c4701..60b35532 100644 --- a/tests/unit/handlers/appinfoHandlers.test.ts +++ b/tests/unit/handlers/appinfoHandlers.test.ts @@ -4,6 +4,7 @@ import { IPC_CHANNELS } from '../../../src/constants'; jest.mock('electron', () => ({ ipcMain: { + on: jest.fn(), handle: jest.fn(), }, }));