diff --git a/src/main/core/tray.ts b/src/main/core/tray.ts index c497dd2..741f238 100644 --- a/src/main/core/tray.ts +++ b/src/main/core/tray.ts @@ -7,7 +7,7 @@ import { import icoIcon from '../../../resources/icon.ico?asset' import pngIcon from '../../../resources/icon.png?asset' import { patchMihomoConfig } from './mihomoApi' -import { createWindow, destroyTimer, mainWindow } from '..' +import { mainWindow, showMainWindow } from '..' import { app, ipcMain, Menu, shell, Tray } from 'electron' import { dataDir, logDir, mihomoCoreDir, mihomoWorkDir } from '../utils/dirs' import { triggerSysProxy } from '../resolve/sysproxy' @@ -23,15 +23,7 @@ const buildContextMenu = async (): Promise => { label: '显示窗口', type: 'normal', click: (): void => { - if (!mainWindow) { - if (destroyTimer) { - clearTimeout(destroyTimer) - } - createWindow(true) - } else { - mainWindow?.show() - mainWindow?.focusOnWebView() - } + showMainWindow() } }, { @@ -169,14 +161,7 @@ export async function createTray(): Promise { if (mainWindow?.isVisible()) { mainWindow?.close() } else { - if (!mainWindow) { - if (destroyTimer) { - clearTimeout(destroyTimer) - } - createWindow(true) - } else { - mainWindow?.show() - } + showMainWindow() } }) } diff --git a/src/main/index.ts b/src/main/index.ts index 206a420..3e3d7eb 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -27,16 +27,7 @@ if (!gotTheLock) { const initPromise = init() app.on('second-instance', async (_event, commandline) => { - if (!mainWindow) { - if (destroyTimer) { - clearTimeout(destroyTimer) - } - createWindow(true) - } else { - mainWindow?.show() - mainWindow?.focusOnWebView() - } - + showMainWindow() const url = commandline.pop() if (url) { await handleDeepLink(url) @@ -44,16 +35,7 @@ app.on('second-instance', async (_event, commandline) => { }) app.on('open-url', async (_event, url) => { - if (!mainWindow) { - if (destroyTimer) { - clearTimeout(destroyTimer) - } - createWindow(true) - } else { - mainWindow?.show() - mainWindow?.focusOnWebView() - } - + showMainWindow() await handleDeepLink(url) }) // Quit when all windows are closed, except on macOS. There, it's common @@ -191,7 +173,6 @@ export function createWindow(show = false): void { mainWindow?.destroy() mainWindow = null }, 300000) - // mainWindow?.webContents.reload() }) mainWindow.webContents.setWindowOpenHandler((details) => { @@ -207,3 +188,15 @@ export function createWindow(show = false): void { mainWindow.loadFile(join(__dirname, '../renderer/index.html')) } } + +export function showMainWindow(): void { + if (destroyTimer) { + clearTimeout(destroyTimer) + } + if (mainWindow) { + mainWindow.show() + mainWindow.focusOnWebView() + } else { + createWindow(true) + } +} diff --git a/src/renderer/src/pages/profiles.tsx b/src/renderer/src/pages/profiles.tsx index 9044095..90c82a3 100644 --- a/src/renderer/src/pages/profiles.tsx +++ b/src/renderer/src/pages/profiles.tsx @@ -94,7 +94,29 @@ const Profiles: React.FC = () => { }, [items]) return ( - + { + for (const item of items) { + if (item.id === current) continue + if (item.type !== 'remote') continue + await addProfileItem(item) + } + const currentItem = items.find((item) => item.id === current) + if (currentItem && currentItem.type === 'remote') { + await addProfileItem(currentItem) + } + }} + > + 更新全部订阅 + + } + >