notify when bs close with error

This commit is contained in:
MathieuG-P
2022-07-26 21:24:52 +02:00
parent bf768e724a
commit a9480638e7
2 changed files with 49 additions and 30 deletions
+48 -25
View File
@@ -3,39 +3,62 @@ import { BSVersion } from 'shared/bs-version.interface';
import { IpcService } from "./ipc.service";
import { NotificationResult, NotificationService } from "./notification.service";
import { BsDownloaderService } from "./bs-downloader.service";
import { BehaviorSubject } from "rxjs";
export class BSLauncherService{
private static instance: BSLauncherService;
private static instance: BSLauncherService;
private readonly ipcService: IpcService;
private readonly notificationService: NotificationService;
private readonly bsDownloaderService: BsDownloaderService;
private readonly ipcService: IpcService;
private readonly notificationService: NotificationService;
private readonly bsDownloaderService: BsDownloaderService;
public readonly launchState$: BehaviorSubject<BSVersion> = new BehaviorSubject(null);
public static getInstance(){
if(!BSLauncherService.instance){ BSLauncherService.instance = new BSLauncherService(); }
return BSLauncherService.instance;
}
public static getInstance(){
if(!BSLauncherService.instance){ BSLauncherService.instance = new BSLauncherService(); }
return BSLauncherService.instance;
}
private constructor(){
this.ipcService = IpcService.getInstance();
this.notificationService = NotificationService.getInstance();
this.bsDownloaderService = BsDownloaderService.getInstance();
}
private constructor(){
this.ipcService = IpcService.getInstance();
this.notificationService = NotificationService.getInstance();
this.bsDownloaderService = BsDownloaderService.getInstance();
this.listenBsExit();
}
public launch(version: BSVersion, oculus: boolean, desktop: boolean, debug: boolean): Promise<NotificationResult|string>{
const lauchOption: LauchOption = {debug, oculus, desktop, version};
return this.ipcService.send<LaunchResult>("bs-launch.launch", {args: lauchOption}).then(res => {
if(!res.success){ return this.notificationService.notifyError({title: "notifications.bs-launch.errors.titles.UNABLE_TO_LAUNCH", desc: res.error.title}); }
if(res.data === "EXE_NOT_FINDED"){
return this.notificationService.notifyError({title: "notifications.bs-launch.errors.titles.EXE_NOT_FINDED", desc: "notifications.bs-launch.errors.msg.EXE_NOT_FINDED", actions: [{id: "0", title:"misc.verify"}]}).then(res => {
if(res === "0"){ this.bsDownloaderService.download(version, true); }
return res;
private listenBsExit(): void{
this.ipcService.watch("bs-launch.exit").subscribe(res => {
const version = this.launchState$.value;
this.launchState$.next(null);
if(res.success){ return; }
this.notificationService.notifyError({title: "Arrêt brutal", desc: "BeatSaber s'est arrêté brusquement, essaye de vérifier les fichiers", actions: [{id: "0", title: "misc.verify"}]}).then(res => {
if(res === "0"){ this.bsDownloaderService.download(version, true); }
});
}
if(res.data === "LAUNCHED"){ return this.notificationService.notifySuccess({title: "notifications.bs-launch.success.titles.launching"}); }
if(res.data){ return this.notificationService.notifyError({title: `notifications.bs-launch.errors.titles.${res.data}`}); }
return this.notificationService.notifyError({title: res.data || res.error.title});
});
}
public launch(version: BSVersion, oculus: boolean, desktop: boolean, debug: boolean): Promise<NotificationResult|string>{
const lauchOption: LauchOption = {debug, oculus, desktop, version};
this.launchState$.next(version);
return this.ipcService.send<LaunchResult>("bs-launch.launch", {args: lauchOption}).then(res => {
if(res.data === "LAUNCHED"){ return this.notificationService.notifySuccess({title: "notifications.bs-launch.success.titles.launching"}); }
this.launchState$.next(null);
if(!res.success){
return this.notificationService.notifyError({title: "notifications.bs-launch.errors.titles.UNABLE_TO_LAUNCH", desc: res.error.title});
}
if(res.data === "EXE_NOT_FINDED"){
return this.notificationService.notifyError({title: "notifications.bs-launch.errors.titles.EXE_NOT_FINDED", desc: "notifications.bs-launch.errors.msg.EXE_NOT_FINDED", actions: [{id: "0", title:"misc.verify"}]}).then(res => {
if(res === "0"){ this.bsDownloaderService.download(version, true); }
return res;
});
}
if(res.data){ return this.notificationService.notifyError({title: `notifications.bs-launch.errors.titles.${res.data}`}); }
return this.notificationService.notifyError({title: res.data || res.error.title});
});
}