Skip to content

Commit

Permalink
feat: add IpcMainSenderAPI for defining main-to-renderer ipc API (#97)
Browse files Browse the repository at this point in the history
* refactor: change ipc channel name format

* feat: add `IpcMainSenderAPI` for fast defining apis
  • Loading branch information
yifanwww authored Oct 1, 2023
1 parent 59412dd commit fd4c5b5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
4 changes: 2 additions & 2 deletions packages/app-common/src/apis/app/apis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import type { IpcRendererInvokerAPI } from '../types';
import type { AppDetails, WindowType } from './types';

export enum AppAPIChannel {
CREATE_WINDOW = 'App_CreateWindow',
GET_APP_DETAILS = 'App_GetAppDetails',
CREATE_WINDOW = 'App:CreateWindow',
GET_APP_DETAILS = 'App:GetAppDetails',
}

type CreateWindowAPI = IpcRendererInvokerAPI<(type: WindowType) => void>;
Expand Down
12 changes: 6 additions & 6 deletions packages/app-common/src/apis/logger/apis.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type { IpcRendererInvokerAPI } from '../types';

export enum LoggerAPIChannel {
LOG = 'Logger_Log',
ERROR = 'Logger_Error',
WARN = 'Logger_Warn',
INFO = 'Logger_Info',
VERBOSE = 'Logger_Verbose',
DEBUG = 'Logger_Debug',
LOG = 'Logger:Log',
ERROR = 'Logger:Error',
WARN = 'Logger:Warn',
INFO = 'Logger:Info',
VERBOSE = 'Logger:Verbose',
DEBUG = 'Logger:Debug',
}

type LogLevel = 'error' | 'warn' | 'info' | 'verbose' | 'debug';
Expand Down
5 changes: 5 additions & 0 deletions packages/app-common/src/apis/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,8 @@ export interface IpcRendererInvokerAPI<PrototypeFn extends UnknownFn> {
main: IpcMainHandler<PrototypeFn>;
renderer: IpcRendererInvoker<PrototypeFn>;
}

export interface IpcMainSenderAPI<PrototypeFn extends UnknownFn> {
main: (...args: Parameters<PrototypeFn>) => void;
renderer: (listener: IpcRendererListener<PrototypeFn>) => void;
}

0 comments on commit fd4c5b5

Please sign in to comment.