forked from sheepzh/time-tracker-4-browser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.ts
More file actions
30 lines (26 loc) · 1.16 KB
/
Copy pathaction.ts
File metadata and controls
30 lines (26 loc) · 1.16 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
import { IS_FIREFOX, IS_MV3 } from "@util/constant/environment"
import { handleError } from "./common"
const action = IS_MV3 ? chrome.action : chrome.browserAction
export function setBadgeText(text: string, tabId?: number): Promise<void> {
const details: { text: string; tabId?: number } =
tabId === undefined ? { text } : { text, tabId }
return new Promise(resolve => action?.setBadgeText(details, () => {
handleError('setBadgeText')
resolve()
}))
}
export function setBadgeBgColor(color: string | chrome.extensionTypes.ColorArray | undefined): Promise<void> {
let realColor: string | chrome.extensionTypes.ColorArray = color ?? (
// Use null to clear bg color for Firefox
IS_FIREFOX ? null as unknown as string : [0, 0, 0, 0]
)
return new Promise(resolve => action?.setBadgeBackgroundColor({ color: realColor }, () => {
handleError('setBadgeColor')
resolve()
}))
}
export function onIconClick(handler: () => void) {
// Forbidden popup page first by setting popup empty string
action.setPopup({ popup: '' }, () => handleError('setPopup'))
action.onClicked.addListener(() => handler?.())
}