Skip to content

Commit 49df270

Browse files
authored
Merge pull request #1677 from ebkr/ignore-cache-vuex
Fix state drift of ignoreCache setting
2 parents 929c6f5 + f775292 commit 49df270

File tree

8 files changed

+25
-22
lines changed

8 files changed

+25
-22
lines changed

src/components/mixins/DownloadMixin.vue

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,6 @@ export default class DownloadMixin extends Vue {
3333
return this.$store.state.modals.isDownloadModModalOpen;
3434
}
3535
36-
get ignoreCache(): boolean {
37-
const settings = this.$store.getters['settings'];
38-
return settings.getContext().global.ignoreCache;
39-
}
40-
4136
get thunderstoreMod(): ThunderstoreMod | null {
4237
return this.$store.state.modals.downloadModModalMod;
4338
}

src/components/profiles-modals/ImportProfileModal.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,7 @@ export default class ImportProfileModal extends mixins(ProfilesMixin) {
246246
const progressCallback = (progress: number|string) => typeof progress === "number"
247247
? this.importPhaseDescription = `Downloading mods: ${Math.floor(progress)}%`
248248
: this.importPhaseDescription = progress;
249-
const settings = this.$store.getters['settings'];
250-
const ignoreCache = settings.getContext().global.ignoreCache;
249+
const ignoreCache = this.$store.state.download.ignoreCache;
251250
const isUpdate = this.importUpdateSelection === 'UPDATE';
252251
253252
try {

src/components/settings-components/SettingsView.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ import CdnProvider from '../../providers/generic/connection/CdnProvider';
170170
'Toggle download cache',
171171
'Downloading a mod will ignore mods stored in the cache. Mods will still be placed in the cache.',
172172
async () => {
173-
return this.settings.getContext().global.ignoreCache
173+
return this.$store.state.download.ignoreCache
174174
? 'Current: cache is disabled'
175175
: 'Current: cache is enabled (recommended)';
176176
},

src/components/views/DownloadModModal.vue

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ import ProfileModList from '../../r2mm/mods/ProfileModList';
7878
public static async downloadSpecific(
7979
profile: Profile,
8080
combo: ThunderstoreCombo,
81-
ignoreCache: boolean,
8281
store: Store<any>
8382
): Promise<void> {
8483
return new Promise(async (resolve, reject) => {
@@ -94,7 +93,7 @@ import ProfileModList from '../../r2mm/mods/ProfileModList';
9493
downloadedMods = await ThunderstoreDownloaderProvider.instance.download(
9594
profile.asImmutableProfile(),
9695
combo,
97-
ignoreCache,
96+
store.state.download.ignoreCache,
9897
(downloadProgress: number, modName: string, status: number, err: R2Error | null) => {
9998
try {
10099
DownloadMixin.downloadProgressCallback(store, assignId, downloadProgress, modName, status, err);
@@ -150,7 +149,7 @@ import ProfileModList from '../../r2mm/mods/ProfileModList';
150149
downloadedMods = await ThunderstoreDownloaderProvider.instance.download(
151150
this.profile.asImmutableProfile(),
152151
tsCombo,
153-
this.ignoreCache,
152+
this.$store.state.download.ignoreCache,
154153
(downloadProgress, modName, status, err) => {
155154
DownloadMixin.downloadProgressCallback(
156155
this.$store,

src/components/views/UpdateAllInstalledModsModal.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,9 @@ export default class UpdateAllInstalledModsModal extends mixins(DownloadMixin)
4848
modsWithUpdates.map(value => `${value.getMod().getName()} (${value.getVersion().getVersionNumber().toString()})`)
4949
);
5050
51+
const ignoreCache = this.$store.state.download.ignoreCache;
5152
this.setIsModProgressModalOpen(true);
52-
ThunderstoreDownloaderProvider.instance.downloadLatestOfAll(modsWithUpdates, this.ignoreCache, (downloadProgress: number, modName: string, status: number, err: R2Error | null) => {
53+
ThunderstoreDownloaderProvider.instance.downloadLatestOfAll(modsWithUpdates, ignoreCache, (downloadProgress: number, modName: string, status: number, err: R2Error | null) => {
5354
try {
5455
if (status === StatusEnum.FAILURE) {
5556
this.setIsModProgressModalOpen(false);

src/pages/Manager.vue

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -484,10 +484,6 @@ import ModalCard from '../components/ModalCard.vue';
484484
this.showLaunchParameterModal = false;
485485
}
486486
487-
toggleIgnoreCache() {
488-
this.settings.setIgnoreCache(!this.settings.getContext().global.ignoreCache);
489-
}
490-
491487
async copyLogToClipboard() {
492488
const fs = FsProvider.instance;
493489
let logOutputPath = "";
@@ -560,7 +556,7 @@ import ModalCard from '../components/ModalCard.vue';
560556
this.copyTroubleshootingInfoToClipboard();
561557
break;
562558
case "ToggleDownloadCache":
563-
this.toggleIgnoreCache();
559+
await this.$store.dispatch('download/toggleIgnoreCache');
564560
break;
565561
case "ValidateSteamInstallation":
566562
this.validateSteamInstallation();
@@ -631,7 +627,6 @@ import ModalCard from '../components/ModalCard.vue';
631627
632628
async created() {
633629
this.launchParametersModel = this.settings.getContext().gameSpecific.launchParameters;
634-
const ignoreCache = this.settings.getContext().global.ignoreCache;
635630
636631
InteractionProvider.instance.hookModInstallProtocol(async (protocolUrl) => {
637632
const game = this.$store.state.activeGame;
@@ -643,7 +638,7 @@ import ModalCard from '../components/ModalCard.vue';
643638
});
644639
return;
645640
}
646-
DownloadModModal.downloadSpecific(this.profile, combo, ignoreCache, this.$store)
641+
DownloadModModal.downloadSpecific(this.profile, combo, this.$store)
647642
.then(async value => {
648643
const modList = await ProfileModList.getModList(this.profile.asImmutableProfile());
649644
if (!(modList instanceof R2Error)) {

src/store/index.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,18 +59,20 @@ export const store = {
5959
return await dispatch('setActiveGame', GameManager.defaultGame);
6060
},
6161

62-
async setActiveGame({commit}: Context, game: Game): Promise<ManagerSettings> {
62+
async setActiveGame({commit, dispatch}: Context, game: Game): Promise<ManagerSettings> {
6363
// Some parts of the code base reads the active game from
6464
// this static class attribute for now. Ideally we wouldn't
6565
// need to track it on two separate places.
6666
GameManager.activeGame = game;
6767
commit('setActiveGame', game);
6868

69+
const settings = await ManagerSettings.getSingleton(game);
70+
commit('setSettings', settings);
71+
commit('download/setIgnoreCacheVuexOnly', settings.getContext().global.ignoreCache);
72+
6973
// Return settings for the new active game. This comes handy
7074
// when accessing settings before user has selected the game
7175
// as the settings-getter might throw a sanity check error.
72-
const settings = await ManagerSettings.getSingleton(game);
73-
commit('setSettings', settings);
7476
return settings;
7577
},
7678

src/store/modules/DownloadModule.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { ActionTree, GetterTree } from "vuex";
22

3+
import ManagerSettings from "../../r2mm/manager/ManagerSettings";
34
import { State as RootState } from "../../store";
45

56
interface DownloadProgress {
@@ -21,6 +22,7 @@ interface UpdateObject {
2122

2223
interface State {
2324
allDownloads: DownloadProgress[],
25+
ignoreCache: boolean,
2426
isModProgressModalOpen: boolean,
2527
}
2628

@@ -32,6 +34,7 @@ export const DownloadModule = {
3234

3335
state: (): State => ({
3436
allDownloads: [],
37+
ignoreCache: false,
3538
isModProgressModalOpen: false,
3639
}),
3740

@@ -49,6 +52,11 @@ export const DownloadModule = {
4952
state.allDownloads = [...state.allDownloads, downloadObject];
5053
return assignId;
5154
},
55+
async toggleIgnoreCache({commit, rootGetters}) {
56+
const settings: ManagerSettings = rootGetters['settings'];
57+
settings.setIgnoreCache(!settings.getContext().global.ignoreCache);
58+
commit('setIgnoreCacheVuexOnly', settings.getContext().global.ignoreCache);
59+
},
5260
},
5361

5462
getters: <GetterTree<State, RootState>>{
@@ -104,6 +112,10 @@ export const DownloadModule = {
104112
newDownloads[index] = {...newDownloads[index], ...update};
105113
state.allDownloads = newDownloads;
106114
},
115+
// Use actions.toggleIngoreCache to store the setting persistently.
116+
setIgnoreCacheVuexOnly(state: State, ignoreCache: boolean) {
117+
state.ignoreCache = ignoreCache;
118+
},
107119
setIsModProgressModalOpen(state: State, isModProgressModalOpen: boolean) {
108120
state.isModProgressModalOpen = isModProgressModalOpen;
109121
}

0 commit comments

Comments
 (0)