forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontextMenu.ts
More file actions
34 lines (33 loc) · 1.73 KB
/
Copy pathcontextMenu.ts
File metadata and controls
34 lines (33 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { Menu, clipboard, shell } from 'electron'
import type { BrowserWindow } from 'electron'
import { buildContextMenuTemplate, LINK_SCHEMES } from './contextMenuTemplate'
import { isAllowedExternalScheme } from './externalUrl'
/**
* Give a window Windows' standard right-click menu — editing (undo/redo, cut/copy/
* paste, select all) plus, on a hyperlink, Open Link / Copy Link Address. Native,
* so it's accessible to Narrator/UIA and follows the OS menu theme. Install on
* every window the user can type, select text, or click a link in.
*
* Without this, right-clicking anywhere in the app does nothing at all: Electron
* ships no default context menu.
*/
export function installContextMenu(win: BrowserWindow): void {
win.webContents.on('context-menu', (_event, params) => {
const template = buildContextMenuTemplate(params, {
copyText: (text) => clipboard.writeText(text),
// Same guard index.ts applies before every shell.openExternal: a chat link
// can be steered by prompt injection to a file://, UNC, or custom-protocol
// URL, and handing those to the OS enables NTLM-hash leak / protocol abuse.
// The builder already gates the menu item on this list; validating again
// here keeps the OS hand-off safe on its own terms. Never navigates the app
// window — the link opens in the user's default browser.
openExternal: (url) => {
if (isAllowedExternalScheme(url, LINK_SCHEMES)) shell.openExternal(url)
// Never log the raw URL — it may carry a token/secret in its query string.
else console.warn('[main] blocked context-menu open of a non-web link')
}
})
if (!template.length) return
Menu.buildFromTemplate(template).popup({ window: win })
})
}