From cac09cf032cc8c494da95bf1956ada9b823f5f0b Mon Sep 17 00:00:00 2001 From: MathieuG-P <40181755+Zagrios@users.noreply.github.com> Date: Tue, 1 Oct 2024 20:51:53 +0200 Subject: [PATCH] [chore] remove unnecessary code from progress bar service --- .../local-playlists-list-panel.component.tsx | 10 ++++----- .../pages/settings-page.component.tsx | 4 ++-- src/renderer/services/auto-updater.service.ts | 4 ++-- .../services/bs-mods-manager.service.ts | 12 +++++----- .../oculus-downloader.service.ts | 4 ++-- .../steam-downloader.service.ts | 4 ++-- .../services/bs-version-manager.service.ts | 6 ++--- .../services/maps-downloader.service.ts | 4 ++-- src/renderer/services/maps-manager.service.ts | 8 +++---- .../models-downloader.service.ts | 6 ++--- .../models-manager.service.ts | 6 ++--- .../services/playlist-downloader.service.ts | 10 ++++----- src/renderer/services/progress-bar.service.ts | 22 +++++++++---------- .../services/version-folder-linker.service.ts | 2 +- 14 files changed, 50 insertions(+), 52 deletions(-) diff --git a/src/renderer/components/maps-playlists-panel/playlists/local-playlists-list-panel.component.tsx b/src/renderer/components/maps-playlists-panel/playlists/local-playlists-list-panel.component.tsx index 76e8fcb4..dd7b5d7b 100644 --- a/src/renderer/components/maps-playlists-panel/playlists/local-playlists-list-panel.component.tsx +++ b/src/renderer/components/maps-playlists-panel/playlists/local-playlists-list-panel.component.tsx @@ -151,7 +151,7 @@ export const LocalPlaylistsListPanel = forwardRef( const obs$ = playlistService.exportPlaylists({ version, bpLists: toExport, dest: folderRes.filePaths.at(0), playlistsMaps: mapsToExport }); - progess.show(obs$, true); + progess.show(obs$); const { error } = await tryit(() => lastValueFrom(obs$)); @@ -163,7 +163,7 @@ export const LocalPlaylistsListPanel = forwardRef( notification.notifySuccess({ title: "playlist.playlists-exported-title", desc: exportMaps ? "playlist.playlists-exported-desc" : "playlist.playlists-with-maps-exported-desc", duration: 5000 }); - progess.hide(true); + progess.hide(); }, deletePlaylists: () => { const toDelete = selectedPlaylists$.value?.length ? selectedPlaylists$.value : playlists$.value; @@ -247,7 +247,7 @@ export const LocalPlaylistsListPanel = forwardRef( if(exitCode !== ModalExitCode.COMPLETED){ return; } const progess$ = new BehaviorSubject({ progression: 0 }); - progess.show(progess$, true) + progess.show(progess$) for(const [i, bpList] of enumerate(bpLists)){ @@ -256,7 +256,7 @@ export const LocalPlaylistsListPanel = forwardRef( if(error){ logRenderError("Error occured while deleting playlist", error); notification.notifyError({ title: "playlist.playlist-delete-error-title", desc: "playlist.playlist-delete-error-desc" }); - progess.hide(true); + progess.hide(); return; } @@ -270,7 +270,7 @@ export const LocalPlaylistsListPanel = forwardRef( notification.notifySuccess({ title: "playlist.playlists-deleted-title", desc: "playlist.playlists-deleted-desc", duration: 5000 }); - progess.hide(true); + progess.hide(); }; const openPlaylistDetails = (playlistPath: string) => { diff --git a/src/renderer/pages/settings-page.component.tsx b/src/renderer/pages/settings-page.component.tsx index ae4c4713..18e88002 100644 --- a/src/renderer/pages/settings-page.component.tsx +++ b/src/renderer/pages/settings-page.component.tsx @@ -214,7 +214,7 @@ export function SettingsPage() { lastValueFrom(installationLocationService.setInstallationFolder(fileChooserRes.filePaths[0], true)).then(res => { progressBarService.complete(); - progressBarService.hide(true); + progressBarService.hide(); setInstallationFolder(res); @@ -226,7 +226,7 @@ export function SettingsPage() { }); }).catch((err: BsmException) => { - progressBarService.hide(true); + progressBarService.hide(); if (err?.code === "COPY_TO_SUBPATH") { notificationService.notifyError({ title: "notifications.settings.move-folder.errors.titles.transfer-failed", desc: "notifications.settings.move-folder.errors.descs.COPY_TO_SUBPATH", duration: 10_000 }); diff --git a/src/renderer/services/auto-updater.service.ts b/src/renderer/services/auto-updater.service.ts index 2008b88b..912c7fe6 100644 --- a/src/renderer/services/auto-updater.service.ts +++ b/src/renderer/services/auto-updater.service.ts @@ -49,13 +49,13 @@ export class AutoUpdaterService { public downloadUpdate(): Observable { return new Observable(obs => { const download$ = this.ipcService.sendV2("download-update"); - this.progressService.show(download$, true); + this.progressService.show(download$); const sub = download$.subscribe(obs); return () => { sub.unsubscribe(); - this.progressService.hide(true); + this.progressService.hide(); } }); } diff --git a/src/renderer/services/bs-mods-manager.service.ts b/src/renderer/services/bs-mods-manager.service.ts index 97cecf77..ef449208 100644 --- a/src/renderer/services/bs-mods-manager.service.ts +++ b/src/renderer/services/bs-mods-manager.service.ts @@ -47,7 +47,7 @@ export class BsModsManagerService { return new Observable(obs => { const install$ = this.ipcService.sendV2("install-mods", { mods, version }); - this.progressBar.show(install$.pipe(catchError(() => of({ current: 0, total: 0} as Progression))), true, { paddingLeft: "190px", paddingRight: "190px", bottom: "20px" }); + this.progressBar.show(install$.pipe(catchError(() => of({ current: 0, total: 0} as Progression))), { paddingLeft: "190px", paddingRight: "190px", bottom: "20px" }); const sub = install$.pipe( tap({ @@ -66,7 +66,7 @@ export class BsModsManagerService { return () => { sub.unsubscribe(); - this.progressBar.hide(true); + this.progressBar.hide(); } }); } @@ -78,7 +78,7 @@ export class BsModsManagerService { return new Observable(obs => { const uninstall$ = this.ipcService.sendV2("uninstall-mods", { mods: [mod], version }); - this.progressBar.show(uninstall$.pipe(catchError(() => of({ current: 0, total: 0} as Progression))), true, { paddingLeft: "190px", paddingRight: "190px", bottom: "20px" }); + this.progressBar.show(uninstall$.pipe(catchError(() => of({ current: 0, total: 0} as Progression))), { paddingLeft: "190px", paddingRight: "190px", bottom: "20px" }); const sub = uninstall$.pipe( tap({ @@ -97,7 +97,7 @@ export class BsModsManagerService { return () => { sub.unsubscribe(); - this.progressBar.hide(true); + this.progressBar.hide(); } }); } @@ -109,7 +109,7 @@ export class BsModsManagerService { return new Observable(obs => { const uninstall$ = this.ipcService.sendV2("uninstall-all-mods", version); - this.progressBar.show(uninstall$.pipe(catchError(() => of({ current: 0, total: 0} as Progression))), true, { paddingLeft: "190px", paddingRight: "190px", bottom: "20px" }); + this.progressBar.show(uninstall$.pipe(catchError(() => of({ current: 0, total: 0} as Progression))), { paddingLeft: "190px", paddingRight: "190px", bottom: "20px" }); const sub = uninstall$.pipe( tap({ @@ -128,7 +128,7 @@ export class BsModsManagerService { return () => { sub.unsubscribe(); - this.progressBar.hide(true); + this.progressBar.hide(); } }); diff --git a/src/renderer/services/bs-version-download/oculus-downloader.service.ts b/src/renderer/services/bs-version-download/oculus-downloader.service.ts index 9d2bf4d6..cd0e5a91 100644 --- a/src/renderer/services/bs-version-download/oculus-downloader.service.ts +++ b/src/renderer/services/bs-version-download/oculus-downloader.service.ts @@ -50,7 +50,7 @@ export class OculusDownloaderService extends AbstractBsDownloaderService impleme private handleDownload(download: Observable>, ingoreErrorCodes?: string[]): Observable> { const progress$ = download.pipe(map(progress => (progress.current / progress.total) * 100), catchError(() => of(0))); - this.progressBar.show(progress$, true); + this.progressBar.show(progress$); const subs: Subscription[] = []; @@ -106,7 +106,7 @@ export class OculusDownloaderService extends AbstractBsDownloaderService impleme } return bsVersion; - }).finally(() => this.progressBar.hide(true)); + }).finally(() => this.progressBar.hide()); } public downloadBsVersion(version: BSVersion): Promise { diff --git a/src/renderer/services/bs-version-download/steam-downloader.service.ts b/src/renderer/services/bs-version-download/steam-downloader.service.ts index 313a1e4a..7241b332 100644 --- a/src/renderer/services/bs-version-download/steam-downloader.service.ts +++ b/src/renderer/services/bs-version-download/steam-downloader.service.ts @@ -189,7 +189,7 @@ export class SteamDownloaderService extends AbstractBsDownloaderService implemen return Promise.resolve(); } - this.progressBarService.show(this.downloadProgress$, true); + this.progressBarService.show(this.downloadProgress$); const downloadPromise = (async () => { @@ -225,7 +225,7 @@ export class SteamDownloaderService extends AbstractBsDownloaderService implemen return downloadPromise.then(() => {}).finally(() => { this.downloadProgress$.next(0); - this.progressBarService.hide(true); + this.progressBarService.hide(); }); } diff --git a/src/renderer/services/bs-version-manager.service.ts b/src/renderer/services/bs-version-manager.service.ts index e9d54bb9..d63ffffa 100644 --- a/src/renderer/services/bs-version-manager.service.ts +++ b/src/renderer/services/bs-version-manager.service.ts @@ -125,7 +125,7 @@ export class BSVersionManagerService { return null; }).finally(() => { - this.progressBar.hide(true) + this.progressBar.hide() }); } @@ -167,7 +167,7 @@ export class BSVersionManagerService { obs.error(err) }).finally(() => { this.askInstalledVersions(); - this.progressBar.hide(true); + this.progressBar.hide(); }); return () => { @@ -177,7 +177,7 @@ export class BSVersionManagerService { shareReplay({ bufferSize: 1, refCount: true }) ); - this.progressBar.show(obs$, true); + this.progressBar.show(obs$); return obs$; } diff --git a/src/renderer/services/maps-downloader.service.ts b/src/renderer/services/maps-downloader.service.ts index caa39653..a8af459c 100644 --- a/src/renderer/services/maps-downloader.service.ts +++ b/src/renderer/services/maps-downloader.service.ts @@ -47,7 +47,7 @@ export class MapsDownloaderService { } private async startDownloadMaps() { - this.progressBar.show(this.downloadProgress$, true, this.progressBarStyle); + this.progressBar.show(this.downloadProgress$, this.progressBarStyle); await timer(2000).toPromise(); @@ -64,7 +64,7 @@ export class MapsDownloaderService { await timer(500).toPromise(); this.currentDownload$.next(null); - this.progressBar.hide(true); + this.progressBar.hide(); } private downloadMap(map: BsvMapDetail, version: BSVersion): Observable { diff --git a/src/renderer/services/maps-manager.service.ts b/src/renderer/services/maps-manager.service.ts index 58095d66..a45cff27 100644 --- a/src/renderer/services/maps-manager.service.ts +++ b/src/renderer/services/maps-manager.service.ts @@ -99,10 +99,10 @@ export class MapsManagerService { const progress$ = this.ipcService.sendV2("delete-maps", maps ).pipe(map(progress => (progress.deleted / progress.total) * 100)); if (showProgressBar) { - this.progressBar.show(progress$, true); + this.progressBar.show(progress$); } - progress$.toPromise().finally(() => this.progressBar.hide(true)); + progress$.toPromise().finally(() => this.progressBar.hide()); return progress$ .pipe( @@ -131,7 +131,7 @@ export class MapsManagerService { }) ); - this.progressBar.show(exportProgress$, true); + this.progressBar.show(exportProgress$); await exportProgress$ .toPromise() @@ -142,7 +142,7 @@ export class MapsManagerService { // TODO TRANSLATE this.notifications.notifySuccess({ title: "Export terminé 🎉", duration: 3000 }); this.progressBar.complete(); - this.progressBar.hide(true); + this.progressBar.hide(); }); } diff --git a/src/renderer/services/models-management/models-downloader.service.ts b/src/renderer/services/models-management/models-downloader.service.ts index a8ec3c0c..91922879 100644 --- a/src/renderer/services/models-management/models-downloader.service.ts +++ b/src/renderer/services/models-management/models-downloader.service.ts @@ -53,13 +53,13 @@ export class ModelsDownloaderService { }), startWith({ progression: 0.1, label: download.model.name }) ); - this.progress.show(progress$, true); + this.progress.show(progress$); } const downloaded = await lastValueFrom(download$); this.lastDownload$.next(downloaded.data); - this.progress.hide(true); + this.progress.hide(); this.queue$.next(this.queue$.value.filter(m => m.model.hash !== download.model.hash)); } @@ -127,7 +127,7 @@ export class ModelsDownloaderService { this.progress.complete(); await lastValueFrom(timer(500)); - this.progress.hide(true); + this.progress.hide(); return res; } diff --git a/src/renderer/services/models-management/models-manager.service.ts b/src/renderer/services/models-management/models-manager.service.ts index 48e3eabb..6205b2fa 100644 --- a/src/renderer/services/models-management/models-manager.service.ts +++ b/src/renderer/services/models-management/models-manager.service.ts @@ -123,7 +123,7 @@ export class ModelsManagerService { }) ); - this.progressBar.show(exportProgress$, true); + this.progressBar.show(exportProgress$); lastValueFrom(exportProgress$) .then(() => { @@ -133,7 +133,7 @@ export class ModelsManagerService { this.notifications.notifyError({ title: "notifications.types.error", desc: "notifications.common.msg.error-occurred", duration: 3000 }); }) .finally(() => { - this.progressBar.hide(true); + this.progressBar.hide(); }); } @@ -182,7 +182,7 @@ export class ModelsManagerService { this.notifications.notifyError({ title: "notifications.types.error", desc: "notifications.common.msg.error-occurred", duration: 3000 }); return []; }) - .finally(() => this.progressBar.hide(true)); + .finally(() => this.progressBar.hide()); } public isDeepLinksEnabled(): Promise { diff --git a/src/renderer/services/playlist-downloader.service.ts b/src/renderer/services/playlist-downloader.service.ts index 7fc77631..9e1ddd34 100644 --- a/src/renderer/services/playlist-downloader.service.ts +++ b/src/renderer/services/playlist-downloader.service.ts @@ -57,7 +57,7 @@ export class PlaylistDownloaderService { canShowProgress = !this.progress.isVisible; if (canShowProgress) { - this.progress.show(download$, true); + this.progress.show(download$); } await lastValueFrom(download$.pipe(tap(subscriber))); @@ -68,7 +68,7 @@ export class PlaylistDownloaderService { this._currentDownload$.next(null); this.downloadQueue$.next(this.downloadQueue$.value.filter(qInfo => !equal(qInfo.info.version, info.version) || !equal(qInfo.info.downloadSource, info.downloadSource))); if (canShowProgress) { - this.progress.hide(true); + this.progress.hide(); } }); @@ -115,11 +115,11 @@ export class PlaylistDownloaderService { const download$ = this.ipc.sendV2("one-click-install-playlist", bpListUrl); const progress$ = download$.pipe(map(data => (data.current / data.total) * 100)); - this.progress.show(progress$, true); + this.progress.show(progress$); return download$.pipe(tap({ - error: () => this.progress.hide(true), - complete: () => this.progress.hide(true) + error: () => this.progress.hide(), + complete: () => this.progress.hide() })); } diff --git a/src/renderer/services/progress-bar.service.ts b/src/renderer/services/progress-bar.service.ts index d9f60b4c..6f5376f1 100644 --- a/src/renderer/services/progress-bar.service.ts +++ b/src/renderer/services/progress-bar.service.ts @@ -40,7 +40,7 @@ export class ProgressBarService { lastValueFrom(this.ipcService.sendV2("window.progression", progression)); } - public subscribreTo(obs: Observable) { + private subscribreTo(obs: Observable) { if (this.subscription) { this.unsubscribe(); } @@ -62,16 +62,16 @@ export class ProgressBarService { }); } - public unsubscribe() { + private unsubscribe() { this._progression$.next({ progression: 0 }); this.subscription?.unsubscribe(); this.subscription = null; } - public show(obs?: Observable, unsubscribe?: boolean, style?: CSSProperties) { - if (unsubscribe) { - this.unsubscribe(); - } + public show(obs?: Observable, style?: CSSProperties) { + + this.unsubscribe(); + if (obs) { this.subscribreTo(obs); } @@ -90,7 +90,7 @@ export class ProgressBarService { return { progression: progress, label } as ProgressionInterface; }) ); - this.show(obs, true, style); + this.show(obs, style); } public complete(): void { @@ -98,13 +98,11 @@ export class ProgressBarService { } public open(): void { - this.show(of(0), true, this._style$.value); + this.show(of(0), this._style$.value); } - public hide(unsubscribe = true) { - if (unsubscribe) { - this.unsubscribe(); - } + public hide() { + this.unsubscribe(); this._visible$.next(false); } diff --git a/src/renderer/services/version-folder-linker.service.ts b/src/renderer/services/version-folder-linker.service.ts index 37fc4785..8bcbf5be 100644 --- a/src/renderer/services/version-folder-linker.service.ts +++ b/src/renderer/services/version-folder-linker.service.ts @@ -67,7 +67,7 @@ export class VersionFolderLinkerService { } if (progressOpened) { - this.progress.hide(true); + this.progress.hide(); } const newArr = [...this._queue$.value];