mirror of
https://github.com/Zagrios/bs-manager.git
synced 2026-07-03 14:08:25 +02:00
notify when bs close with error
This commit is contained in:
@@ -1,11 +1,9 @@
|
||||
import path from "path";
|
||||
import { LaunchResult, LauchOption } from "shared/models/bs-launch";
|
||||
import { BSVersion } from 'shared/bs-version.interface';
|
||||
import { UtilsService } from "./utils.service";
|
||||
import { BS_EXECUTABLE, BS_APP_ID } from "../constants";
|
||||
import { ChildProcessWithoutNullStreams, spawn } from "child_process";
|
||||
import { SteamService } from "./steam.service";
|
||||
import { InstallationLocationService } from "./installation-location.service";
|
||||
import { BSLocalVersionService } from "./bs-local-version.service";
|
||||
|
||||
export class BSLauncherService{
|
||||
@@ -14,7 +12,6 @@ export class BSLauncherService{
|
||||
|
||||
private readonly utilsService: UtilsService;
|
||||
private readonly steamService: SteamService;
|
||||
private readonly installLocationService: InstallationLocationService;
|
||||
private readonly localVersionService: BSLocalVersionService;
|
||||
|
||||
private bsProcess: ChildProcessWithoutNullStreams;
|
||||
@@ -27,7 +24,6 @@ export class BSLauncherService{
|
||||
private constructor(){
|
||||
this.utilsService = UtilsService.getInstance();
|
||||
this.steamService = SteamService.getInstance();
|
||||
this.installLocationService = InstallationLocationService.getInstance();
|
||||
this.localVersionService = BSLocalVersionService.getInstance();
|
||||
}
|
||||
|
||||
@@ -50,7 +46,7 @@ export class BSLauncherService{
|
||||
|
||||
this.bsProcess.on('message', msg => { /** EMIT HERE **/ });
|
||||
this.bsProcess.on('error', err => { /** EMIT HERE **/ });
|
||||
this.bsProcess.on('exit', code => this.utilsService.ipcSend("bs-launch.exit", {data: code, success: true}));
|
||||
this.bsProcess.on('exit', code => this.utilsService.ipcSend("bs-launch.exit", {data: code, success: code === 0}));
|
||||
|
||||
return "LAUNCHED";
|
||||
}
|
||||
|
||||
@@ -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});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user