本文整理匯總了TypeScript中@electron/internal/browser/ipc-main-internal.ipcMainInternal類的典型用法代碼示例。如果您正苦於以下問題:TypeScript ipcMainInternal類的具體用法?TypeScript ipcMainInternal怎麽用?TypeScript ipcMainInternal使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了ipcMainInternal類的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: callHandler
export const handleSync = function <T extends IPCHandler> (channel: string, handler: T) {
ipcMainInternal.on(channel, (event, ...args) => {
callHandler(handler, event, args, responseArgs => {
event.returnValue = responseArgs
})
})
}
示例2: handler
return new Promise<T>((resolve, reject) => {
const requestId = ++nextId
const channel = `${command}_RESPONSE_${requestId}`
ipcMainInternal.on(channel, function handler (
event, error: Electron.SerializedError, result: any
) {
if (event.sender !== sender) {
console.error(`Reply to ${command} sent by unexpected WebContents (${event.sender.id})`)
return
}
ipcMainInternal.removeListener(channel, handler)
if (error) {
reject(errorUtils.deserialize(error))
} else {
resolve(result)
}
})
if (sendToAll) {
sender._sendInternalToAll(command, requestId, ...args)
} else {
sender._sendInternal(command, requestId, ...args)
}
})