From 183b46be9eae8b4f4573a4ee0e464ad7063c2306 Mon Sep 17 00:00:00 2001 From: kangfenmao Date: Mon, 22 Sep 2025 20:20:14 +0800 Subject: [PATCH] feat(ipc): add App_Quit channel and update related handlers - Introduced a new IPC channel for quitting the application. - Updated ipc.ts to handle the App_Quit channel, allowing the app to quit when invoked. - Added corresponding quit method in the preload API for client-side access. - Fixed a minor URL check in WindowService to ensure proper navigation handling. --- packages/shared/IpcChannel.ts | 1 + src/main/ipc.ts | 1 + src/main/services/WindowService.ts | 2 +- src/preload/index.ts | 1 + 4 files changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/shared/IpcChannel.ts b/packages/shared/IpcChannel.ts index 1e925984a8..7f766d21e1 100644 --- a/packages/shared/IpcChannel.ts +++ b/packages/shared/IpcChannel.ts @@ -8,6 +8,7 @@ export enum IpcChannel { App_ShowUpdateDialog = 'app:show-update-dialog', App_CheckForUpdate = 'app:check-for-update', App_Reload = 'app:reload', + App_Quit = 'app:quit', App_Info = 'app:info', App_Proxy = 'app:proxy', App_SetLaunchToTray = 'app:set-launch-to-tray', diff --git a/src/main/ipc.ts b/src/main/ipc.ts index d0ef8ec94a..7ca6853e39 100644 --- a/src/main/ipc.ts +++ b/src/main/ipc.ts @@ -126,6 +126,7 @@ export function registerIpc(mainWindow: BrowserWindow, app: Electron.App) { }) ipcMain.handle(IpcChannel.App_Reload, () => mainWindow.reload()) + ipcMain.handle(IpcChannel.App_Quit, () => app.quit()) ipcMain.handle(IpcChannel.Open_Website, (_, url: string) => shell.openExternal(url)) // Update diff --git a/src/main/services/WindowService.ts b/src/main/services/WindowService.ts index 7cf01b9fc7..66aed098e7 100644 --- a/src/main/services/WindowService.ts +++ b/src/main/services/WindowService.ts @@ -256,7 +256,7 @@ export class WindowService { private setupWebContentsHandlers(mainWindow: BrowserWindow) { mainWindow.webContents.on('will-navigate', (event, url) => { - if (url.includes('localhost:5173')) { + if (url.includes('localhost:517')) { return } diff --git a/src/preload/index.ts b/src/preload/index.ts index af1cac21a1..a77e47e78d 100644 --- a/src/preload/index.ts +++ b/src/preload/index.ts @@ -47,6 +47,7 @@ const api = { getDiskInfo: (directoryPath: string): Promise<{ free: number; size: number } | null> => ipcRenderer.invoke(IpcChannel.App_GetDiskInfo, directoryPath), reload: () => ipcRenderer.invoke(IpcChannel.App_Reload), + quit: () => ipcRenderer.invoke(IpcChannel.App_Quit), setProxy: (proxy: string | undefined, bypassRules?: string) => ipcRenderer.invoke(IpcChannel.App_Proxy, proxy, bypassRules), checkForUpdate: () => ipcRenderer.invoke(IpcChannel.App_CheckForUpdate),