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
28 lines (24 loc) · 1.07 KB
/
action.ts
File metadata and controls
28 lines (24 loc) · 1.07 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
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 | undefined): Promise<void> {
return new Promise(resolve => action?.setBadgeText({ text, tabId }, () => {
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?.())
}