forked from sheepzh/time-tracker-4-browser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontext-menu.ts
More file actions
26 lines (23 loc) · 924 Bytes
/
context-menu.ts
File metadata and controls
26 lines (23 loc) · 924 Bytes
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
import { IS_MV3 } from "@util/constant/environment"
import { handleError } from "./common"
function onClick(id: string, handler: Function) {
chrome.contextMenus.onClicked.addListener(({ menuItemId }) => menuItemId === id && handler?.())
}
export function createContextMenu(props: ChromeContextMenuCreateProps): Promise<void> {
let clickHandler: Function = undefined
if (IS_MV3) {
clickHandler = props.onclick
delete props.onclick
}
return new Promise(resolve => chrome.contextMenus.create(props, () => {
handleError('createContextMenu')
clickHandler && onClick(props.id, clickHandler)
resolve()
}))
}
export function updateContextMenu(menuId: string, props: ChromeContextMenuUpdateProps): Promise<void> {
return new Promise(resolve => chrome.contextMenus.update(menuId, props, () => {
handleError('updateContextMenu')
resolve()
}))
}