web-frame-init.ts 797 B

123456789101112131415161718192021
  1. import { webFrame, WebFrame } from 'electron';
  2. import * as ipcRendererUtils from '@electron/internal/renderer/ipc-renderer-internal-utils';
  3. import { IPC_MESSAGES } from '@electron/internal/common/ipc-messages';
  4. // All keys of WebFrame that extend Function
  5. type WebFrameMethod = {
  6. [K in keyof WebFrame]:
  7. WebFrame[K] extends Function ? K : never
  8. }
  9. export const webFrameInit = () => {
  10. // Call webFrame method
  11. ipcRendererUtils.handle(IPC_MESSAGES.RENDERER_WEB_FRAME_METHOD, (
  12. event, method: keyof WebFrameMethod, ...args: any[]
  13. ) => {
  14. // The TypeScript compiler cannot handle the sheer number of
  15. // call signatures here and simply gives up. Incorrect invocations
  16. // will be caught by "keyof WebFrameMethod" though.
  17. return (webFrame[method] as any)(...args);
  18. });
  19. };