File tree Expand file tree Collapse file tree 1 file changed +20
-5
lines changed
Expand file tree Collapse file tree 1 file changed +20
-5
lines changed Original file line number Diff line number Diff line change 88const STORAGE_KEY = "_logOpen"
99const STORAGE_VAL = "1"
1010
11- let OPEN_LOG = localStorage . getItem ( STORAGE_KEY ) === STORAGE_VAL
11+ let OPEN_LOG = false
12+
13+ // localStorage is not undefined in mv3 of service worker
14+ function initOpenLog ( ) {
15+ try {
16+ localStorage . getItem ( STORAGE_KEY ) === STORAGE_VAL
17+ } catch ( ignored ) { }
18+ }
19+
20+ function updateLocalStorage ( openState : boolean ) {
21+ try {
22+ openState
23+ ? localStorage . setItem ( STORAGE_KEY , STORAGE_VAL )
24+ : localStorage . removeItem ( STORAGE_KEY )
25+ } catch ( ignored ) { }
26+ }
27+
28+ initOpenLog ( )
1229
1330/**
1431 * @since 0.0.4
@@ -22,16 +39,14 @@ export function log(...args: any) {
2239 * @since 0.0.4
2340 */
2441export function openLog ( ) : string {
25- OPEN_LOG = true
26- localStorage . setItem ( STORAGE_KEY , STORAGE_VAL )
42+ updateLocalStorage ( OPEN_LOG = true )
2743 return 'Opened the log manually.'
2844}
2945
3046/**
3147 * @since 0.0.8
3248 */
3349export function closeLog ( ) : string {
34- OPEN_LOG = false
35- localStorage . removeItem ( STORAGE_KEY )
50+ updateLocalStorage ( OPEN_LOG = false )
3651 return 'Closed the log manually.'
3752}
You can’t perform that action at this time.
0 commit comments