From 2ff6fc008294a63c71b0ecc901edf1ea8948d37c Mon Sep 17 00:00:00 2001 From: Innei Date: Thu, 27 Jun 2024 14:54:44 +0800 Subject: [PATCH] fix: filter context menu in web app Signed-off-by: Innei --- src/renderer/src/lib/native-menu.ts | 39 ++++++++++++++--------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/src/renderer/src/lib/native-menu.ts b/src/renderer/src/lib/native-menu.ts index 238e02bd4..5a1dc5eb8 100644 --- a/src/renderer/src/lib/native-menu.ts +++ b/src/renderer/src/lib/native-menu.ts @@ -12,26 +12,7 @@ export const showNativeMenu = async ( items: Array>, e?: MouseEvent | React.MouseEvent, ) => { - const nextItems = [ - ...items, - ...(import.meta.env.DEV && e ? - [ - { - type: "separator" as const, - }, - { - type: "text" as const, - label: "Inspect Element", - click: () => { - tipcClient?.inspectElement({ - x: e.pageX, - y: e.pageY, - }) - }, - }, - ] : - []), - ].filter(Boolean) as NativeMenuItem[] + const nextItems = items.filter(Boolean) as NativeMenuItem[] const el = e && e.currentTarget @@ -50,6 +31,24 @@ export const showNativeMenu = async ( }), ) return + } else { + if (import.meta.env.DEV && e) { + nextItems.push( + { + type: "separator" as const, + }, + { + type: "text" as const, + label: "Inspect Element", + click: () => { + tipcClient?.inspectElement({ + x: e.pageX, + y: e.pageY, + }) + }, + }, + ) + } } const unlisten = window.electron?.ipcRenderer.on("menu-click", (_, index) => {