@@ -32,11 +32,17 @@ async function requestDashVersionInfo(config) {
32
32
ddk_version : ddkVersion ,
33
33
plotly_version : plotlyVersion
34
34
} = config ;
35
- const cachedVersionInfo = localStorage . getItem ( 'cachedNewDashVersion' ) ;
36
- const cachedNewDashVersionLink = localStorage . getItem (
37
- 'cachedNewDashVersionLink'
38
- ) ;
39
- const lastFetched = localStorage . getItem ( 'lastFetched' ) ;
35
+ let cachedVersionInfo , cachedNewDashVersionLink , lastFetched ;
36
+ try {
37
+ cachedVersionInfo = localStorage . getItem ( 'cachedNewDashVersion' ) ;
38
+ cachedNewDashVersionLink = localStorage . getItem (
39
+ 'cachedNewDashVersionLink'
40
+ ) ;
41
+ lastFetched = localStorage . getItem ( 'lastFetched' ) ;
42
+ } catch ( e ) {
43
+ // If localStorage is not available, return an empty object
44
+ return { } ;
45
+ }
40
46
if (
41
47
lastFetched &&
42
48
Date . now ( ) - Number ( lastFetched ) < DAY_IN_MS &&
@@ -57,12 +63,19 @@ async function requestDashVersionInfo(config) {
57
63
. then ( response => response . json ( ) )
58
64
. then ( body => {
59
65
if ( body && body . version && body . link ) {
60
- localStorage . setItem (
61
- 'cachedNewDashVersion' ,
62
- JSON . stringify ( body . version )
63
- ) ;
64
- localStorage . setItem ( 'cachedNewDashVersionLink' , body . link ) ;
65
- localStorage . setItem ( 'lastFetched' , Date . now ( ) ) ;
66
+ try {
67
+ localStorage . setItem (
68
+ 'cachedNewDashVersion' ,
69
+ JSON . stringify ( body . version )
70
+ ) ;
71
+ localStorage . setItem (
72
+ 'cachedNewDashVersionLink' ,
73
+ body . link
74
+ ) ;
75
+ localStorage . setItem ( 'lastFetched' , Date . now ( ) ) ;
76
+ } catch ( e ) {
77
+ // Ignore errors if localStorage is not available
78
+ }
66
79
return body ;
67
80
} else {
68
81
return { } ;
@@ -75,12 +88,19 @@ async function requestDashVersionInfo(config) {
75
88
}
76
89
77
90
function shouldRequestDashVersion ( config ) {
78
- const showNotificationsLocalStorage =
79
- localStorage . getItem ( 'showNotifications' ) ;
80
- const showNotifications = config . disable_version_check
81
- ? false
82
- : showNotificationsLocalStorage !== 'false' ;
83
- const lastFetched = localStorage . getItem ( 'lastFetched' ) ;
91
+ let showNotificationsLocalStorage , showNotifications , lastFetched ;
92
+ try {
93
+ showNotificationsLocalStorage =
94
+ localStorage . getItem ( 'showNotifications' ) ;
95
+
96
+ showNotifications = config . disable_version_check
97
+ ? false
98
+ : showNotificationsLocalStorage !== 'false' ;
99
+ lastFetched = localStorage . getItem ( 'lastFetched' ) ;
100
+ } catch ( e ) {
101
+ // If localStorage is not available, return false
102
+ return false ;
103
+ }
84
104
return (
85
105
showNotifications &&
86
106
( ! lastFetched || Date . now ( ) - Number ( lastFetched ) > DAY_IN_MS )
@@ -92,13 +112,19 @@ function shouldShowUpgradeNotification(
92
112
newDashVersion ,
93
113
config
94
114
) {
95
- const showNotificationsLocalStorage =
96
- localStorage . getItem ( 'showNotifications' ) ;
115
+ let showNotificationsLocalStorage , lastDismissed , lastDismissedVersion ;
116
+ try {
117
+ showNotificationsLocalStorage =
118
+ localStorage . getItem ( 'showNotifications' ) ;
119
+ lastDismissed = localStorage . getItem ( 'lastDismissed' ) ;
120
+ lastDismissedVersion = localStorage . getItem ( 'lastDismissedVersion' ) ;
121
+ } catch ( e ) {
122
+ // If localStorage is not available, return false
123
+ return false ;
124
+ }
97
125
const showNotifications = config . disable_version_check
98
126
? false
99
127
: showNotificationsLocalStorage !== 'false' ;
100
- const lastDismissed = localStorage . getItem ( 'lastDismissed' ) ;
101
- const lastDismissedVersion = localStorage . getItem ( 'lastDismissedVersion' ) ;
102
128
if (
103
129
newDashVersion === undefined ||
104
130
compareVersions ( currentDashVersion , newDashVersion ) >= 0 ||
@@ -113,10 +139,7 @@ function shouldShowUpgradeNotification(
113
139
} else if (
114
140
lastDismissedVersion &&
115
141
! lastDismissed &&
116
- compareVersions (
117
- localStorage . getItem ( 'lastDismissedVersion' ) ,
118
- newDashVersion
119
- ) < 0
142
+ compareVersions ( lastDismissedVersion , newDashVersion ) < 0
120
143
) {
121
144
return true ;
122
145
} else {
@@ -131,19 +154,31 @@ export const VersionInfo = ({config}) => {
131
154
132
155
const setDontShowAgain = ( ) => {
133
156
// Set local storage to record the last dismissed notification
134
- localStorage . setItem ( 'showNotifications' , false ) ;
157
+ try {
158
+ localStorage . setItem ( 'showNotifications' , false ) ;
159
+ } catch ( e ) {
160
+ // Ignore errors if localStorage is not available
161
+ }
135
162
setUpgradeTooltipOpened ( false ) ;
136
163
} ;
137
164
138
165
const setRemindMeLater = ( ) => {
139
166
// Set local storage to record the last dismissed notification
140
- localStorage . setItem ( 'lastDismissed' , Date . now ( ) ) ;
167
+ try {
168
+ localStorage . setItem ( 'lastDismissed' , Date . now ( ) ) ;
169
+ } catch ( e ) {
170
+ // Ignore errors if localStorage is not available
171
+ }
141
172
setUpgradeTooltipOpened ( false ) ;
142
173
} ;
143
174
144
175
const setSkipThisVersion = ( ) => {
145
176
// Set local storage to record the last dismissed version
146
- localStorage . setItem ( 'lastDismissedVersion' , newDashVersion ) ;
177
+ try {
178
+ localStorage . setItem ( 'lastDismissedVersion' , newDashVersion ) ;
179
+ } catch ( e ) {
180
+ // Ignore errors if localStorage is not available
181
+ }
147
182
setUpgradeTooltipOpened ( false ) ;
148
183
} ;
149
184
0 commit comments