preload: fix handle preload data arguments
This commit is contained in:
1 parent
32a8c7067a
commit
00ae01dc3f
2 files changed
+15
-4
No files matched your search
+14
-3
@@ -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}`)
|
||||
}
|
||||
})
|
||||
@@ -17,7 +17,7 @@ onMounted((): void => {
|
||||
languages.value = availableLocales
|
||||
|
||||
// Get application version from package.json version string (Using IPC communication)
|
||||
window.mainApi.receive('msgReceivedVersion', (version: string) => {
|
||||
window.mainApi.receive('msgReceivedVersion', (event: Event, version: string) => {
|
||||
appVersion.value = version
|
||||
})
|
||||
window.mainApi.send('msgRequestGetVersion')
|
||||
|
||||
Reference in new issue
Block a user