diff --git a/src/handlers/appInfoHandlers.ts b/src/handlers/appInfoHandlers.ts index 084abfd9..2b1f57ce 100644 --- a/src/handlers/appInfoHandlers.ts +++ b/src/handlers/appInfoHandlers.ts @@ -1,6 +1,8 @@ import { app, ipcMain } from 'electron'; import { IPC_CHANNELS } from '../constants'; - +/** + * Handles static information about the app in IPC channels. + */ export class AppInfoHandlers { constructor() {} diff --git a/src/handlers/ipcHandler.ts b/src/handlers/ipcHandler.ts deleted file mode 100644 index 00d5d4b5..00000000 --- a/src/handlers/ipcHandler.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { PathHandlers } from './pathHandlers'; - -export class IPCHandler { - constructor() {} - - registerHandlers() { - new PathHandlers().registerHandlers(); - } -} diff --git a/src/handlers/pathHandlers.ts b/src/handlers/pathHandlers.ts index 41fa6163..69a87113 100644 --- a/src/handlers/pathHandlers.ts +++ b/src/handlers/pathHandlers.ts @@ -2,17 +2,20 @@ import { app, ipcMain, shell } from 'electron'; import { IPC_CHANNELS } from '../constants'; import { determineResourcesPaths } from '../main'; import log from 'electron-log/main'; +import { getModelConfigPath } from '../config/extra_model_config'; export class PathHandlers { constructor() {} registerHandlers() { - // Path-related handlers - ipcMain.on(IPC_CHANNELS.OPEN_LOGS_PATH, () => { shell.openPath(app.getPath('logs')); }); + ipcMain.handle(IPC_CHANNELS.GET_MODEL_CONFIG_PATH, () => { + return getModelConfigPath(); + }); + ipcMain.handle(IPC_CHANNELS.GET_BASE_PATH, async () => { const { basePath } = await determineResourcesPaths(); return basePath; diff --git a/src/main.ts b/src/main.ts index 364d6afb..a18c9776 100644 --- a/src/main.ts +++ b/src/main.ts @@ -21,6 +21,7 @@ import { ComfyConfigManager } from './config/comfyConfigManager'; import { AppWindow } from './main-process/appWindow'; import { getAppResourcesPath, getBasePath, getPythonInstallPath } from './install/resourcePaths'; import { PathHandlers } from './handlers/pathHandlers'; +import { AppInfoHandlers } from './handlers/appInfoHandlers'; dotenv.config(); @@ -146,6 +147,8 @@ if (!gotTheLock) { try { createWindow(); + new PathHandlers().registerHandlers(); + new AppInfoHandlers().registerHandlers(); ipcMain.handle(IPC_CHANNELS.OPEN_FORUM, () => { shell.openExternal('https://forum.comfy.org'); @@ -157,9 +160,6 @@ if (!gotTheLock) { ...options, }); }); - ipcMain.handle(IPC_CHANNELS.GET_MODEL_CONFIG_PATH, () => { - return getModelConfigPath(); - }); ipcMain.on(IPC_CHANNELS.OPEN_DEV_TOOLS, () => { appWindow.openDevTools(); diff --git a/tests/unit/handlers/pathHandler.test.ts b/tests/unit/handlers/pathHandler.test.ts new file mode 100644 index 00000000..16756281 --- /dev/null +++ b/tests/unit/handlers/pathHandler.test.ts @@ -0,0 +1,40 @@ +import { ipcMain } from 'electron'; + +import { PathHandlers } from '../../../src/handlers/pathHandlers'; +import { IPC_CHANNELS } from '../../../src/constants'; + +const isChannelRegistered = (channel: string): boolean => { + // @ts-ignore - accessing private property for testing + return ipcMain.listeners(channel).length > 0; +}; + +describe('IPC Handlers', () => { + beforeEach(() => { + // Clear all existing listeners before each test + ipcMain.removeAllListeners(); + }); + describe('PathHandlers', () => { + let handler: PathHandlers; + beforeEach(() => { + // Clear all existing listeners before each test + ipcMain.removeAllListeners(); + handler = new PathHandlers(); + handler.registerHandlers(); + }); + + it('should register all expected channels', () => { + handler.registerHandlers(); + + const expectedChannels = [ + IPC_CHANNELS.GET_MODEL_CONFIG_PATH, + IPC_CHANNELS.GET_BASE_PATH, + IPC_CHANNELS.OPEN_LOGS_PATH, + IPC_CHANNELS.OPEN_PATH, + ]; + + expectedChannels.forEach((channel) => { + expect(isChannelRegistered(channel)).toBe(true); + }); + }); + }); +});