2019-02-18 00:24:18 +00:00
|
|
|
import { webFrame, WebFrame } from 'electron';
|
2019-03-13 19:03:17 +00:00
|
|
|
import * as ipcRendererUtils from '@electron/internal/renderer/ipc-renderer-internal-utils';
|
2020-10-13 21:11:06 +00:00
|
|
|
import { IPC_MESSAGES } from '@electron/internal/common/ipc-messages';
|
2019-02-18 00:24:18 +00:00
|
|
|
|
|
|
|
// All keys of WebFrame that extend Function
|
|
|
|
type WebFrameMethod = {
|
|
|
|
[K in keyof WebFrame]:
|
|
|
|
WebFrame[K] extends Function ? K : never
|
|
|
|
}
|
|
|
|
|
|
|
|
export const webFrameInit = () => {
|
|
|
|
// Call webFrame method
|
2020-10-13 21:11:06 +00:00
|
|
|
ipcRendererUtils.handle(IPC_MESSAGES.RENDERER_WEB_FRAME_METHOD, (
|
2019-03-13 19:03:17 +00:00
|
|
|
event, method: keyof WebFrameMethod, ...args: any[]
|
2019-02-18 00:24:18 +00:00
|
|
|
) => {
|
|
|
|
// The TypeScript compiler cannot handle the sheer number of
|
|
|
|
// call signatures here and simply gives up. Incorrect invocations
|
|
|
|
// will be caught by "keyof WebFrameMethod" though.
|
2019-03-13 19:03:17 +00:00
|
|
|
return (webFrame[method] as any)(...args);
|
2019-02-18 00:24:18 +00:00
|
|
|
});
|
|
|
|
};
|