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 GPU preselection #501

Merged
merged 4 commits into from
Dec 17, 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: 9 additions & 3 deletions src/handlers/appInfoHandlers.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<TorchDeviceType | undefined> => {
return await useDesktopConfig().getAsync('detectedGpu');
});
}
}
9 changes: 4 additions & 5 deletions src/main-process/comfyDesktopApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,6 @@ export class ComfyDesktopApp {
}
}
);
// Config
ipcMain.handle(IPC_CHANNELS.GET_GPU, async (): Promise<TorchDeviceType | undefined> => {
return await useDesktopConfig().getAsync('detectedGpu');
});
// Restart core
ipcMain.handle(IPC_CHANNELS.RESTART_CORE, async (): Promise<boolean> => {
if (!this.comfyServer) return false;
Expand All @@ -159,8 +155,11 @@ export class ComfyDesktopApp {
* Install ComfyUI and return the base path.
*/
static async install(appWindow: AppWindow): Promise<string> {
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');
Expand Down
1 change: 1 addition & 0 deletions tests/unit/handlers/appinfoHandlers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { IPC_CHANNELS } from '../../../src/constants';

jest.mock('electron', () => ({
ipcMain: {
on: jest.fn(),
handle: jest.fn(),
},
}));
Expand Down
Loading