From 250aa7154a986d8c3fa214b6f80886bebf97ddbc Mon Sep 17 00:00:00 2001 From: gyuannn Date: Tue, 28 Jan 2025 17:20:53 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20mini-app=20?= =?UTF-8?q?=E4=B8=AD=E6=97=A0=E6=B3=95=E4=BD=BF=E7=94=A8=20context-menu=20?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/services/WindowService.ts | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/main/services/WindowService.ts b/src/main/services/WindowService.ts index 720fb877..87d09069 100644 --- a/src/main/services/WindowService.ts +++ b/src/main/services/WindowService.ts @@ -17,6 +17,7 @@ export class WindowService { private wasFullScreen: boolean = false private selectionMenuWindow: BrowserWindow | null = null private lastSelectedText: string = '' + private contextMenu: Menu | null = null public static getInstance(): WindowService { if (!WindowService.instance) { @@ -110,15 +111,25 @@ export class WindowService { } private setupContextMenu(mainWindow: BrowserWindow) { - mainWindow.webContents.on('context-menu', () => { + if (!this.contextMenu) { const locale = locales[configManager.getLanguage()] const { common } = locale.translation - const menu = new Menu() - menu.append(new MenuItem({ label: common.copy, role: 'copy' })) - menu.append(new MenuItem({ label: common.paste, role: 'paste' })) - menu.append(new MenuItem({ label: common.cut, role: 'cut' })) - menu.popup() + this.contextMenu = new Menu() + this.contextMenu.append(new MenuItem({ label: common.copy, role: 'copy' })) + this.contextMenu.append(new MenuItem({ label: common.paste, role: 'paste' })) + this.contextMenu.append(new MenuItem({ label: common.cut, role: 'cut' })) + } + + mainWindow.webContents.on('context-menu', () => { + this.contextMenu?.popup() + }) + + // Handle webview context menu + mainWindow.webContents.on('did-attach-webview', (_, webContents) => { + webContents.on('context-menu', () => { + this.contextMenu?.popup() + }) }) }