[feature] Rework of the BS launching system to prepare for shortcuts

This commit is contained in:
MathieuG-P
2023-06-26 23:25:53 +02:00
parent f9674df2ce
commit b7e287c86a
12 changed files with 249 additions and 78 deletions
@@ -25,7 +25,7 @@ export function LaunchSlide({version}: Props) {
const [advancedLaunch, setAdvancedLaunch] = useState(false);
const [additionalArgsString, setAdditionalArgsString] = useState<string>(configService.get<string>("additionnal-args") || "");
const launchState = useObservable(bsLauncherService.launchState$);
const versionRunning = useObservable(bsLauncherService.versionRunning$);
useEffect(() => {
configService.set("additionnal-args", additionalArgsString);
@@ -69,7 +69,7 @@ export function LaunchSlide({version}: Props) {
</motion.div>
</div>
<div className='grow flex justify-center items-center'>
<BsmButton onClick={launch} active={JSON.stringify(version) === JSON.stringify(launchState)} className='relative -translate-y-1/2 text-5xl text-gray-800 dark:text-gray-200 font-bold tracking-wide pt-1 pb-3 px-7 rounded-lg shadow-md italic shadow-black active:scale-90 transition-transform' text="misc.launch"/>
<BsmButton onClick={launch} active={JSON.stringify(version) === JSON.stringify(versionRunning)} className='relative -translate-y-1/2 text-5xl text-gray-800 dark:text-gray-200 font-bold tracking-wide pt-1 pb-3 px-7 rounded-lg shadow-md italic shadow-black active:scale-90 transition-transform' text="misc.launch"/>
</div>
</div>
)
+36 -11
View File
@@ -1,10 +1,11 @@
import { LauchOption, LaunchResult } from "shared/models/bs-launch";
import { LaunchOption, LaunchResult } from "shared/models/bs-launch";
import { BSVersion } from 'shared/bs-version.interface';
import { IpcService } from "./ipc.service";
import { NotificationService } from "./notification.service";
import { BsDownloaderService } from "./bs-downloader.service";
import { BehaviorSubject } from "rxjs";
import { BehaviorSubject, Observable } from "rxjs";
import { NotificationResult } from "shared/models/notification/notification.model";
import { BSLaunchErrorEvent, BSLaunchErrorType, BSLaunchEvent } from "../../shared/models/bs-launch";
export class BSLauncherService{
@@ -14,7 +15,7 @@ export class BSLauncherService{
private readonly notificationService: NotificationService;
private readonly bsDownloaderService: BsDownloaderService;
public readonly launchState$: BehaviorSubject<BSVersion> = new BehaviorSubject(null);
public readonly versionRunning$: BehaviorSubject<BSVersion> = new BehaviorSubject(null);
public static getInstance(){
if(!BSLauncherService.instance){ BSLauncherService.instance = new BSLauncherService(); }
@@ -25,13 +26,13 @@ export class BSLauncherService{
this.ipcService = IpcService.getInstance();
this.notificationService = NotificationService.getInstance();
this.bsDownloaderService = BsDownloaderService.getInstance();
this.listenBsExit();
}
// TODO REMOVE
private listenBsExit(): void{
this.ipcService.watch("bs-launch.exit").subscribe(res => {
const version = this.launchState$.value;
this.launchState$.next(null);
const version = this.versionRunning$.value;
this.versionRunning$.next(null);
if(res.success){ return; }
this.notificationService.notifyError({title: "notifications.bs-launch.errors.titles.EXIT", desc: "notifications.bs-launch.errors.msg.EXIT", actions: [{id: "0", title: "misc.verify"}]}).then(res => {
if(res === "0"){ this.bsDownloaderService.download(version, true); }
@@ -41,15 +42,15 @@ export class BSLauncherService{
// TODO : Rework with shortcuts implementation
public launch(version: BSVersion, oculus: boolean, desktop: boolean, debug: boolean, additionalArgs?: string[]): Promise<NotificationResult|string>{
const lauchOption: LauchOption = {debug, oculus, desktop, version, additionalArgs};
if(this.launchState$.value){ return this.notificationService.notifyError({title: "notifications.bs-launch.errors.titles.BS_ALREADY_RUNNING"}); }
this.launchState$.next(version);
public launch_old(version: BSVersion, oculus: boolean, desktop: boolean, debug: boolean, additionalArgs?: string[]): Promise<NotificationResult|string>{
const lauchOption: LaunchOption = {debug, oculus, desktop, version, additionalArgs};
if(this.versionRunning$.value){ return this.notificationService.notifyError({title: "notifications.bs-launch.errors.titles.BS_ALREADY_RUNNING"}); }
this.versionRunning$.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);
this.versionRunning$.next(null);
if(!res.success){
return this.notificationService.notifyError({title: "notifications.bs-launch.errors.titles.UNABLE_TO_LAUNCH", desc: res.error.title});
}
@@ -66,6 +67,30 @@ export class BSLauncherService{
});
}
public launch(version: BSVersion, oculus: boolean, desktop: boolean, debug: boolean, additionalArgs?: string[]): Observable<BSLaunchEvent> {
const launchState$ = this.ipcService.sendV2<BSLaunchEvent, LaunchOption>("bs-launch.launch", {args: {debug, oculus, desktop, version, additionalArgs}});
this.versionRunning$.next(version);
launchState$.subscribe({
next: event => {
this.notificationService.notifySuccess({title: `notifications.bs-launch.success.titles.${event.type}`, desc: `notifications.bs-launch.success.msg.${event.type}`});
},
error: (err: BSLaunchErrorEvent) => {
if(err.type === BSLaunchErrorType.UNKNOWN_ERROR || !Object.values(BSLaunchErrorType).includes(err.type)){
this.notificationService.notifyError({title: "notifications.bs-launch.errors.titles.UNABLE_TO_LAUNCH"});
} else {
this.notificationService.notifyError({title: `notifications.bs-launch.errors.titles.${err.type}`, desc: `notifications.bs-launch.errors.msg.${err.type}`})
}
},
complete: () => {
this.versionRunning$.next(null);
}
})
return launchState$;
}
}
export enum LaunchMods{