Skip to content

Commit

Permalink
Merge pull request #1219 from ebkr/disable-all-setting
Browse files Browse the repository at this point in the history
Use Vuex when disabling all mods from settings page
  • Loading branch information
anttimaki authored Feb 22, 2024
2 parents 54bcab7 + 59da3bf commit 0ab6a03
Showing 1 changed file with 12 additions and 20 deletions.
32 changes: 12 additions & 20 deletions src/pages/Manager.vue
Original file line number Diff line number Diff line change
Expand Up @@ -499,41 +499,29 @@ import CategoryFilterModal from '../components/modals/CategoryFilterModal.vue';
}
}
async setAllModsEnabled(enabled: boolean) {
async setAllModsEnabled() {
let lastSuccessfulUpdate: ManifestV2[] = [];
try {
for (const mod of this.localModList) {
if (mod.isEnabled() === enabled) {
if (mod.isEnabled()) {
continue;
}
let profileErr: R2Error | void;
if (enabled) {
profileErr = await ProfileInstallerProvider.instance.enableMod(mod, this.contextProfile!);
} else {
profileErr = await ProfileInstallerProvider.instance.disableMod(mod, this.contextProfile!);
}
const profileErr = await ProfileInstallerProvider.instance.enableMod(mod, this.contextProfile!);
if (profileErr instanceof R2Error) {
this.showError(profileErr);
continue;
}
const update: ManifestV2[] | R2Error = await ProfileModList.updateMod(mod, this.contextProfile!, async (updatingMod: ManifestV2) => {
if (enabled) {
updatingMod.enable();
} else {
updatingMod.disable();
}
});
const update = await ProfileModList.updateMod(mod, this.contextProfile!, async (mod) => mod.enable());
if (update instanceof R2Error) {
this.showError(update);
} else {
lastSuccessfulUpdate = update;
}
}
} catch (e) {
const name = `Error ${enabled ? "enabling" : "disabling"} mods`;
this.showError(R2Error.fromThrownValue(e, name));
this.showError(R2Error.fromThrownValue(e, "Error enabling mods"));
} finally {
if (lastSuccessfulUpdate.length) {
await this.$store.dispatch("updateModList", lastSuccessfulUpdate);
Expand Down Expand Up @@ -572,7 +560,7 @@ import CategoryFilterModal from '../components/modals/CategoryFilterModal.vue';
});
}
handleSettingsCallbacks(invokedSetting: any) {
async handleSettingsCallbacks(invokedSetting: any) {
switch(invokedSetting) {
case "BrowseDataFolder":
this.browseDataFolder();
Expand Down Expand Up @@ -625,10 +613,14 @@ import CategoryFilterModal from '../components/modals/CategoryFilterModal.vue';
this.settings = (() => this.settings)();
break;
case "EnableAll":
this.setAllModsEnabled(true);
await this.setAllModsEnabled();
break;
case "DisableAll":
this.setAllModsEnabled(false);
await this.$store.dispatch(
"profile/disableModsFromActiveProfile",
{mods: this.$store.state.localModList}
);
await this.$router.push({name: "manager.installed"});
break;
case "UpdateAllMods":
this.$store.commit("openUpdateAllModsModal");
Expand Down

0 comments on commit 0ab6a03

Please sign in to comment.