@@ -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,20 @@ 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
+ // If version check is disabled, return false to avoid
92
+ // checking localStorage unnecessarily
93
+ if ( config . disable_version_check ) {
94
+ return false ;
95
+ }
96
+ let showNotifications , lastFetched ;
97
+ try {
98
+ showNotifications =
99
+ localStorage . getItem ( 'showNotifications' ) !== 'false' ;
100
+ lastFetched = localStorage . getItem ( 'lastFetched' ) ;
101
+ } catch ( e ) {
102
+ // If localStorage is not available, return false
103
+ return false ;
104
+ }
84
105
return (
85
106
showNotifications &&
86
107
( ! lastFetched || Date . now ( ) - Number ( lastFetched ) > DAY_IN_MS )
@@ -92,13 +113,21 @@ function shouldShowUpgradeNotification(
92
113
newDashVersion ,
93
114
config
94
115
) {
95
- const showNotificationsLocalStorage =
96
- localStorage . getItem ( 'showNotifications' ) ;
97
- const showNotifications = config . disable_version_check
98
- ? false
99
- : showNotificationsLocalStorage !== 'false' ;
100
- const lastDismissed = localStorage . getItem ( 'lastDismissed' ) ;
101
- const lastDismissedVersion = localStorage . getItem ( 'lastDismissedVersion' ) ;
116
+ // If version check is disabled, return false to avoid
117
+ // checking localStorage unnecessarily
118
+ if ( config . disable_version_check ) {
119
+ return false ;
120
+ }
121
+ let showNotifications , lastDismissed , lastDismissedVersion ;
122
+ try {
123
+ showNotifications =
124
+ localStorage . getItem ( 'showNotifications' ) !== 'false' ;
125
+ lastDismissed = localStorage . getItem ( 'lastDismissed' ) ;
126
+ lastDismissedVersion = localStorage . getItem ( 'lastDismissedVersion' ) ;
127
+ } catch ( e ) {
128
+ // If localStorage is not available, return false
129
+ return false ;
130
+ }
102
131
if (
103
132
newDashVersion === undefined ||
104
133
compareVersions ( currentDashVersion , newDashVersion ) >= 0 ||
@@ -113,10 +142,7 @@ function shouldShowUpgradeNotification(
113
142
} else if (
114
143
lastDismissedVersion &&
115
144
! lastDismissed &&
116
- compareVersions (
117
- localStorage . getItem ( 'lastDismissedVersion' ) ,
118
- newDashVersion
119
- ) < 0
145
+ compareVersions ( lastDismissedVersion , newDashVersion ) < 0
120
146
) {
121
147
return true ;
122
148
} else {
@@ -131,19 +157,31 @@ export const VersionInfo = ({config}) => {
131
157
132
158
const setDontShowAgain = ( ) => {
133
159
// Set local storage to record the last dismissed notification
134
- localStorage . setItem ( 'showNotifications' , false ) ;
160
+ try {
161
+ localStorage . setItem ( 'showNotifications' , false ) ;
162
+ } catch ( e ) {
163
+ // Ignore errors if localStorage is not available
164
+ }
135
165
setUpgradeTooltipOpened ( false ) ;
136
166
} ;
137
167
138
168
const setRemindMeLater = ( ) => {
139
169
// Set local storage to record the last dismissed notification
140
- localStorage . setItem ( 'lastDismissed' , Date . now ( ) ) ;
170
+ try {
171
+ localStorage . setItem ( 'lastDismissed' , Date . now ( ) ) ;
172
+ } catch ( e ) {
173
+ // Ignore errors if localStorage is not available
174
+ }
141
175
setUpgradeTooltipOpened ( false ) ;
142
176
} ;
143
177
144
178
const setSkipThisVersion = ( ) => {
145
179
// Set local storage to record the last dismissed version
146
- localStorage . setItem ( 'lastDismissedVersion' , newDashVersion ) ;
180
+ try {
181
+ localStorage . setItem ( 'lastDismissedVersion' , newDashVersion ) ;
182
+ } catch ( e ) {
183
+ // Ignore errors if localStorage is not available
184
+ }
147
185
setUpgradeTooltipOpened ( false ) ;
148
186
} ;
149
187
0 commit comments