main: fix external link not working correctly

This commit is contained in:
leejooy96 committed 2023-02-04 17:12:08 +09:00
1 parent c38d6153fe
commit 5599c40db1
3 files changed
+9 -5

No files matched your search

+6 -1
View File
@@ -1,4 +1,4 @@
import { BrowserWindow, ipcMain } from 'electron' import { BrowserWindow, ipcMain, shell } from 'electron'
import Constants from './utils/Constants' import Constants from './utils/Constants'
/* /*
@@ -10,5 +10,10 @@ export default class IPCs {
ipcMain.on('msgRequestGetVersion', () => { ipcMain.on('msgRequestGetVersion', () => {
window.webContents.send('msgReceivedVersion', Constants.APP_VERSION) window.webContents.send('msgReceivedVersion', Constants.APP_VERSION)
}) })
// Open url via web browser
ipcMain.on('msgOpenExternalLink', async (event, url) => {
await shell.openExternal(url)
})
} }
} }
+2 -3
View File
@@ -1,11 +1,10 @@
import { contextBridge, ipcRenderer, shell } from 'electron' import { contextBridge, ipcRenderer } from 'electron'
// Whitelist of valid channels used for IPC communication (Send message from Renderer to Main) // Whitelist of valid channels used for IPC communication (Send message from Renderer to Main)
const mainAvailChannels = ['msgRequestGetVersion'] const mainAvailChannels = ['msgRequestGetVersion', 'msgOpenExternalLink']
const rendererAvailChannels = ['msgReceivedVersion'] const rendererAvailChannels = ['msgReceivedVersion']
contextBridge.exposeInMainWorld('mainApi', { contextBridge.exposeInMainWorld('mainApi', {
openExternal: async (url) => await shell.openExternal(url),
send: (channel, data) => { send: (channel, data) => {
if (mainAvailChannels.includes(channel)) { if (mainAvailChannels.includes(channel)) {
ipcRenderer.send(channel, data) ipcRenderer.send(channel, data)
+1 -1
View File
@@ -4,7 +4,7 @@ export default class Utils {
} }
static async openExternal(url: string): Promise<void> { static async openExternal(url: string): Promise<void> {
await window.mainApi.openExternal(url) await window.mainApi.send('msgOpenExternalLink', url)
} }
} }