Skip to content

Commit

Permalink
fix for an error when auto-re-enabling a mod that's changed while the…
Browse files Browse the repository at this point in the history
… manager is running
  • Loading branch information
Shazbot committed Jun 8, 2023
1 parent 106fd44 commit f7e0ab0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "wh3mm",
"productName": "wh3mm",
"version": "1.37.0",
"version": "1.37.1",
"description": "WH3 Mod Manager",
"main": ".webpack/main",
"scripts": {
Expand Down
34 changes: 22 additions & 12 deletions src/appSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
withoutDataAndContentDuplicates,
} from "./modsHelpers";

// these var are outside the state, if we're changing them inside a reducer make sure it's done inside a timeout
// if a enabled mod was removed it's possible it was updated, re-enabled it then
let removedEnabledModPaths: string[] = [];
const removedModsCategories: Record<string, string[]> = {};
Expand Down Expand Up @@ -209,30 +210,35 @@ const appSlice = createSlice({

if (removedEnabledModPaths.find((path) => path === mod.path)) {
mod.isEnabled = true;
removedEnabledModPaths = removedEnabledModPaths.filter((pathOfRemoved) => pathOfRemoved != mod.path);
setTimeout(() => {
removedEnabledModPaths = removedEnabledModPaths.filter(
(pathOfRemoved) => pathOfRemoved != mod.path
);
}, 1);
}

if (removedModsCategories[mod.path]) {
mod.categories = removedModsCategories[mod.path];
delete removedModsCategories[mod.path];
setTimeout(() => {
delete removedModsCategories[mod.path];
}, 1);
}

if (mod.isInData && dataModsToEnableByName.find((nameOfToEnable) => nameOfToEnable === mod.name)) {
mod.isEnabled = true;
dataModsToEnableByName.splice(
dataModsToEnableByName.findIndex((nameOfToEnable) => nameOfToEnable === mod.name),
1
);
}

setTimeout(() => {
dataModsToEnableByName.splice(
dataModsToEnableByName.findIndex((nameOfToEnable) => nameOfToEnable === mod.name),
1
);
}, 1);
}
if (state.dataFromConfig?.currentPreset.mods.find((iterMod) => iterMod.path == mod.path)?.isEnabled) {
mod.isEnabled = true;
}

if (state.newMergedPacks.some((mergedPack) => mergedPack.path == mod.path)) {
mod.isEnabled = true;
}

if (state.alwaysEnabledMods.some((iterMod) => iterMod.name == mod.name)) {
mod.isEnabled = true;
}
Expand Down Expand Up @@ -275,9 +281,13 @@ const appSlice = createSlice({
}

if (!dataMod && removedMod.isEnabled) {
removedEnabledModPaths.push(removedMod.path);
setTimeout(() => {
removedEnabledModPaths.push(removedMod.path);
}, 1);
}
removedModsCategories[removedMod.path] = removedMod.categories ?? [];
setTimeout(() => {
removedModsCategories[removedMod.path] = removedMod.categories ?? [];
}, 1);

state.currentPreset.mods = state.currentPreset.mods.filter((iterMod) => iterMod.path !== modPath);
state.allMods = state.allMods.filter((iterMod) => iterMod.path !== modPath);
Expand Down

0 comments on commit f7e0ab0

Please sign in to comment.