Skip to content

Commit

Permalink
Reduce the likelihood of state management bugs
Browse files Browse the repository at this point in the history
Make sure the profile mod list is refreshed with the latest information
even if the uninstall logic exits midway.
  • Loading branch information
MythicManiac committed Jan 22, 2024
1 parent 0a5b1eb commit b64c89c
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/components/views/LocalModList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ import SearchUtils from '../../utils/SearchUtils';
return Dependants.getDependencyList(mod, this.modifiableModList);
}
async performUninstallMod(mod: ManifestV2, updateModList=true): Promise<R2Error | void> {
async performUninstallMod(mod: ManifestV2, updateModList=true): Promise<ManifestV2[] | R2Error> {
const uninstallError: R2Error | null = await ProfileInstallerProvider.instance.uninstallMod(mod, this.contextProfile!);
if (uninstallError instanceof R2Error) {
// Uninstall failed
Expand All @@ -405,6 +405,7 @@ import SearchUtils from '../../utils/SearchUtils';
if (updateModList) {
await this.updateModListAfterChange(modList);
}
return modList;
}
async disableMod(vueMod: any) {
Expand Down Expand Up @@ -448,6 +449,7 @@ import SearchUtils from '../../utils/SearchUtils';
async uninstallMod(vueMod: any) {
let mod: ManifestV2 = new ManifestV2().fromReactive(vueMod);
let lastSuccess: ManifestV2[] | null = null;
try {
for (const dependant of Dependants.getDependantList(mod, this.modifiableModList)) {
this.modBeingUninstalled = dependant.getName();
Expand All @@ -456,6 +458,8 @@ import SearchUtils from '../../utils/SearchUtils';
this.$emit('error', result);
this.modBeingUninstalled = null;
return;
} else {
lastSuccess = result;
}
}
this.modBeingUninstalled = mod.getName();
Expand All @@ -464,16 +468,21 @@ import SearchUtils from '../../utils/SearchUtils';
this.$emit('error', result);
this.modBeingUninstalled = null;
return;
} else {
lastSuccess = result;
}
} catch (e) {
// Failed to uninstall mod.
const err: Error = e as Error;
this.$emit('error', err);
this.modBeingUninstalled = null;
LoggerProvider.instance.Log(LogSeverity.ACTION_STOPPED, `${err.name}\n-> ${err.message}`);
} finally {
this.modBeingUninstalled = null;
if (lastSuccess) {
await this.updateModListAfterChange(lastSuccess);
}
}
this.selectedManifestMod = null;
this.modBeingUninstalled = null;
const result: ManifestV2[] | R2Error = await ProfileModList.getModList(this.contextProfile!);
if (result instanceof R2Error) {
this.$emit('error', result);
Expand Down

0 comments on commit b64c89c

Please sign in to comment.