Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Improve performance of Manager.setAllModsEnabled #1191

Merged
merged 1 commit into from
Feb 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 35 additions & 19 deletions src/pages/Manager.vue
Original file line number Diff line number Diff line change
Expand Up @@ -499,30 +499,46 @@ import CategoryFilterModal from '../components/modals/CategoryFilterModal.vue';
}

async setAllModsEnabled(enabled: boolean) {
for (const mod of this.localModList) {
let profileErr: R2Error | void;
if (enabled) {
profileErr = await ProfileInstallerProvider.instance.enableMod(mod, this.contextProfile!);
} else {
profileErr = await ProfileInstallerProvider.instance.disableMod(mod, this.contextProfile!);
}
if (profileErr instanceof R2Error) {
this.showError(profileErr);
continue;
}
const update: ManifestV2[] | R2Error = await ProfileModList.updateMod(mod, this.contextProfile!, async (updatingMod: ManifestV2) => {
let lastSuccessfulUpdate: ManifestV2[] = [];

try {
for (const mod of this.localModList) {
if (mod.isEnabled() === enabled) {
continue;
}

let profileErr: R2Error | void;
if (enabled) {
updatingMod.enable();
profileErr = await ProfileInstallerProvider.instance.enableMod(mod, this.contextProfile!);
} else {
updatingMod.disable();
profileErr = await ProfileInstallerProvider.instance.disableMod(mod, this.contextProfile!);
}
});
if (update instanceof R2Error) {
this.showError(update);
continue;
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();
}
});
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));
} finally {
if (lastSuccessfulUpdate.length) {
await this.$store.dispatch("updateModList", lastSuccessfulUpdate);
}
await this.$store.dispatch("updateModList", update);
}

await this.$router.push({name: "manager.installed"});
}

Expand Down
Loading