@@ -18,6 +18,7 @@ export interface CachedMod {
18
18
}
19
19
20
20
interface State {
21
+ activeGameCacheStatus : string | undefined ;
21
22
cache : Map < string , CachedMod > ;
22
23
deprecated : Map < string , boolean > ;
23
24
exclusions : string [ ] ;
@@ -55,6 +56,8 @@ export const TsModsModule = {
55
56
namespaced : true ,
56
57
57
58
state : ( ) : State => ( {
59
+ /*** Does the active game have a mod list stored in IndexedDB? */
60
+ activeGameCacheStatus : undefined ,
58
61
cache : new Map < string , CachedMod > ( ) ,
59
62
deprecated : new Map < string , boolean > ( ) ,
60
63
/*** Packages available through API that should be ignored by the manager */
@@ -127,6 +130,7 @@ export const TsModsModule = {
127
130
128
131
mutations : < MutationTree < State > > {
129
132
reset ( state : State ) {
133
+ state . activeGameCacheStatus = undefined ;
130
134
state . cache = new Map < string , CachedMod > ( ) ;
131
135
state . deprecated = new Map < string , boolean > ( ) ;
132
136
state . mods = [ ] ;
@@ -141,6 +145,9 @@ export const TsModsModule = {
141
145
state . isThunderstoreModListUpdateInProgress = false ;
142
146
state . thunderstoreModListUpdateStatus = '' ;
143
147
} ,
148
+ setActiveGameCacheStatus ( state , status : string | undefined ) {
149
+ state . activeGameCacheStatus = status ;
150
+ } ,
144
151
setMods ( state , payload : ThunderstoreMod [ ] ) {
145
152
state . mods = payload ;
146
153
} ,
@@ -222,6 +229,7 @@ export const TsModsModule = {
222
229
} catch ( e ) {
223
230
commit ( 'setThunderstoreModListUpdateError' , e ) ;
224
231
} finally {
232
+ commit ( 'setActiveGameCacheStatus' , undefined ) ;
225
233
commit ( 'finishThunderstoreModListUpdate' ) ;
226
234
}
227
235
} ,
@@ -293,14 +301,28 @@ export const TsModsModule = {
293
301
return updated !== undefined ;
294
302
} ,
295
303
296
- async getActiveGameCacheStatus ( { state, rootState} ) {
304
+ async getActiveGameCacheStatus ( { commit , state, rootState} ) : Promise < string > {
297
305
if ( state . isThunderstoreModListUpdateInProgress ) {
298
306
return "Online mod list is currently updating, please wait for the operation to complete" ;
299
307
}
300
308
301
- return ( await PackageDb . hasEntries ( rootState . activeGame . internalFolderName ) )
302
- ? `${ rootState . activeGame . displayName } has a local copy of online mod list`
303
- : `${ rootState . activeGame . displayName } has no local copy stored` ;
309
+ // Only check the status once, as this is used in the settings
310
+ // where the value is polled on one second intervals.
311
+ if ( state . activeGameCacheStatus === undefined ) {
312
+ let status = '' ;
313
+ try {
314
+ status = ( await PackageDb . hasEntries ( rootState . activeGame . internalFolderName ) )
315
+ ? `${ rootState . activeGame . displayName } has a local copy of online mod list`
316
+ : `${ rootState . activeGame . displayName } has no local copy stored` ;
317
+ } catch ( e ) {
318
+ console . error ( e ) ;
319
+ status = 'Error occurred while checking mod list status' ;
320
+ }
321
+
322
+ commit ( 'setActiveGameCacheStatus' , status ) ;
323
+ }
324
+
325
+ return state . activeGameCacheStatus || 'Unknown status' ;
304
326
} ,
305
327
306
328
async prewarmCache ( { getters, rootGetters} ) {
@@ -324,7 +346,9 @@ export const TsModsModule = {
324
346
try {
325
347
commit ( 'setThunderstoreModListUpdateStatus' , 'Resetting mod list cache...' ) ;
326
348
await PackageDb . resetCommunity ( community ) ;
349
+ commit ( 'setModsLastUpdated' , undefined ) ;
327
350
} finally {
351
+ commit ( 'setActiveGameCacheStatus' , undefined ) ;
328
352
commit ( 'finishThunderstoreModListUpdate' ) ;
329
353
}
330
354
} ,
0 commit comments