当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript ipcRendererInternal.on方法代码示例

本文整理汇总了TypeScript中@electron/internal/renderer/ipc-renderer-internal.ipcRendererInternal.on方法的典型用法代码示例。如果您正苦于以下问题:TypeScript ipcRendererInternal.on方法的具体用法?TypeScript ipcRendererInternal.on怎么用?TypeScript ipcRendererInternal.on使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在@electron/internal/renderer/ipc-renderer-internal.ipcRendererInternal的用法示例。


在下文中一共展示了ipcRendererInternal.on方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: Promise

export const webFrameInit = () => {
  // Call webFrame method
  ipcRendererInternal.on('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.
    (webFrame[method] as any)(...args)
  })

  ipcRendererInternal.on('ELECTRON_INTERNAL_RENDERER_ASYNC_WEB_FRAME_METHOD', (
    event, requestId: number, method: keyof WebFrameMethod, args: any[]
  ) => {
    new Promise(resolve =>
      // 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.
      (webFrame[method] as any)(...args, resolve)
    ).then(result => {
      return [null, result]
    }, error => {
      return [errorUtils.serialize(error)]
    }).then(responseArgs => {
      event.sender.send(`ELECTRON_INTERNAL_BROWSER_ASYNC_WEB_FRAME_RESPONSE_${requestId}`, ...responseArgs)
    })
  })
}
开发者ID:vwvww,项目名称:electron,代码行数:28,代码来源:web-frame-init.ts

示例2: registerEvents

export function registerEvents (webView: WebViewImpl, viewInstanceId: number) {
  ipcRendererInternal.on(`ELECTRON_GUEST_VIEW_INTERNAL_DESTROY_GUEST-${viewInstanceId}`, function () {
    webView.guestInstanceId = undefined
    webView.reset()
    const domEvent = new Event('destroyed')
    webView.dispatchEvent(domEvent)
  })

  ipcRendererInternal.on(`ELECTRON_GUEST_VIEW_INTERNAL_DISPATCH_EVENT-${viewInstanceId}`, function (event, eventName, ...args) {
    dispatchEvent(webView, eventName, eventName, ...args)
  })

  ipcRendererInternal.on(`ELECTRON_GUEST_VIEW_INTERNAL_IPC_MESSAGE-${viewInstanceId}`, function (event, channel, ...args) {
    const domEvent = new Event('ipc-message') as IpcMessageEvent
    domEvent.channel = channel
    domEvent.args = args

    webView.dispatchEvent(domEvent)
  })
}
开发者ID:doridoridoriand,项目名称:electron,代码行数:20,代码来源:guest-view-internal.ts

示例3: Promise

export const handle = function <T extends IPCHandler> (channel: string, handler: T) {
  ipcRendererInternal.on(channel, (event, requestId, ...args) => {
    new Promise(resolve => resolve(handler(event, ...args))
    ).then(result => {
      return [null, result]
    }, error => {
      return [errorUtils.serialize(error)]
    }).then(responseArgs => {
      event.sender.send(`${channel}_RESPONSE_${requestId}`, ...responseArgs)
    })
  })
}
开发者ID:doridoridoriand,项目名称:electron,代码行数:12,代码来源:ipc-renderer-internal-utils.ts

示例4: if

      process.once('document-start', fire)
    } else if (script.runAt === 'document_end') {
      process.once('document-end', fire)
    } else {
      document.addEventListener('DOMContentLoaded', fire)
    }
  }
}

// Handle the request of chrome.tabs.executeJavaScript.
ipcRendererInternal.on('CHROME_TABS_EXECUTESCRIPT', function (
  event,
  senderWebContentsId: number,
  requestId: number,
  extensionId: string,
  url: string,
  code: string
) {
  const result = runContentScript.call(window, extensionId, url, code)
  ipcRendererInternal.sendToAll(senderWebContentsId, `CHROME_TABS_EXECUTESCRIPT_RESULT_${requestId}`, result)
})

// Read the renderer process preferences.
const preferences = process.getRenderProcessPreferences()
if (preferences) {
  for (const pref of preferences) {
    if (pref.contentScripts) {
      for (const script of pref.contentScripts) {
        injectContentScript(pref.extensionId, script)
      }
    }
开发者ID:vwvww,项目名称:electron,代码行数:31,代码来源:content-scripts-injector.ts


注:本文中的@electron/internal/renderer/ipc-renderer-internal.ipcRendererInternal.on方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。