chore: refactor browser IPC into TS and app API into TS (#16921)
* chore: refactor browser IPC into typescript * chore: refactor app.ts into Typescript * Refactors app.dock into cpp * Removes app.launcher which has not existed for 3 years * Removes 2 deprecated APIs (that have been deprecated for more than one major) * Refactors deprecate.ts as well
This commit is contained in:
parent
4ccd6d5900
commit
5790869a3f
16 changed files with 258 additions and 201 deletions
29
lib/browser/ipc-main-internal-utils.ts
Normal file
29
lib/browser/ipc-main-internal-utils.ts
Normal file
|
@ -0,0 +1,29 @@
|
|||
import { ipcMainInternal } from '@electron/internal/browser/ipc-main-internal'
|
||||
import * as errorUtils from '@electron/internal/common/error-utils'
|
||||
|
||||
type IPCHandler = (...args: any[]) => any
|
||||
|
||||
const callHandler = async function (handler: IPCHandler, event: Electron.Event, args: any[], reply: (args: any[]) => void) {
|
||||
try {
|
||||
const result = await handler(event, ...args)
|
||||
reply([null, result])
|
||||
} catch (error) {
|
||||
reply([errorUtils.serialize(error)])
|
||||
}
|
||||
}
|
||||
|
||||
export const handle = function <T extends IPCHandler> (channel: string, handler: T) {
|
||||
ipcMainInternal.on(channel, (event, requestId, ...args) => {
|
||||
callHandler(handler, event, args, responseArgs => {
|
||||
event._replyInternal(`${channel}_RESPONSE_${requestId}`, ...responseArgs)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
export const handleSync = function <T extends IPCHandler> (channel: string, handler: T) {
|
||||
ipcMainInternal.on(channel, (event, ...args) => {
|
||||
callHandler(handler, event, args, responseArgs => {
|
||||
event.returnValue = responseArgs
|
||||
})
|
||||
})
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue