forked from sheepzh/time-tracker-4-browser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsidePanel.ts
More file actions
33 lines (28 loc) · 1.11 KB
/
sidePanel.ts
File metadata and controls
33 lines (28 loc) · 1.11 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
31
32
33
import { IS_ANDROID, IS_MV3 } from '@util/constant/environment'
import { handleError } from './common'
// NOT SUPPORTED in Firefox
// Keep noticing at chrome.sidebarAction for Firefox
export const SIDE_PANEL_STATE_SUPPORTED_CONTROL = !!chrome.sidePanel?.setOptions
export async function isSidePanelEnabled(): Promise<boolean> {
if (IS_ANDROID || !SIDE_PANEL_STATE_SUPPORTED_CONTROL) return false
if (IS_MV3) {
const result = await chrome.sidePanel.getOptions({})
return result.enabled ?? true
} else {
return new Promise(resolve => chrome.sidePanel.getOptions({}, options => {
handleError('isSidePanelEnabled')
resolve(options.enabled ?? true)
}))
}
}
export async function setSidePanelEnabled(enabled: boolean): Promise<void> {
if (IS_ANDROID || !SIDE_PANEL_STATE_SUPPORTED_CONTROL) return
if (IS_MV3) {
await chrome.sidePanel.setOptions({ enabled })
} else {
return new Promise(resolve => chrome.sidePanel.setOptions({ enabled }, () => {
handleError('setSidePanelEnabled')
resolve()
}))
}
}