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() + }) }) }