當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript ipc-renderer-internal.ipcRendererInternal類代碼示例

本文整理匯總了TypeScript中@electron/internal/renderer/ipc-renderer-internal.ipcRendererInternal的典型用法代碼示例。如果您正苦於以下問題:TypeScript ipcRendererInternal類的具體用法?TypeScript ipcRendererInternal怎麽用?TypeScript ipcRendererInternal使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了ipcRendererInternal類的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: reject

 return new Promise<T>((resolve, reject) => {
   const requestId = ++nextId
   ipcRendererInternal.once(`${command}_RESPONSE_${requestId}`, (
     _event, error: Electron.SerializedError, result: any
   ) => {
     if (error) {
       reject(errorUtils.deserialize(error))
     } else {
       resolve(result)
     }
   })
   ipcRendererInternal.send(command, requestId, ...args)
 })
開發者ID:doridoridoriand,項目名稱:electron,代碼行數:13,代碼來源:ipc-renderer-internal-utils.ts

示例3:

export function invokeSync<T> (command: string, ...args: any[]): T {
  const [ error, result ] = ipcRendererInternal.sendSync(command, null, ...args)

  if (error) {
    throw errorUtils.deserialize(error)
  } else {
    return result
  }
}
開發者ID:doridoridoriand,項目名稱:electron,代碼行數:9,代碼來源:ipc-renderer-internal-utils.ts

示例4: 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

示例5: function

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)
})
開發者ID:vwvww,項目名稱:electron,代碼行數:11,代碼來源:content-scripts-injector.ts

示例6: 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

示例7: require

const { isParentDir } = require('@electron/internal/common/path-utils')

let absoluteAppPath: string
const getAppPath = function () {
  if (absoluteAppPath === undefined) {
    absoluteAppPath = fs.realpathSync(appPath!)
  }
  return absoluteAppPath
}

// Load the preload scripts.
for (const preloadScript of preloadScripts) {
  try {
    if (!isParentDir(getAppPath(), fs.realpathSync(preloadScript))) {
      throw new Error('Preload scripts outside of app path are not allowed')
    }
    require(preloadScript)
  } catch (error) {
    console.error(`Unable to load preload script: ${preloadScript}`)
    console.error(`${error}`)

    ipcRendererInternal.send('ELECTRON_BROWSER_PRELOAD_ERROR', preloadScript, errorUtils.serialize(error))
  }
}

// Warn about security issues
if (process.isMainFrame) {
  const { securityWarnings } = require('@electron/internal/renderer/security-warnings')
  securityWarnings(nodeIntegration)
}
開發者ID:electron,項目名稱:electron,代碼行數:30,代碼來源:init.ts

示例8: deregisterEvents

export function deregisterEvents (viewInstanceId: number) {
  ipcRendererInternal.removeAllListeners(`ELECTRON_GUEST_VIEW_INTERNAL_DESTROY_GUEST-${viewInstanceId}`)
  ipcRendererInternal.removeAllListeners(`ELECTRON_GUEST_VIEW_INTERNAL_DISPATCH_EVENT-${viewInstanceId}`)
  ipcRendererInternal.removeAllListeners(`ELECTRON_GUEST_VIEW_INTERNAL_IPC_MESSAGE-${viewInstanceId}`)
}
開發者ID:doridoridoriand,項目名稱:electron,代碼行數:5,代碼來源:guest-view-internal.ts

示例9:

 window.addEventListener('focus', () => {
   ipcRendererInternal.send('ELECTRON_GUEST_VIEW_MANAGER_FOCUS_CHANGE', true, guestInstanceId)
 })
開發者ID:doridoridoriand,項目名稱:electron,代碼行數:3,代碼來源:web-view-init.ts


注:本文中的@electron/internal/renderer/ipc-renderer-internal.ipcRendererInternal類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。