fix: filter context menu in web app

Signed-off-by: Innei <i@innei.in>
This commit is contained in:
Innei 2024-06-27 14:54:44 +08:00
parent e2beb86955
commit 2ff6fc0082
No known key found for this signature in database
GPG Key ID: 0F62D33977F021F7
1 changed files with 19 additions and 20 deletions

View File

@ -12,26 +12,7 @@ export const showNativeMenu = async (
items: Array<Nullable<NativeMenuItem | false>>,
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) => {