electron/lib/renderer/web-frame-init.ts

21 lines
733 B
TypeScript
Raw Normal View History

2020-03-20 20:28:31 +00:00
import { webFrame, WebFrame } from 'electron';
import * as ipcRendererUtils from '@electron/internal/renderer/ipc-renderer-internal-utils';
// 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
ipcRendererUtils.handle('ELECTRON_INTERNAL_RENDERER_WEB_FRAME_METHOD', (
event, method: keyof WebFrameMethod, ...args: any[]
) => {
// 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.
2020-03-20 20:28:31 +00:00
return (webFrame[method] as any)(...args);
});
};