install mods & uninstall mod & uninstall all mods & ligth theme & some modals

This commit is contained in:
MathieuG-P
2022-10-03 00:56:20 +02:00
parent 337697fafb
commit 9d2ec1166e
26 changed files with 459 additions and 108 deletions
@@ -1,12 +1,23 @@
import { BehaviorSubject } from "rxjs";
import { map } from "rxjs/operators";
import { BSVersion } from "shared/bs-version.interface";
import { Mod } from "shared/models/mods/mod.interface";
import { Mod, ModInstallProgression } from "shared/models/mods/mod.interface";
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 BsModsManagerService {
private static instance: BsModsManagerService;
private readonly ipcService: IpcService;
private readonly progressBar: ProgressBarService;
private readonly modals: ModalService;
private readonly notifications: NotificationService;
public readonly isInstalling$: BehaviorSubject<boolean> = new BehaviorSubject(false);
public readonly isUninstalling$: BehaviorSubject<boolean> = new BehaviorSubject(false);
public static getInstance(): BsModsManagerService{
if(!BsModsManagerService.instance){ BsModsManagerService.instance = new BsModsManagerService(); }
@@ -15,6 +26,9 @@ export class BsModsManagerService {
private constructor(){
this.ipcService = IpcService.getInstance();
this.progressBar = ProgressBarService.getInstance();
this.modals = ModalService.getInsance();
this.notifications = NotificationService.getInstance();
}
public getAvailableMods(version: BSVersion): Promise<Mod[]>{
@@ -26,11 +40,46 @@ export class BsModsManagerService {
}
public installMods(mods: Mod[], version: BSVersion){
throw "NOT IMPLEMENTED YET";
if(!this.progressBar.require()){ return; }
const progress$ = this.ipcService.watch<ModInstallProgression>("mod-installed").pipe(map(res => res.data.progression));
this.progressBar.show(progress$, true, {paddingLeft: "190px", paddingRight: "190px", bottom: "20px"});
this.isInstalling$.next(true);
return this.ipcService.send<number, {mods: Mod[], version: BSVersion}>("install-mods", {args: {mods, version}}).then(res => {
this.isInstalling$.next(false);
this.progressBar.hide();
});
}
public async uninstallMod(mod: Mod, version: BSVersion){
const modalRes = await this.modals.openModal(ModalType.UNINSTALL_MOD, mod);
if(modalRes.exitCode !== ModalExitCode.COMPLETED || !this.progressBar.require()){ return; }
const progress$ = this.ipcService.watch<ModInstallProgression>("mod-uninstalled").pipe(map(res => res.data.progression));
this.progressBar.show(progress$, true, {paddingLeft: "190px", paddingRight: "190px", bottom: "20px"});
this.isUninstalling$.next(true);
return this.ipcService.send("uninstall-mods", {args: {mods: [mod], version}}).then(res => {
this.isUninstalling$.next(false);
this.progressBar.hide();
});
}
public uninstallMods(mods: Mod[], version: BSVersion){
throw "NOT IMPLEMENTED YET";
public async uninstallAllMods(version: BSVersion){
//TODO MODAL
const progress$ = this.ipcService.watch<ModInstallProgression>("mod-uninstalled").pipe(map(res => res.data.progression));
this.progressBar.show(progress$, true, {paddingLeft: "190px", paddingRight: "190px", bottom: "20px"});
this.isUninstalling$.next(true);
return this.ipcService.send("uninstall-all-mods", {args: version}).then(res => {
this.isUninstalling$.next(false);
this.progressBar.hide();
});
}
public isModsAvailable(version: BSVersion): Promise<boolean>{
+5 -4
View File
@@ -50,23 +50,24 @@ export class ModalService{
}
export enum ModalType {
export const enum ModalType {
STEAM_LOGIN = "STEAM_LOGIN",
GUARD_CODE = "GUARD_CODE",
UNINSTALL = "UNINSTALL",
INSTALLATION_FOLDER = "INSTALLATION_FOLDER",
EDIT_VERSION = "EDIT_VERSION",
CLONE_VERSION = "CLONE_VERSION"
CLONE_VERSION = "CLONE_VERSION",
UNINSTALL_MOD = "UNINSTALL_MOD"
}
export enum ModalExitCode {
export const enum ModalExitCode {
NO_CHOICE = -1,
COMPLETED = 0,
CLOSED = 1,
CANCELED = 2,
}
export interface ModalResponse<T> {
export interface ModalResponse<T = unknown> {
exitCode: ModalExitCode,
data?: T
}
@@ -0,0 +1,30 @@
import { BehaviorSubject } from "rxjs";
export class PageStateService {
private static instance: PageStateService;
private readonly _state$: BehaviorSubject<any> = new BehaviorSubject(undefined);
public static getInstance(): PageStateService{
if(!PageStateService.instance){ PageStateService.instance = new PageStateService(); }
return PageStateService.instance;
}
private constructor(){
this.state$.subscribe(a => console.log(a))
}
public setState(state: unknown){
this._state$.next(state);
}
public getState<T = unknown>(): T{
return this._state$.value;
}
public get state$(){
return this._state$.asObservable();
}
}
@@ -2,6 +2,7 @@ import { distinctUntilChanged, map } from "rxjs/operators";
import { BehaviorSubject, Observable, Subscription, timer } from "rxjs";
import { IpcService } from "./ipc.service";
import { NotificationService } from "./notification.service";
import { CSSProperties } from "react";
export class ProgressBarService{
@@ -12,6 +13,7 @@ export class ProgressBarService{
private readonly _progression$: BehaviorSubject<number>;
private readonly _visible$: BehaviorSubject<boolean>;
private readonly _style$: BehaviorSubject<CSSProperties>;
private subscription: Subscription;
@@ -26,6 +28,7 @@ export class ProgressBarService{
this._progression$ = new BehaviorSubject<number>(0);
this._visible$ = new BehaviorSubject<boolean>(false);
this._style$ = new BehaviorSubject<CSSProperties>(undefined);
this.progression$.subscribe(progression => this.setSystemProgression(progression));
}
@@ -47,13 +50,14 @@ export class ProgressBarService{
this.subscription = null;
}
public show(obs?: Observable<number>, unsubscribe? : boolean){
public show(obs?: Observable<number>, unsubscribe? : boolean, style?: CSSProperties){
if(unsubscribe){ this.unsubscribe(); }
if(obs){ this.subscribreTo(obs); }
this.visible$.next(true);
this.visible$.next(true);
this._style$.next(style);
}
public showFake(speed: number): void{
public showFake(speed: number, style?: CSSProperties): void{
const obs = timer(1000, 100).pipe(map(val => {
if(this.progression$.value >= 100){ return 100; }
const currentProgress = speed * (val + 1);
@@ -66,7 +70,7 @@ export class ProgressBarService{
this.progression$.next(100);
}
public hide(unsubscribe: boolean){
public hide(unsubscribe: boolean = true){
if(unsubscribe){ this.unsubscribe(); }
this.visible$.next(false);
}
@@ -82,6 +86,7 @@ export class ProgressBarService{
public get progression$(): BehaviorSubject<number>{ return this._progression$; }
public get visible$(): BehaviorSubject<boolean>{ return this._visible$; }
public get isVisible(): boolean{ return this._visible$.value; }
public get style$(): BehaviorSubject<CSSProperties>{ return this._style$; }