[chore] remove unnecessary code from progress bar service

This commit is contained in:
MathieuG-P
2024-10-01 20:51:53 +02:00
parent db5af48250
commit cac09cf032
14 changed files with 50 additions and 52 deletions
@@ -151,7 +151,7 @@ export const LocalPlaylistsListPanel = forwardRef<LocalPlaylistsListRef, Props>(
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<LocalPlaylistsListRef, Props>(
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<LocalPlaylistsListRef, Props>(
if(exitCode !== ModalExitCode.COMPLETED){ return; }
const progess$ = new BehaviorSubject<ProgressionInterface>({ progression: 0 });
progess.show(progess$, true)
progess.show(progess$)
for(const [i, bpList] of enumerate(bpLists)){
@@ -256,7 +256,7 @@ export const LocalPlaylistsListPanel = forwardRef<LocalPlaylistsListRef, Props>(
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<LocalPlaylistsListRef, Props>(
notification.notifySuccess({ title: "playlist.playlists-deleted-title", desc: "playlist.playlists-deleted-desc", duration: 5000 });
progess.hide(true);
progess.hide();
};
const openPlaylistDetails = (playlistPath: string) => {
@@ -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 });
@@ -49,13 +49,13 @@ export class AutoUpdaterService {
public downloadUpdate(): Observable<Progression> {
return new Observable<Progression>(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();
}
});
}
@@ -47,7 +47,7 @@ export class BsModsManagerService {
return new Observable<Progression>(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<Progression>(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<Progression>(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();
}
});
@@ -50,7 +50,7 @@ export class OculusDownloaderService extends AbstractBsDownloaderService impleme
private handleDownload(download: Observable<Progression<BSVersion>>, ingoreErrorCodes?: string[]): Observable<Progression<BSVersion>> {
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<BSVersion> {
@@ -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();
});
}
@@ -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$;
}
@@ -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<BsmLocalMap> {
@@ -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();
});
}
@@ -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;
}
@@ -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<boolean> {
@@ -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()
}));
}
+10 -12
View File
@@ -40,7 +40,7 @@ export class ProgressBarService {
lastValueFrom(this.ipcService.sendV2("window.progression", progression));
}
public subscribreTo(obs: Observable<ProgressionInterface | number | Progression>) {
private subscribreTo(obs: Observable<ProgressionInterface | number | Progression>) {
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<ProgressionInterface | number | Progression>, unsubscribe?: boolean, style?: CSSProperties) {
if (unsubscribe) {
this.unsubscribe();
}
public show(obs?: Observable<ProgressionInterface | number | Progression>, 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);
}
@@ -67,7 +67,7 @@ export class VersionFolderLinkerService {
}
if (progressOpened) {
this.progress.hide(true);
this.progress.hide();
}
const newArr = [...this._queue$.value];