mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
menu.ts: refactoring and fixes, reuse route paths from views (renderer)
Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
1 parent
117ad584d3
commit
a4bcfc1e52
7 files changed
+118
-139
No files matched your search
+15
-7
@@ -69,16 +69,24 @@ export function handleIpc(channel: IpcChannel, handler: IpcMessageHandler, optio
|
||||
export interface IpcPairOptions {
|
||||
channel: IpcChannel
|
||||
handle?: IpcMessageHandler
|
||||
options?: IpcHandleOpts
|
||||
autoBind?: boolean;
|
||||
timeout?: number;
|
||||
}
|
||||
|
||||
export function createIpcChannel({ channel, ...initOpts }: IpcPairOptions) {
|
||||
// todo: improve api
|
||||
export function createIpcChannel({ channel, autoBind, ...initOpts }: IpcPairOptions) {
|
||||
const bindHandler = (opts: { handler?: IpcMessageHandler, options?: IpcHandleOpts } = {}) => {
|
||||
const handler = opts.handler || initOpts.handle || Function;
|
||||
const options = opts.options || { timeout: initOpts.timeout };
|
||||
handleIpc(channel, handler, options);
|
||||
};
|
||||
if (autoBind) {
|
||||
bindHandler();
|
||||
}
|
||||
return {
|
||||
handleInMain: (opts: Partial<Omit<IpcPairOptions, "channel">> = {}) => {
|
||||
const { handle = initOpts.handle, options = initOpts.options } = opts;
|
||||
return handleIpc(channel, handle, options);
|
||||
},
|
||||
invokeFromRenderer: (...args: any[]) => {
|
||||
channel: channel,
|
||||
handleInMain: bindHandler,
|
||||
invokeFromRenderer(...args: any[]) {
|
||||
return invokeIpc(channel, ...args);
|
||||
},
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user