[bugfix] Fix uninstall mod error (#862)

This commit is contained in:
MathieuG-P
2025-04-25 14:42:45 +02:00
committed by GitHub
parent 79be1a842c
commit faf6c0f121
2 changed files with 20 additions and 22 deletions
@@ -44,7 +44,7 @@ export class BsModsManagerService {
private async getModFromHash(hash: string): Promise<BbmModVersion | undefined> {
const mod: BbmModVersion | undefined = await this.beatModsApi.getModByHash(hash)
.catch((error) => {
.catch((error): undefined => {
log.warn("Could not get mod with hash", hash, "cause", error?.message);
return undefined;
});
@@ -122,7 +122,7 @@ export class BsModsManagerService {
return undefined;
}
const injectorMd5 = await md5File(injectorPath);
return this.beatModsApi.getModByHash(injectorMd5).catch((error) => {
return this.beatModsApi.getModByHash(injectorMd5).catch((error): undefined => {
log.error("Could not get bsipa mod", error?.message);
return undefined;
});
@@ -340,11 +340,22 @@ export class BsModsManagerService {
const versionPath = await this.bsLocalService.getVersionPath(version);
const promises = mod.version.contentHashes.map(async content => {
return Promise.all([
deleteFile(path.join(versionPath, content.path)),
deleteFile(path.join(versionPath, "IPA", "Pending", content.path))
]);
const promises: Promise<void>[] = mod.version.contentHashes.map(async content => {
return (async () => {
const modPath = path.join(versionPath, content.path);
if(pathExistsSync(modPath)){
log.info("Deleting mod", modPath);
await deleteFile(modPath);
}
const pendingPath = path.join(versionPath, "IPA", "Pending", content.path);
if(pathExistsSync(pendingPath)){
log.info("Deleting pending mod", pendingPath);
return deleteFile(pendingPath);
}
log.warn("Mod file not found in", versionPath, "or pending folder", pendingPath);
})() ;
});
await Promise.all(promises);
@@ -1,9 +1,8 @@
import { BsmButton } from "renderer/components/shared/bsm-button.component";
import { BsmCheckbox } from "renderer/components/shared/bsm-checkbox.component";
import { BbmCategories, BbmFullMod } from "shared/models/mods/mod.interface";
import { CSSProperties, MouseEvent, useMemo, useRef } from "react";
import { CSSProperties, MouseEvent, useMemo } from "react";
import { useThemeColor } from "renderer/hooks/use-theme-color.hook";
import useDoubleClick from "use-double-click";
import { useOnUpdate } from "renderer/hooks/use-on-update.hook";
import striptags from "striptags";
import { safeGt } from "shared/helpers/semver.helpers";
@@ -88,17 +87,9 @@ function FileSizeText({ fileSize, wantInfoStyle }: Readonly<FileSizeProps>) {
export function ModItem({ className, mod, installedVersion, isDependency, isSelected, onChange, wantInfo, onWantInfo, disabled, onUninstall }: Props) {
const themeColor = useThemeColor("second-color");
const clickRef = useRef();
const isChecked = useMemo(() => isDependency || isSelected || mod.mod.category === BbmCategories.Core, [isDependency, isSelected, mod.mod.category]);
useDoubleClick({
onSingleClick: e => handleWantInfo(e),
onDoubleClick: e => handleOnChange(e),
ref: clickRef,
latency: 175,
});
useOnUpdate(() => {
onChange(isChecked);
}, [isChecked]);
@@ -110,13 +101,9 @@ export function ModItem({ className, mod, installedVersion, isDependency, isSele
e.preventDefault();
onWantInfo(mod);
};
const handleOnChange = (e: MouseEvent) => {
e.preventDefault();
onChange(!isChecked);
};
return (
<li ref={clickRef} className={`${className} group`}>
<li className={`${className} group`} onClick={handleWantInfo}>
<div className="h-full flex items-center justify-center p-1.5 px-4 rounded-l-md bg-inherit ml-3 border-2 border-r-0 z-[1] group-hover:brightness-90" style={wantInfoStyle}>
<BsmCheckbox className="size-[18px] aspect-square z-[1] relative bg-inherit" onChange={() => onChange(!isChecked)} disabled={mod.mod.category === BbmCategories.Core || isDependency || disabled} checked={isChecked} />
</div>