From 99b37f27827a1e1661b64c8a5ddbd4a5293d0f8a Mon Sep 17 00:00:00 2001 From: fullex <106392080+0xfullex@users.noreply.github.com> Date: Mon, 7 Apr 2025 09:51:10 +0800 Subject: [PATCH] perf: remove unused codes related to minapp (#4444) --- src/main/ipc.ts | 12 -------- src/main/services/WindowService.ts | 30 ------------------- src/preload/index.d.ts | 1 - src/preload/index.ts | 1 - .../components/MinApp/WebviewContainer.tsx | 10 ------- 5 files changed, 54 deletions(-) diff --git a/src/main/ipc.ts b/src/main/ipc.ts index 22e0b7db..c6bceac3 100644 --- a/src/main/ipc.ts +++ b/src/main/ipc.ts @@ -193,18 +193,6 @@ export function registerIpc(mainWindow: BrowserWindow, app: Electron.App) { // fs ipcMain.handle(IpcChannel.Fs_Read, FileService.readFile) - // minapp - ipcMain.handle(IpcChannel.Minapp, (_, args) => { - windowService.createMinappWindow({ - url: args.url, - parent: mainWindow, - windowOptions: { - ...mainWindow.getBounds(), - ...args.windowOptions - } - }) - }) - // export ipcMain.handle(IpcChannel.Export_Word, exportService.exportToWord) diff --git a/src/main/services/WindowService.ts b/src/main/services/WindowService.ts index 9e1cf3cb..1e8d071b 100644 --- a/src/main/services/WindowService.ts +++ b/src/main/services/WindowService.ts @@ -83,36 +83,6 @@ export class WindowService { return this.mainWindow } - public createMinappWindow({ - url, - parent, - windowOptions - }: { - url: string - parent?: BrowserWindow - windowOptions?: Electron.BrowserWindowConstructorOptions - }): BrowserWindow { - const width = windowOptions?.width || 1000 - const height = windowOptions?.height || 680 - - const minappWindow = new BrowserWindow({ - width, - height, - autoHideMenuBar: true, - title: 'Cherry Studio', - ...windowOptions, - parent, - webPreferences: { - preload: join(__dirname, '../preload/minapp.js'), - sandbox: false, - contextIsolation: false - } - }) - - minappWindow.loadURL(url) - return minappWindow - } - private setupMainWindow(mainWindow: BrowserWindow, mainWindowState: any) { mainWindowState.manage(mainWindow) diff --git a/src/preload/index.d.ts b/src/preload/index.d.ts index aee54e55..9e63498c 100644 --- a/src/preload/index.d.ts +++ b/src/preload/index.d.ts @@ -29,7 +29,6 @@ declare global { setTrayOnClose: (isActive: boolean) => void restartTray: () => void setTheme: (theme: 'light' | 'dark') => void - minApp: (options: { url: string; windowOptions?: Electron.BrowserWindowConstructorOptions }) => void reload: () => void clearCache: () => Promise<{ success: boolean; error?: string }> system: { diff --git a/src/preload/index.ts b/src/preload/index.ts index c8b6fb1a..33db0852 100644 --- a/src/preload/index.ts +++ b/src/preload/index.ts @@ -20,7 +20,6 @@ const api = { restartTray: () => ipcRenderer.invoke(IpcChannel.App_RestartTray), setTheme: (theme: 'light' | 'dark') => ipcRenderer.invoke(IpcChannel.App_SetTheme, theme), openWebsite: (url: string) => ipcRenderer.invoke(IpcChannel.Open_Website, url), - minApp: (url: string) => ipcRenderer.invoke(IpcChannel.Minapp, url), clearCache: () => ipcRenderer.invoke(IpcChannel.App_ClearCache), system: { getDeviceType: () => ipcRenderer.invoke(IpcChannel.System_GetDeviceType) diff --git a/src/renderer/src/components/MinApp/WebviewContainer.tsx b/src/renderer/src/components/MinApp/WebviewContainer.tsx index 203122e0..3d9eadc2 100644 --- a/src/renderer/src/components/MinApp/WebviewContainer.tsx +++ b/src/renderer/src/components/MinApp/WebviewContainer.tsx @@ -38,13 +38,6 @@ const WebviewContainer = memo( useEffect(() => { if (!webviewRef.current) return - const handleNewWindow = (event: any) => { - event.preventDefault() - if (webviewRef.current?.loadURL) { - webviewRef.current.loadURL(event.url) - } - } - const handleLoaded = () => { onLoadedCallback(appid) } @@ -53,7 +46,6 @@ const WebviewContainer = memo( onNavigateCallback(appid, event.url) } - webviewRef.current.addEventListener('new-window', handleNewWindow) webviewRef.current.addEventListener('did-finish-load', handleLoaded) webviewRef.current.addEventListener('did-navigate-in-page', handleNavigate) @@ -61,7 +53,6 @@ const WebviewContainer = memo( webviewRef.current.src = url return () => { - webviewRef.current?.removeEventListener('new-window', handleNewWindow) webviewRef.current?.removeEventListener('did-finish-load', handleLoaded) webviewRef.current?.removeEventListener('did-navigate-in-page', handleNavigate) } @@ -76,7 +67,6 @@ const WebviewContainer = memo( style={WebviewStyle} allowpopups={'true' as any} partition="persist:webview" - nodeintegration={'true' as any} /> ) }