diff --git a/src/components/mixins/UtilityMixin.vue b/src/components/mixins/UtilityMixin.vue index 84e3911b3..3571e19aa 100644 --- a/src/components/mixins/UtilityMixin.vue +++ b/src/components/mixins/UtilityMixin.vue @@ -16,15 +16,6 @@ export default class UtilityMixin extends Vue { } async refreshThunderstoreModList() { - // Don't do background update on index route since the game - // isn't really chosen yet, nor in the splash screen since it - // proactively updates the package list. - const exemptRoutes = ["index", "splash"]; - - if (this.$route.name && exemptRoutes.includes(this.$route.name)) { - return; - } - const response = await ConnectionProvider.instance.getPackages(this.$store.state.activeGame); await this.$store.dispatch("tsMods/updatePersistentCache", response.data); await this.$store.dispatch("tsMods/updateMods"); @@ -39,7 +30,21 @@ export default class UtilityMixin extends Vue { * failure to see how this affects the number of reported errors. */ private async tryRefreshThunderstoreModList() { + // Don't do background update on index route since the game + // isn't really chosen yet, nor in the splash screen since it + // proactively updates the package list. + const exemptRoutes = ["index", "splash"]; + + if (this.$route.name && exemptRoutes.includes(this.$route.name)) { + return; + } + + if (this.$store.state.tsMods.isBackgroundUpdateInProgress) { + return; + } + try { + this.$store.commit("tsMods/startBackgroundUpdate"); await this.refreshThunderstoreModList(); } catch (e) { if (this.tsRefreshFailed) { @@ -49,6 +54,8 @@ export default class UtilityMixin extends Vue { this.tsRefreshFailed = true; return; + } finally { + this.$store.commit("tsMods/finishBackgroundUpdate"); } this.tsRefreshFailed = false; diff --git a/src/components/settings-components/SettingsView.vue b/src/components/settings-components/SettingsView.vue index 5e76b7643..637aead4c 100644 --- a/src/components/settings-components/SettingsView.vue +++ b/src/components/settings-components/SettingsView.vue @@ -78,7 +78,6 @@ import UtilityMixin from '../mixins/UtilityMixin.vue'; private search: string = ''; private managerVersionNumber: VersionNumber = ManagerInformation.VERSION; private searchableSettings: SettingsRow[] = []; - private downloadingThunderstoreModList: boolean = false; get activeGame(): Game { return this.$store.state.activeGame; @@ -299,7 +298,7 @@ import UtilityMixin from '../mixins/UtilityMixin.vue'; 'Refresh online mod list', 'Check for any new mod releases.', async () => { - if (this.downloadingThunderstoreModList) { + if (this.$store.state.tsMods.isBackgroundUpdateInProgress) { return "Checking for new releases"; } if (this.$store.state.tsMods.connectionError.length > 0) { @@ -312,17 +311,19 @@ import UtilityMixin from '../mixins/UtilityMixin.vue'; }, 'fa-exchange-alt', async () => { - if (!this.downloadingThunderstoreModList) { - this.downloadingThunderstoreModList = true; - this.$store.commit("tsMods/setConnectionError", ""); + if (this.$store.state.tsMods.isBackgroundUpdateInProgress) { + return; + } - try { - await this.refreshThunderstoreModList(); - } catch (e) { - this.$store.commit("tsMods/setConnectionError", e); - } finally { - this.downloadingThunderstoreModList = false; - } + this.$store.commit("tsMods/startBackgroundUpdate"); + this.$store.commit("tsMods/setConnectionError", ""); + + try { + await this.refreshThunderstoreModList(); + } catch (e) { + this.$store.commit("tsMods/setConnectionError", e); + } finally { + this.$store.commit("tsMods/finishBackgroundUpdate"); } } ), diff --git a/src/store/modules/TsModsModule.ts b/src/store/modules/TsModsModule.ts index 576bbdd63..6396e8aae 100644 --- a/src/store/modules/TsModsModule.ts +++ b/src/store/modules/TsModsModule.ts @@ -18,6 +18,7 @@ interface State { connectionError: string; deprecated: Map; exclusions?: string[]; + isBackgroundUpdateInProgress: boolean; mods: ThunderstoreMod[]; modsLastUpdated?: Date; } @@ -38,6 +39,8 @@ export const TsModsModule = { deprecated: new Map(), /*** Packages available through API that should be ignored by the manager */ exclusions: [], + /*** Mod list is automatically and periodically updated in the background */ + isBackgroundUpdateInProgress: false, /*** All mods available through API for the current active game */ mods: [], /*** When was the mod list last refreshed from the API? */ @@ -116,6 +119,9 @@ export const TsModsModule = { clearModCache(state) { state.cache.clear(); }, + finishBackgroundUpdate(state) { + state.isBackgroundUpdateInProgress = false; + }, setConnectionError(state, error: string|unknown) { if (typeof error === 'string') { state.connectionError = error; @@ -133,6 +139,9 @@ export const TsModsModule = { setExclusions(state, payload: string[]) { state.exclusions = payload; }, + startBackgroundUpdate(state) { + state.isBackgroundUpdateInProgress = true; + }, updateDeprecated(state, allMods: ThunderstoreMod[]) { state.deprecated = Deprecations.getDeprecatedPackageMap(allMods); }