forked from Stigmatoz/web-activity-time-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuseBadge.ts
More file actions
42 lines (38 loc) · 970 Bytes
/
useBadge.ts
File metadata and controls
42 lines (38 loc) · 970 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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import Browser from 'webextension-polyfill';
export interface BadgeState {
text: string | null;
color: BadgeColor;
tabId?: number;
icon?: BadgeIcon;
}
export enum BadgeIcon {
default = '/128x128.png',
pomodoroWorkingTime = '/assets/icons/pomodoro.png',
pomodoroRestTime = '/assets/icons/pomodoro-rest.png',
}
export enum BadgeColor {
red = '#fdb8b8',
green = '#6ec05e',
blue = '#1a73e8',
none = '#000',
}
export async function useBadge(badge: BadgeState): Promise<void> {
if (badge.color != BadgeColor.none)
await Browser.action.setBadgeBackgroundColor({ color: badge.color });
await Browser.action.setBadgeText({
tabId: badge.tabId,
text: badge.text,
});
if (badge.icon) {
await Browser.action.setIcon({
path: badge.icon,
});
await Browser.action.setBadgeText({
tabId: badge.tabId,
text: badge.text,
});
} else
await Browser.action.setIcon({
path: BadgeIcon.default,
});
}