Skip to content

Commit

Permalink
make ipc API more consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-marechal committed Apr 6, 2023
1 parent 2deb455 commit 0b38ebb
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class ElectronFrontendApplicationImpl implements ElectronFrontendApplicat
protected ipcRenderer: TheiaIpcRenderer;

@proxy() handleCanClose(handler: (reason: StopReason) => Promise<boolean>): void {
this.ipcRenderer.handle(ipc.canClose, handler);
this.ipcRenderer.handle(ipc.canClose, (event, reason) => handler(reason));
}

@proxy() updateApplicationState(state: FrontendApplicationState): void {
Expand Down
6 changes: 4 additions & 2 deletions packages/core/src/electron-common/electron-ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ const namespaces = new Set<string>();
export type TheiaIpcMainInvokeEvent = IpcMainInvokeEvent;
export type TheiaIpcMainEvent = IpcMainEvent;
export type TheiaIpcRendererEvent = IpcRendererEvent;
/** Reserved for future uses. */
export interface TheiaIpcRendererInvokeEvent { }

/**
* Attach callbacks to this event to receive notifications.
Expand Down Expand Up @@ -108,14 +110,14 @@ export interface TheiaIpcRenderer {
* This functionality is not natively supported by Electron, so this
* relies on a custom message protocol.
*/
handle<T extends AnyFunction>(channel: IpcChannel<T>, listener: T, thisArg?: object): void
handle<T extends AnyFunction>(channel: IpcChannel<T>, listener: IpcListener<TheiaIpcRendererInvokeEvent, T>, thisArg?: object): void
/**
* Handle requests coming from the main context only once.
*
* This functionality is not natively supported by Electron, so this
* relies on a custom message protocol.
*/
handleOnce<T extends AnyFunction>(channel: IpcChannel<T>, listener: T, thisArg?: object): void
handleOnce<T extends AnyFunction>(channel: IpcChannel<T>, listener: IpcListener<TheiaIpcRendererInvokeEvent, T>, thisArg?: object): void
on<T extends AnyFunction>(channel: IpcChannel<T>, listener: IpcListener<TheiaIpcRendererEvent, T>, thisArg?: object): this
once<T extends AnyFunction>(channel: IpcChannel<T>, listener: IpcListener<TheiaIpcRendererEvent, T>, thisArg?: object): this
postMessage<M>(channel: IpcChannel<(message: M) => void>, message: M, transfer?: readonly MessagePort[]): void
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/electron-common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export { ElectronClipboardService, ELECTRON_CLIPBOARD_IPC } from './electron-cli
export { ElectronCurrentWindow, ELECTRON_CURRENT_WINDOW_IPC } from './electron-current-window';
export { ElectronFrontendApplication, ELECTRON_FRONTEND_APPLICATION_IPC } from './electron-frontend-application';
export { ELECTRON_INVOKE_IPC } from './electron-invoke';
export { createIpcChannel, createIpcNamespace, IpcChannel, IpcEvent, IpcHandleConverter, IpcListener, proxy, proxyable, ProxyableOptions, ProxyOptions, TheiaIpcMain, TheiaIpcMainEvent, TheiaIpcMainInvokeEvent, TheiaIpcRenderer, TheiaIpcRendererEvent, TheiaIpcWindow } from './electron-ipc';
export { createIpcChannel, createIpcNamespace, IpcChannel, IpcEvent, IpcHandleConverter, IpcListener, proxy, proxyable, ProxyableOptions, ProxyOptions, TheiaIpcMain, TheiaIpcMainEvent, TheiaIpcMainInvokeEvent, TheiaIpcRenderer, TheiaIpcRendererEvent, TheiaIpcRendererInvokeEvent, TheiaIpcWindow } from './electron-ipc';
export { ElectronKeyboardLayout, ELECTRON_KEYBOARD_LAYOUT_IPC, NativeKeyboardLayout } from './electron-keyboard-layout';
export { MenuDto, MenuRole } from './electron-menu';
export { ConnectionRequest, ConnectionResponse, ELECTRON_MESSAGE_PORT_IPC, MessagePortClient, MessagePortHandler, MessagePortHandlerId, MessagePortServer } from './electron-message-port';
Expand Down

0 comments on commit 0b38ebb

Please sign in to comment.