-
Notifications
You must be signed in to change notification settings - Fork 15k
/
web-frame-init.ts
25 lines (22 loc) · 952 Bytes
/
web-frame-init.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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[]
) => {
// TODO(MarshallOfSound): Remove once the world-safe-execute-javascript deprecation warning is removed
if (method.startsWith('executeJavaScript')) {
return (webFrame as any)[`_${method}`](...args);
}
// 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.
return (webFrame[method] as any)(...args);
});
};