-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor IPC handler. * Refactor. * Test IPC hander. * Fix imports. * Fix tests. * Fix tests.
- Loading branch information
1 parent
88084c4
commit 94ce295
Showing
5 changed files
with
123 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { app, ipcMain, shell } from 'electron'; | ||
import { IPC_CHANNELS } from '../constants'; | ||
/** | ||
* Handles static information about the app in IPC channels. | ||
*/ | ||
export class AppInfoHandlers { | ||
constructor() {} | ||
|
||
registerHandlers() { | ||
ipcMain.handle(IPC_CHANNELS.IS_PACKAGED, () => { | ||
return app.isPackaged; | ||
}); | ||
|
||
ipcMain.handle(IPC_CHANNELS.GET_ELECTRON_VERSION, () => { | ||
return app.getVersion(); | ||
}); | ||
|
||
ipcMain.handle(IPC_CHANNELS.OPEN_FORUM, () => { | ||
shell.openExternal('https://forum.comfy.org'); | ||
}); | ||
ipcMain.handle(IPC_CHANNELS.DEFAULT_INSTALL_LOCATION, () => app.getPath('documents')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { app, ipcMain, shell } from 'electron'; | ||
import { IPC_CHANNELS } from '../constants'; | ||
import log from 'electron-log/main'; | ||
import { getModelConfigPath } from '../config/extra_model_config'; | ||
import { getBasePath } from '../install/resourcePaths'; | ||
|
||
export class PathHandlers { | ||
constructor() {} | ||
|
||
registerHandlers() { | ||
ipcMain.on(IPC_CHANNELS.OPEN_LOGS_PATH, (): void => { | ||
shell.openPath(app.getPath('logs')); | ||
}); | ||
|
||
ipcMain.handle(IPC_CHANNELS.GET_MODEL_CONFIG_PATH, (): string => { | ||
return getModelConfigPath(); | ||
}); | ||
|
||
ipcMain.handle(IPC_CHANNELS.GET_BASE_PATH, async (): Promise<string | null> => { | ||
return getBasePath(); | ||
}); | ||
|
||
ipcMain.on(IPC_CHANNELS.OPEN_PATH, (event, folderPath: string): void => { | ||
log.info(`Opening path: ${folderPath}`); | ||
shell.openPath(folderPath); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { ipcMain } from 'electron'; | ||
import { AppInfoHandlers } from '../../../src/handlers/appInfoHandlers'; | ||
import { IPC_CHANNELS } from '../../../src/constants'; | ||
|
||
jest.mock('electron', () => ({ | ||
ipcMain: { | ||
handle: jest.fn(), | ||
}, | ||
})); | ||
|
||
describe('AppInfoHandlers', () => { | ||
let handler: AppInfoHandlers; | ||
beforeEach(() => { | ||
handler = new AppInfoHandlers(); | ||
handler.registerHandlers(); | ||
}); | ||
|
||
it('should register all expected handle channels', () => { | ||
const expectedChannels = [ | ||
IPC_CHANNELS.IS_PACKAGED, | ||
IPC_CHANNELS.GET_ELECTRON_VERSION, | ||
IPC_CHANNELS.OPEN_FORUM, | ||
IPC_CHANNELS.DEFAULT_INSTALL_LOCATION, | ||
]; | ||
|
||
expectedChannels.forEach((channel) => { | ||
expect(ipcMain.handle).toHaveBeenCalledWith(channel, expect.any(Function)); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { ipcMain } from 'electron'; | ||
|
||
import { PathHandlers } from '../../../src/handlers/pathHandlers'; | ||
import { IPC_CHANNELS } from '../../../src/constants'; | ||
|
||
jest.mock('electron', () => ({ | ||
ipcMain: { | ||
on: jest.fn(), | ||
handle: jest.fn(), | ||
}, | ||
})); | ||
|
||
describe('PathHandlers', () => { | ||
let handler: PathHandlers; | ||
beforeEach(() => { | ||
handler = new PathHandlers(); | ||
handler.registerHandlers(); | ||
}); | ||
|
||
it('should register all expected handle channels', () => { | ||
const expectedChannelsForHandle = [IPC_CHANNELS.GET_MODEL_CONFIG_PATH, IPC_CHANNELS.GET_BASE_PATH]; | ||
|
||
expectedChannelsForHandle.forEach((channel) => { | ||
expect(ipcMain.handle).toHaveBeenCalledWith(channel, expect.any(Function)); | ||
}); | ||
}); | ||
|
||
it('should register all expected on channels', () => { | ||
const expectedChannelsForOn = [IPC_CHANNELS.OPEN_LOGS_PATH, IPC_CHANNELS.OPEN_PATH]; | ||
|
||
expectedChannelsForOn.forEach((channel) => { | ||
expect(ipcMain.on).toHaveBeenCalledWith(channel, expect.any(Function)); | ||
}); | ||
}); | ||
}); |