Skip to content

Commit

Permalink
feat: improve error message in simple-electron-ipc
Browse files Browse the repository at this point in the history
  • Loading branch information
oe committed Aug 15, 2024
1 parent 368728e commit 560ba04
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions packages/simple-electron-ipc/src/abstract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ export abstract class ElectronMessageHub extends AbstractHub {

protected readonly _ipc: IpcMain | IpcRenderer

constructor(options: IElectronBaseMessageHubOptions) {
constructor(options: IElectronBaseMessageHubOptions, className: string) {
super(options)
if (options.type !== process.type) {
throw new TypeError(
`can only be used in electron ${options.type === 'browser' ? 'main' : 'renderer'} process`,
`[${className}]can only be used in electron ${options.type === 'browser' ? 'main' : 'renderer'} process`,
)
}
this._ipc = options.type === 'browser' ? electron.ipcMain : electron.ipcRenderer
Expand Down
2 changes: 1 addition & 1 deletion packages/simple-electron-ipc/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ElectronMessageHub, IElectronMessageHubOptions } from './abstract'
let sharedMainMessageHub: MainMessageHub
export class MainMessageHub extends ElectronMessageHub {
constructor(options?: IElectronMessageHubOptions) {
super({ ...options, type: 'browser' })
super({ ...options, type: 'browser' }, 'MainMessageHub')
}

emit<ResponseType = unknown>(target: WebContents, method: string, ...args: any[]) {
Expand Down
2 changes: 1 addition & 1 deletion packages/simple-electron-ipc/src/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ElectronMessageHub, IElectronMessageHubOptions } from './abstract'
let rendererMessageHub: RendererMessageHub
export class RendererMessageHub extends ElectronMessageHub {
constructor(options?: IElectronMessageHubOptions) {
super({ ...options, type: 'renderer' })
super({ ...options, type: 'renderer' }, 'RendererMessageHub')
}

emit<ResponseType = unknown>(method: string, ...args: any[]) {
Expand Down

0 comments on commit 560ba04

Please sign in to comment.