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'] const rendererAvailChannels = ['msgReceivedVersion']
contextBridge.exposeInMainWorld('mainApi', { contextBridge.exposeInMainWorld('mainApi', {
send: (channel, data) => { send: (channel, ...data) => {
if (mainAvailChannels.includes(channel)) { 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) => { receive: (channel, cbFunc) => {
if (rendererAvailChannels.includes(channel)) { 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}`)
} }
}) })
+1 -1
View File
@@ -17,7 +17,7 @@ onMounted((): void => {
languages.value = availableLocales languages.value = availableLocales
// Get application version from package.json version string (Using IPC communication) // 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 appVersion.value = version
}) })
window.mainApi.send('msgRequestGetVersion') window.mainApi.send('msgRequestGetVersion')