MCPcopy Create free account
hub / github.com/bearlyai/OpenADE / addContextMenu

Function addContextMenu

projects/electron/src/modules/contextMenu.ts:6–41  ·  view source on GitHub ↗
(wc: WebContents)

Source from the content-addressed store, hash-verified

4const trackedContents = new WeakSet<WebContents>()
5
6const addContextMenu = (wc: WebContents) => {
7 if (trackedContents.has(wc)) {
8 return
9 }
10 trackedContents.add(wc)
11
12 wc.once("destroyed", () => {
13 trackedContents.delete(wc)
14 })
15
16 wc.on("context-menu", (_event, params: ContextMenuParams) => {
17 try {
18 const template = buildNativeContextMenuTemplate(
19 params,
20 {
21 replaceMisspelling: (word: string) => wc.replaceMisspelling(word),
22 learnSpelling: (word: string) => wc.session.addWordToSpellCheckerDictionary(word),
23 lookUpSelection: () => wc.showDefinitionForSelection(),
24 copyImageAt: (x: number, y: number) => wc.copyImageAt(x, y),
25 copyImageAddress: (url: string) => clipboard.write({ text: url, bookmark: url }),
26 copyVideoAddress: (url: string) => clipboard.write({ text: url, bookmark: url }),
27 copyLink: (url: string, text: string) => clipboard.write({ text: url, bookmark: text || url }),
28 },
29 process.platform
30 )
31
32 if (template.length === 0) {
33 return
34 }
35
36 Menu.buildFromTemplate(template).popup()
37 } catch (error) {
38 console.error("[contextMenu] Failed to build or show context menu:", error)
39 }
40 })
41}
42
43export const load = () => {
44 app.on("web-contents-created", (_, wc) => {

Callers 1

loadFunction · 0.85

Calls 6

hasMethod · 0.80
errorMethod · 0.80
deleteMethod · 0.65
writeMethod · 0.65
onMethod · 0.45

Tested by

no test coverage detected