From d677aeed0778f97ba6180a050ca4af98884eedec Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Wed, 8 May 2024 09:31:24 +0800 Subject: [PATCH] Refactor(Window): Automatically show application Automatically show application when opening the tool from a browser --- src/main/index.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/main/index.ts b/src/main/index.ts index b97451d..b29d785 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -1,4 +1,4 @@ -import { app, shell, BrowserWindow, ipcMain, webContents } from 'electron' +import { app, shell, BrowserWindow, ipcMain } from 'electron' import { join } from 'path' import { electronApp, optimizer, is } from '@electron-toolkit/utils' import icon from '../../resources/logo.ico?asset' @@ -31,10 +31,9 @@ const handleArgv = (argv: string[]) => { const handleUrl = (url: string) => { const { hostname, pathname } = new URL(url) - if (hostname === 'openurl') { - webContents.getAllWebContents().forEach((webContent) => { - webContent.send('open-url', pathname) - }) + if (hostname === 'openurl' && mainWindow) { + mainWindow.webContents.send('open-url', pathname) + mainWindow.show() } }