mirror of
https://github.com/Zagrios/bs-manager.git
synced 2026-07-03 14:08:25 +02:00
add double click to quick launch
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
import { DownloadEvent } from 'main/services/bs-installer.service';
|
||||
import { BehaviorSubject, distinctUntilChanged } from 'rxjs';
|
||||
import { BehaviorSubject, distinctUntilChanged, filter, debounceTime } from 'rxjs';
|
||||
import { IpcResponse } from 'shared/models/ipc-models.model';
|
||||
import { BSVersion } from '../../main/services/bs-version-manager.service'
|
||||
import { AuthUserService } from './auth-user.service';
|
||||
import { BSVersionManagerService } from './bs-version-manager.service';
|
||||
import { IpcService } from './ipc.service';
|
||||
import { ModalExitCode, ModalService, ModalType } from './modale.service';
|
||||
import { NotificationService } from './notification.service';
|
||||
import { ProgressBarService } from './progress-bar.service';
|
||||
|
||||
export class BsDownloaderService{
|
||||
|
||||
@@ -15,6 +17,8 @@ export class BsDownloaderService{
|
||||
private readonly ipcService: IpcService;
|
||||
private readonly bsVersionManager: BSVersionManagerService;
|
||||
private readonly authService: AuthUserService;
|
||||
private readonly progressBarService: ProgressBarService;
|
||||
private readonly notificationService: NotificationService;
|
||||
|
||||
public readonly currentBsVersionDownload$: BehaviorSubject<BSVersion> = new BehaviorSubject(null);
|
||||
|
||||
@@ -34,30 +38,35 @@ export class BsDownloaderService{
|
||||
this.modalService = ModalService.getInsance();
|
||||
this.bsVersionManager = BSVersionManagerService.getInstance();
|
||||
this.authService = AuthUserService.getInstance();
|
||||
this.progressBarService = ProgressBarService.getInstance();
|
||||
this.notificationService = NotificationService.getInstance();
|
||||
this.asignListerners();
|
||||
}
|
||||
|
||||
private asignListerners(): void{
|
||||
|
||||
this.ipcService.watch<number>("bs-download.[Progress]").pipe(distinctUntilChanged()).subscribe(response => this.downloadProgress$.next(response.data));
|
||||
private asignListerners(): void{
|
||||
this.ipcService.watch<number>("bs-download.[Progress]").pipe(distinctUntilChanged()).subscribe(response => this.downloadProgress$.next(response.data));
|
||||
|
||||
this.ipcService.watch<string>("bs-download.[SteamID]").subscribe(response => response.success && this.authService.setSteamID(response.data));
|
||||
this.ipcService.watch<string>("bs-download.[SteamID]").pipe(filter(r => r.success && !!r.data)).subscribe(response => this.authService.setSteamID(response.data));
|
||||
|
||||
this.ipcService.watch<string>("bs-download.[Warning]").subscribe(response => this.downloadWarning$.next(response.data));
|
||||
this.ipcService.watch<string>("bs-download.[Warning]").pipe(filter(v => !!v && !!v.data), distinctUntilChanged(), debounceTime(1000)).subscribe(warning => {
|
||||
this.notificationService.notifyWarning({title: "notifications.types.warning", desc: `notifications.bs-download.warnings.msg.${warning.data}`});
|
||||
});
|
||||
|
||||
this.ipcService.watch<string>("bs-download.[Error]").subscribe(response => this.downloadError$.next(response.data));
|
||||
this.ipcService.watch<string>("bs-download.[Error]").pipe(filter(v => !!v && !!v.data), distinctUntilChanged(), debounceTime(1000)).subscribe(err => {
|
||||
this.notificationService.notifyError({title: "notifications.types.error", desc: `notifications.bs-download.errors.msg.${err.data}`});
|
||||
});
|
||||
|
||||
this.ipcService.watch<void>("bs-download.[2FA]").subscribe(async response => {
|
||||
if(!response.success){ return; }
|
||||
const res = await this.modalService.openModal(ModalType.GUARD_CODE);
|
||||
if(res.exitCode !== ModalExitCode.COMPLETED){ return; }
|
||||
this.ipcService.sendLazy('bs-download.[2FA]', {args: res.data});
|
||||
});
|
||||
this.ipcService.watch<void>("bs-download.[2FA]").subscribe(async response => {
|
||||
if(!response.success){ return; }
|
||||
const res = await this.modalService.openModal(ModalType.GUARD_CODE);
|
||||
if(res.exitCode !== ModalExitCode.COMPLETED){ return; }
|
||||
this.ipcService.sendLazy('bs-download.[2FA]', {args: res.data});
|
||||
});
|
||||
|
||||
this.currentBsVersionDownload$.subscribe(version => {
|
||||
if(version){ this.bsVersionManager.setInstalledVersions([...this.bsVersionManager.installedVersions$.value, version]); }
|
||||
else{ this.bsVersionManager.askInstalledVersions(); }
|
||||
});
|
||||
this.currentBsVersionDownload$.subscribe(version => {
|
||||
if(version){ this.bsVersionManager.setInstalledVersions([...this.bsVersionManager.installedVersions$.value, version]); }
|
||||
else{ this.bsVersionManager.askInstalledVersions(); }
|
||||
});
|
||||
}
|
||||
|
||||
private resetDownload(): void{
|
||||
@@ -66,44 +75,51 @@ export class BsDownloaderService{
|
||||
this.selectedBsVersion$.next(null);
|
||||
}
|
||||
|
||||
public async download(bsVersion: BSVersion): Promise<IpcResponse<DownloadEvent>>{
|
||||
let promise;
|
||||
if(!this.authService.sessionExist()){
|
||||
const res = await this.modalService.openModal(ModalType.STEAM_LOGIN);
|
||||
if(res.exitCode !== ModalExitCode.COMPLETED){ return {success: false}; }
|
||||
this.authService.setSteamSession(res.data.username, res.data.stay);
|
||||
promise = this.ipcService.send<DownloadEvent>('bs-download.start', {args: {bsVersion: bsVersion, username: res.data.username, password: res.data.password, stay: res.data.stay}});
|
||||
}
|
||||
else{
|
||||
promise = this.ipcService.send<DownloadEvent>('bs-download.start', {args: {bsVersion: bsVersion, username: this.authService.getSteamUsername()}});
|
||||
}
|
||||
public async download(bsVersion: BSVersion, isVerification?: boolean): Promise<IpcResponse<DownloadEvent>>{
|
||||
if(this.progressBarService.visible$.value){
|
||||
this.notificationService.notifyError({title: "notifications.bs-download.errors.titles.already-downloading"});
|
||||
return {success: false};
|
||||
}
|
||||
|
||||
this.currentBsVersionDownload$.next(bsVersion);
|
||||
this.progressBarService.show(this.downloadProgress$);
|
||||
|
||||
let res = await promise;
|
||||
let promise;
|
||||
if(!this.authService.sessionExist()){
|
||||
const res = await this.modalService.openModal(ModalType.STEAM_LOGIN);
|
||||
if(res.exitCode !== ModalExitCode.COMPLETED){ return {success: false}; }
|
||||
this.authService.setSteamSession(res.data.username, res.data.stay);
|
||||
promise = this.ipcService.send<DownloadEvent>('bs-download.start', {args: {bsVersion: bsVersion, username: res.data.username, password: res.data.password, stay: res.data.stay}});
|
||||
}
|
||||
else{
|
||||
promise = this.ipcService.send<DownloadEvent>('bs-download.start', {args: {bsVersion: bsVersion, username: this.authService.getSteamUsername()}});
|
||||
}
|
||||
|
||||
if(!res.success){ return res; }
|
||||
this.currentBsVersionDownload$.next(bsVersion);
|
||||
|
||||
let res = await promise;
|
||||
|
||||
if(res.data.type === "[Password]"){
|
||||
this.authService.deleteSteamSession();
|
||||
res = await this.download(bsVersion);
|
||||
}
|
||||
|
||||
this.resetDownload();
|
||||
return res;
|
||||
}
|
||||
if(res.data.type === "[Password]"){
|
||||
this.authService.deleteSteamSession();
|
||||
res = await this.download(bsVersion);
|
||||
}
|
||||
|
||||
this.progressBarService.hide(true);
|
||||
this.resetDownload();
|
||||
res.success && this.notificationService.notifySuccess({title: `notifications.bs-download.success.titles.${isVerification ? "verification-finished" : "download-success"}`, duration: 3000});
|
||||
return res;
|
||||
}
|
||||
|
||||
public get isDownloading(): boolean{
|
||||
return !!this.currentBsVersionDownload$.value;
|
||||
}
|
||||
public get isDownloading(): boolean{
|
||||
return !!this.currentBsVersionDownload$.value;
|
||||
}
|
||||
|
||||
public async getInstallationFolder(): Promise<string>{
|
||||
const res = await this.ipcService.send<string>("bs-download.installation-folder");
|
||||
return res.success ? res.data : "";
|
||||
}
|
||||
public async getInstallationFolder(): Promise<string>{
|
||||
const res = await this.ipcService.send<string>("bs-download.installation-folder");
|
||||
return res.success ? res.data : "";
|
||||
}
|
||||
|
||||
public setInstallationFolder(path: string): Promise<IpcResponse<string>>{
|
||||
return this.ipcService.send<string>("bs-download.set-installation-folder", {args: path});
|
||||
}
|
||||
public setInstallationFolder(path: string): Promise<IpcResponse<string>>{
|
||||
return this.ipcService.send<string>("bs-download.set-installation-folder", {args: path});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,32 +2,48 @@ import { LauchOption } from "../../shared/models/launch-models.model";
|
||||
import { BSVersion } from "../../main/services/bs-version-manager.service";
|
||||
import { IpcService } from "./ipc.service";
|
||||
import { BsLaunchResult } from "../../shared/models/launch-models.model";
|
||||
import { IpcResponse } from "shared/models/ipc-models.model";
|
||||
import { NotificationResult, NotificationService } from "./notification.service";
|
||||
import { BsDownloaderService } from "./bs-downloader.service";
|
||||
|
||||
export class BSLauncherService{
|
||||
|
||||
private static instance: BSLauncherService;
|
||||
private static instance: BSLauncherService;
|
||||
|
||||
private readonly ipcService: IpcService;
|
||||
private readonly ipcService: IpcService;
|
||||
private readonly notificationService: NotificationService;
|
||||
private readonly bsDownloaderService: BsDownloaderService;
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
public launch(version: BSVersion, oculus: boolean, desktop: boolean, debug: boolean): Promise<IpcResponse<BsLaunchResult>>{
|
||||
const lauchOption: LauchOption = {debug, oculus, desktop, version};
|
||||
return this.ipcService.send<BsLaunchResult>("bs-launch.launch", {args: lauchOption});
|
||||
}
|
||||
public launch(version: BSVersion, oculus: boolean, desktop: boolean, debug: boolean): Promise<NotificationResult|string>{
|
||||
const lauchOption: LauchOption = {debug, oculus, desktop, version};
|
||||
return this.ipcService.send<BsLaunchResult>("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"){
|
||||
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 === "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});
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export enum LaunchMods{
|
||||
OCULUS_MOD = "LAUNCH_OCULUS_MOD",
|
||||
DESKTOP_MOD = "LAUNCH_DESKTOP_MOD",
|
||||
DEBUG_MOD ="LAUNCH_DEBUG_MOD"
|
||||
OCULUS_MOD = "LAUNCH_OCULUS_MOD",
|
||||
DESKTOP_MOD = "LAUNCH_DESKTOP_MOD",
|
||||
DEBUG_MOD ="LAUNCH_DEBUG_MOD"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user