Merge pull request #307 from Zagrios/bugfix/installing-version-disappear-on-uninstall-another/304

[bugfix] On uninstalling a version, downloading version disappears
This commit is contained in:
MathieuG-P
2023-08-14 16:21:05 +02:00
committed by GitHub
4 changed files with 47 additions and 20 deletions
@@ -11,21 +11,37 @@ import { useThemeColor } from "renderer/hooks/use-theme-color.hook";
import Tippy from "@tippyjs/react";
import { useTranslation } from "renderer/hooks/use-translation.hook";
import { useService } from "renderer/hooks/use-service.hook";
import { BsDownloaderService } from "renderer/services/bs-downloader.service";
import { distinctUntilChanged } from "rxjs";
import equal from "fast-deep-equal";
export function NavBar() {
const bsVersionServoce = useService(BSVersionManagerService);
const versionManager = useService(BSVersionManagerService);
const versionDownloader = useService(BsDownloaderService);
const downloadingVersion = useObservable(versionDownloader.currentBsVersionDownload$.pipe(distinctUntilChanged(equal)));
const installedVersions = useObservable(versionManager.installedVersions$);
const installedVersions = useObservable(bsVersionServoce.installedVersions$);
const color = useThemeColor("first-color");
const t = useTranslation();
function listVersions(){
const versions = Array.isArray(installedVersions) ? [...installedVersions] : [];
if (downloadingVersion){ versions.push(downloadingVersion); }
const sorted = versions.sort((a, b) => +b.ReleaseDate - +a.ReleaseDate);
return BSVersionManagerService.removeDuplicateVersions(sorted);
}
return (
<nav id="nav-bar" className="z-10 flex flex-col h-full max-h-full items-center p-1">
<BsManagerIcon className="relative aspect-square w-16 h-16 mb-3" />
<ol id="versions" className="w-fit max-w-[120px] relative left-[2px] grow overflow-y-hidden scrollbar-track-transparent scrollbar-thin scrollbar-thumb-rounded-full scrollbar-thumb-neutral-900 hover:overflow-y-scroll">
<SharedNavBarItem />
<NavBarSpliter />
{installedVersions?.map(version => (
{listVersions().map(version => (
<BsVersionItem key={JSON.stringify(version)} version={version} />
))}
</ol>
+2 -12
View File
@@ -1,6 +1,6 @@
import { DownloadInfo } from "main/services/bs-installer.service";
import { BehaviorSubject, Observable, ReplaySubject, Subscription, lastValueFrom, throwError } from "rxjs";
import { distinctUntilChanged, filter, map, share, take, tap, throttleTime } from "rxjs/operators";
import { filter, map, share, take, tap, throttleTime } from "rxjs/operators";
import { BSVersion } from "shared/bs-version.interface";
import { AuthUserService } from "./auth-user.service";
import { BSVersionManagerService } from "./bs-version-manager.service";
@@ -12,7 +12,6 @@ import { LoginModal } from "renderer/components/modal/modal-types/login-modal.co
import { GuardModal } from "renderer/components/modal/modal-types/guard-modal.component";
import { LinkOpenerService } from "./link-opener.service";
import { DepotDownloaderErrorEvent, DepotDownloaderEvent, DepotDownloaderEventType, DepotDownloaderInfoEvent, DepotDownloaderWarningEvent } from "../../shared/models/depot-downloader.model";
import equal from "fast-deep-equal";
import { SteamMobileApproveModal } from "renderer/components/modal/modal-types/steam-mobile-approve-modal.component";
export class BsDownloaderService {
@@ -45,15 +44,6 @@ export class BsDownloaderService {
this.progressBarService = ProgressBarService.getInstance();
this.notificationService = NotificationService.getInstance();
this.linkOpener = LinkOpenerService.getInstance();
this.currentBsVersionDownload$.pipe(distinctUntilChanged(equal)).subscribe(version => {
if(version) {
this.bsVersionManager.setInstalledVersions([...this.bsVersionManager.installedVersions$.value, version ]);
}
else {
this.bsVersionManager.askInstalledVersions();
}
});
}
public isDotNet6Installed(): Promise<boolean> {
@@ -281,7 +271,7 @@ export class BsDownloaderService {
this.currentBsVersionDownload$.next(null);
this.progressBarService.hide(true);
this.isVerification$.next(false);
this.bsVersionManager.askAvailableVersions();
this.bsVersionManager.askInstalledVersions();
});
}
@@ -5,6 +5,7 @@ import { ModalExitCode, ModalService } from "./modale.service";
import { NotificationService } from "./notification.service";
import { ProgressBarService } from "./progress-bar.service";
import { EditVersionModal } from "renderer/components/modal/modal-types/edit-version-modal.component";
import { swapElements } from "shared/helpers/array.helpers";
export class BSVersionManagerService {
private static instance: BSVersionManagerService;
@@ -33,17 +34,19 @@ export class BSVersionManagerService {
}
public setInstalledVersions(versions: BSVersion[]) {
const sorted: BSVersion[] = [...versions].sort((a, b) => +b.ReleaseDate - +a.ReleaseDate);
const sorted: BSVersion[] = versions.sort((a, b) => +b.ReleaseDate - +a.ReleaseDate);
const steamIndex = sorted.findIndex(v => v.steam);
const oculusIndex = sorted.findIndex(v => v.oculus);
if (steamIndex > 0) {
[sorted[0], sorted[steamIndex]] = [sorted[steamIndex], sorted[0]];
swapElements(steamIndex, 0, sorted);
}
if (oculusIndex > 0) {
[sorted[steamIndex > 0 ? 1 : 0], sorted[steamIndex]] = [sorted[steamIndex], sorted[steamIndex > 0 ? 1 : 0]];
swapElements(oculusIndex, steamIndex >= 0 ? 1 : 0, sorted);
}
const cleanedSort = [...new Map(sorted.map(version => [`${version.BSVersion}-${version.name}-${version.steam}-${version.oculus}`, version])).values()];
this.installedVersions$.next(cleanedSort);
this.installedVersions$.next(BSVersionManagerService.removeDuplicateVersions(sorted));
}
public getInstalledVersions(): BSVersion[] {
@@ -119,4 +122,17 @@ export class BSVersionManagerService {
public getVersionPath(version: BSVersion): Observable<string> {
return this.ipcService.sendV2("get-version-full-path", { args: version });
}
public static removeDuplicateVersions(versions: BSVersion[]): BSVersion[] {
return Array.from(new Map(versions.map(version => ([
JSON.stringify([
version.BSVersion,
version.BSManifest,
version.name,
version.steam,
version.oculus
]),
version
]))).values());
}
}
+5
View File
@@ -5,3 +5,8 @@ export function splitIntoChunk<T = unknown>(arr: T[], chunkSize: number): T[][]
}
return resArr;
}
export function swapElements<T = unknown>(from: number, to: number, arr: T[]): T[] {
[arr[from], arr[to]] = [arr[to], arr[from]];
return arr;
}