From 59da3bf26de2593d8f7d3d35deebcc5363e8b2c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antti=20M=C3=A4ki?= Date: Thu, 15 Feb 2024 17:33:48 +0200 Subject: [PATCH] Simplify Manager.setAllModsEnabled 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. --- src/pages/Manager.vue | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/src/pages/Manager.vue b/src/pages/Manager.vue index 82a92162..54002222 100644 --- a/src/pages/Manager.vue +++ b/src/pages/Manager.vue @@ -499,32 +499,21 @@ 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 { @@ -532,8 +521,7 @@ import CategoryFilterModal from '../components/modals/CategoryFilterModal.vue'; } } } 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); @@ -625,7 +613,7 @@ import CategoryFilterModal from '../components/modals/CategoryFilterModal.vue'; this.settings = (() => this.settings)(); break; case "EnableAll": - this.setAllModsEnabled(true); + await this.setAllModsEnabled(); break; case "DisableAll": await this.$store.dispatch(