refactor: Port renderer-internal to TypeScript (#16939)

* chore: make aliasify work on .ts files as well

* refactor: Port ipc-renderer-internal to TypeScript

* refactor: Correctly import internal ipcRenderer

* refactor: One more rename

* refactor: Fix one more lint issue

* refactor: Correctly reference ipcRendererInternal
This commit is contained in:
Felix Rieseberg 2019-02-14 17:24:25 -08:00 committed by Samuel Attard
parent 5790869a3f
commit 2498e8d1c2
19 changed files with 109 additions and 108 deletions

View file

@ -1,4 +1,4 @@
import * as ipcRenderer from '@electron/internal/renderer/ipc-renderer-internal'
import { ipcRendererInternal } from '@electron/internal/renderer/ipc-renderer-internal'
import * as errorUtils from '@electron/internal/common/error-utils'
let nextId = 0
@ -6,7 +6,7 @@ let nextId = 0
export function invoke<T> (command: string, ...args: any[]) {
return new Promise<T>((resolve, reject) => {
const requestId = ++nextId
ipcRenderer.once(`${command}_RESPONSE_${requestId}`, (
ipcRendererInternal.once(`${command}_RESPONSE_${requestId}`, (
_event: Electron.Event, error: Electron.SerializedError, result: any
) => {
if (error) {
@ -15,12 +15,12 @@ export function invoke<T> (command: string, ...args: any[]) {
resolve(result)
}
})
ipcRenderer.send(command, requestId, ...args)
ipcRendererInternal.send(command, requestId, ...args)
})
}
export function invokeSync<T> (command: string, ...args: any[]): T {
const [ error, result ] = ipcRenderer.sendSync(command, ...args)
const [ error, result ] = ipcRendererInternal.sendSync(command, ...args)
if (error) {
throw errorUtils.deserialize(error)