From a2d0ab96780ab242e9a52df28e9629e5b40a34d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antti=20M=C3=A4ki?= Date: Fri, 9 Feb 2024 17:19:06 +0200 Subject: [PATCH] LocalModCard: don't delegate mod disabling to LocalModList LocalModCard now disables mods without dependants internally, and delegates mods with dependants to DisableModModal, effectively cutting out the middleman LocalModList. --- src/components/views/LocalModList.vue | 32 +------------------ .../views/LocalModList/LocalModCard.vue | 24 ++++++++++++-- 2 files changed, 23 insertions(+), 33 deletions(-) diff --git a/src/components/views/LocalModList.vue b/src/components/views/LocalModList.vue index c7ddafc81..643c22fe1 100644 --- a/src/components/views/LocalModList.vue +++ b/src/components/views/LocalModList.vue @@ -32,7 +32,7 @@ v-for='(mod, index) in draggableList' :key="`local-${mod.getName()}-${profileName}-${index}-${cardExpanded}`" :mod="mod" - @disableMod="disableModRequireConfirmation" + @error="emitError" @enableMod="enableMod" @uninstallMod="uninstallModRequireConfirmation" @updateMod="updateMod" @@ -158,26 +158,6 @@ import SearchAndSort from './LocalModList/SearchAndSort.vue'; return modList; } - async performDisable(mods: ManifestV2[]): Promise { - for (let mod of mods) { - const disableErr: R2Error | void = await ProfileInstallerProvider.instance.disableMod(mod, this.contextProfile!); - if (disableErr instanceof R2Error) { - // Failed to disable - this.$emit('error', disableErr); - return disableErr; - } - } - const updatedList = await ProfileModList.updateMods(mods, this.contextProfile!, (updatingMod: ManifestV2) => { - updatingMod.disable(); - }); - if (updatedList instanceof R2Error) { - // Failed to update mod list. - this.$emit('error', updatedList); - return updatedList; - } - await this.updateModListAfterChange(updatedList); - } - async uninstallModWithDependents(mod: ManifestV2) { await this.uninstallMods([...this.getDependantList(mod), mod]); } @@ -234,16 +214,6 @@ import SearchAndSort from './LocalModList/SearchAndSort.vue'; } } - disableModRequireConfirmation(mod: ManifestV2) { - for (const value of this.getDependantList(mod)) { - if (value.isEnabled()) { - this.$store.commit('openDisableModModal', mod); - return; - } - } - this.performDisable([mod]); - } - viewDependencyList(mod: ManifestV2) { this.showDependencyList(mod, DependencyListDisplayType.VIEW); } diff --git a/src/components/views/LocalModList/LocalModCard.vue b/src/components/views/LocalModList/LocalModCard.vue index 193e68d40..4f352ff95 100644 --- a/src/components/views/LocalModList/LocalModCard.vue +++ b/src/components/views/LocalModList/LocalModCard.vue @@ -3,6 +3,8 @@ import { Vue, Component, Prop, Watch } from 'vue-property-decorator'; import { ExpandableCard, Link } from '../../all'; import DonateButton from '../../buttons/DonateButton.vue'; import ManifestV2 from '../../../model/ManifestV2'; +import LoggerProvider, { LogSeverity } from '../../../providers/ror2/logging/LoggerProvider'; +import Dependants from '../../../r2mm/mods/Dependants'; import ModBridge from '../../../r2mm/mods/ModBridge'; @Component({ @@ -73,8 +75,26 @@ export default class LocalModCard extends Vue { ); } - disableMod() { - this.$emit('disableMod', this.mod); + async disableMod() { + const dependants = Dependants.getDependantList(this.mod, this.$store.state.localModList); + + for (const mod of dependants) { + if (mod.isEnabled()) { + this.$store.commit('openDisableModModal', this.mod); + return; + } + } + + try { + await this.$store.dispatch( + 'profile/disableModsFromActiveProfile', + { mods: [this.mod] } + ); + } catch (e) { + this.$emit('error', e); + const err: Error = e as Error; + LoggerProvider.instance.Log(LogSeverity.ACTION_STOPPED, `${err.name}\n-> ${err.message}`); + } } enableMod(mod: ManifestV2) {