web-frame-init.ts 728 B

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