mirror of
https://github.com/Zagrios/bs-manager.git
synced 2026-07-03 14:08:25 +02:00
can now export maps of a bs version
This commit is contained in:
@@ -82,11 +82,8 @@ export class BsDownloaderService{
|
||||
return this.ipcService.send<boolean>("bs-download.kill");
|
||||
}
|
||||
|
||||
public async download(bsVersion: BSVersion, isVerification?: boolean, isFirstCall: boolean = true): Promise<IpcResponse<DownloadEvent>>{
|
||||
if(isFirstCall && this.progressBarService.isVisible){
|
||||
this.notificationService.notifyError({title: "notifications.shared.errors.titles.operation-running", desc: "notifications.shared.errors.msg.operation-running", duration: 3000});
|
||||
return {success: false};
|
||||
}
|
||||
public async download(bsVersion: BSVersion, isVerification?: boolean, isFirstCall = true): Promise<IpcResponse<DownloadEvent>>{
|
||||
if(isFirstCall && !this.progressBarService.require()){ return {success: false}; }
|
||||
|
||||
this.progressBarService.show(this.downloadProgress$);
|
||||
this._isVerification = !!isVerification;
|
||||
|
||||
@@ -88,10 +88,7 @@ export class BSVersionManagerService {
|
||||
}
|
||||
|
||||
public async cloneVersion(version: BSVersion): Promise<BSVersion>{
|
||||
if(this.progressBarService.isVisible){
|
||||
this.notificationService.notifyError({title: "notifications.shared.errors.titles.operation-running", desc: "notifications.shared.errors.msg.operation-running", duration: 3000});
|
||||
return null;
|
||||
}
|
||||
if(!this.progressBarService.require()){ return null; }
|
||||
const modalRes = await this.modalService.openModal<{name: string, color: string}>(ModalType.CLONE_VERSION, version);
|
||||
if(modalRes.exitCode !== ModalExitCode.COMPLETED){ return null; }
|
||||
if(modalRes.data.name?.length < 2){ return null; }
|
||||
|
||||
@@ -16,7 +16,7 @@ export class IpcService {
|
||||
this.channelObservables = new Map<string, Observable<IpcResponse<unknown>>>();
|
||||
}
|
||||
|
||||
public send<T>(channel: string, request?: IpcRequest<any>): Promise<IpcResponse<T>>{
|
||||
public send<T, U = unknown>(channel: string, request?: IpcRequest<U>): Promise<IpcResponse<T>>{
|
||||
if(!request){ request = {args: null, responceChannel: null}; }
|
||||
if(!request.responceChannel){ request.responceChannel = `${channel}_responce_${new Date().getTime()}`; }
|
||||
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
import { BSVersion } from "shared/bs-version.interface";
|
||||
import { OpenSaveDialogOption } from "shared/models/ipc";
|
||||
import { ExportVersionMapsOption } from "shared/models/maps/export-version-maps.model";
|
||||
import { IpcService } from "./ipc.service";
|
||||
import { NotificationService } from "./notification.service";
|
||||
import { ProgressBarService } from "./progress-bar.service";
|
||||
|
||||
export class MapService {
|
||||
|
||||
private static instance: MapService;
|
||||
|
||||
private readonly ipcService: IpcService;
|
||||
private readonly progressService: ProgressBarService;
|
||||
private readonly notificationService: NotificationService;
|
||||
|
||||
public static getInstance(): MapService{
|
||||
if(!MapService.instance){ MapService.instance = new MapService(); }
|
||||
return MapService.instance;
|
||||
}
|
||||
|
||||
private constructor(){
|
||||
this.ipcService = IpcService.getInstance();
|
||||
this.notificationService = NotificationService.getInstance();
|
||||
this.progressService = ProgressBarService.getInstance();
|
||||
}
|
||||
|
||||
public async exportVersionMaps(version: BSVersion): Promise<void>{
|
||||
if(!this.progressService.require()){ return; }
|
||||
|
||||
const resFile = await this.ipcService.send<string, OpenSaveDialogOption>("save-file", {args: {
|
||||
filename: `${version.BSVersion} Maps`,
|
||||
filters: [{name: "zip", extensions: ["zip"]}]
|
||||
}});
|
||||
|
||||
if(!resFile.success){ return; }
|
||||
|
||||
this.progressService.showFake(.008);
|
||||
|
||||
const resExport = await this.ipcService.send<string, ExportVersionMapsOption>("map.export-version", {args: {version, path: resFile.data}});
|
||||
if(!resExport.success && resExport.error.title){
|
||||
const {title, msg} = resExport.error;
|
||||
this.notificationService.notifyError({title, desc: msg});
|
||||
}
|
||||
else {
|
||||
this.notificationService.notifySuccess({title: "Export terminé 🎉", duration: 3000});
|
||||
}
|
||||
this.progressService.complete();
|
||||
this.progressService.hide(true);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -17,7 +17,7 @@ export class NotificationService{
|
||||
}
|
||||
|
||||
public notify(notification: Notification): Promise<NotificationResult|string>{
|
||||
let resovableNotification: ResolvableNotification = {id: uuidv4(), notification: notification, resolver: null };
|
||||
const resovableNotification: ResolvableNotification = {id: uuidv4(), notification, resolver: null };
|
||||
const promise = new Promise<NotificationResult|string>(resolve => {
|
||||
resovableNotification.resolver = resolve;
|
||||
setTimeout(() => resolve(NotificationResult.NO_CHOICE), notification.duration || 7000);
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
import { distinctUntilChanged, map } from "rxjs/operators";
|
||||
import { BehaviorSubject, Observable, Subscription, timer } from "rxjs";
|
||||
import { IpcService } from "./ipc.service";
|
||||
import { NotificationService } from "./notification.service";
|
||||
|
||||
export class ProgressBarService{
|
||||
|
||||
private static instance: ProgressBarService;
|
||||
|
||||
private readonly ipcService: IpcService;
|
||||
private notificationService: NotificationService;
|
||||
|
||||
private readonly _progression$: BehaviorSubject<number>;
|
||||
private readonly _visible$: BehaviorSubject<boolean>;
|
||||
@@ -20,6 +22,7 @@ export class ProgressBarService{
|
||||
|
||||
private constructor(){
|
||||
this.ipcService = IpcService.getInstance();
|
||||
this.notificationService = NotificationService.getInstance();
|
||||
|
||||
this._progression$ = new BehaviorSubject<number>(0);
|
||||
this._visible$ = new BehaviorSubject<boolean>(false);
|
||||
@@ -68,6 +71,14 @@ export class ProgressBarService{
|
||||
this.visible$.next(false);
|
||||
}
|
||||
|
||||
public require(): boolean{
|
||||
if(this.isVisible){
|
||||
this.notificationService.notifyError({title: "notifications.shared.errors.titles.operation-running", desc: "notifications.shared.errors.msg.operation-running", duration: 3000});
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public get progression$(): BehaviorSubject<number>{ return this._progression$; }
|
||||
public get visible$(): BehaviorSubject<boolean>{ return this._visible$; }
|
||||
public get isVisible(): boolean{ return this._visible$.value; }
|
||||
|
||||
Reference in New Issue
Block a user