Skip to content

Commit

Permalink
Simplify Manager.setAllModsEnabled
Browse files Browse the repository at this point in the history
Now that the same method is no longer used to disable mods too, it can
be cleaned up quite nicely.

The whole implementation will end up being replaced with one that's
located in the Vuex store, like the disabling counterpart, but it's
beyond the scope of this PR.
  • Loading branch information
anttimaki committed Feb 15, 2024
1 parent 033c3fe commit 5fb93a1
Showing 1 changed file with 6 additions and 18 deletions.
24 changes: 6 additions & 18 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 @@ -625,7 +613,7 @@ import CategoryFilterModal from '../components/modals/CategoryFilterModal.vue';
this.settings = (() => this.settings)();
break;
case "EnableAll":
this.setAllModsEnabled(true);
this.setAllModsEnabled();
break;
case "DisableAll":
await this.$store.dispatch(
Expand Down

0 comments on commit 5fb93a1

Please sign in to comment.