preload: fix handle preload data arguments

This commit is contained in:
leejooy96 committed 2023-02-08 16:20:39 +09:00
1 parent 32a8c7067a
commit 00ae01dc3f
2 files changed
+15 -4

No files matched your search

+14 -3
View File
@@ -5,14 +5,25 @@ const mainAvailChannels = ['msgRequestGetVersion', 'msgOpenExternalLink']
const rendererAvailChannels = ['msgReceivedVersion']
contextBridge.exposeInMainWorld('mainApi', {
send: (channel, data) => {
send: (channel, ...data) => {
if (mainAvailChannels.includes(channel)) {
ipcRenderer.send(channel, data)
ipcRenderer.send.apply(null, [channel, ...data])
} else {
throw new Error(`Send failed: Unknown ipc channel name: ${channel}`)
}
},
receive: (channel, cbFunc) => {
if (rendererAvailChannels.includes(channel)) {
ipcRenderer.on(channel, (event, ...args) => cbFunc(...args))
ipcRenderer.on(channel, (event, ...args) => cbFunc(event, ...args))
} else {
throw new Error(`Receive failed: Unknown ipc channel name: ${channel}`)
}
},
invoke: async (channel, ...data) => {
if (mainAvailChannels.includes(channel)) {
const result = await ipcRenderer.invoke.apply(null, [channel, ...data])
return result
}
throw new Error(`Invoke failed: Unknown ipc channel name: ${channel}`)
}
})