mirror of
https://github.com/Zagrios/bs-manager.git
synced 2026-07-03 14:08:25 +02:00
[feature-136] fix some bugs + prepare models download + use color libs for font contrast
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { BehaviorSubject } from "rxjs";
|
||||
import { BehaviorSubject, Observable, shareReplay } from "rxjs";
|
||||
import { DefaultConfigKey, defaultConfiguration } from "renderer/config/default-configuration.config";
|
||||
|
||||
export class ConfigurationService {
|
||||
@@ -40,9 +40,9 @@ export class ConfigurationService {
|
||||
this.emitChange(key);
|
||||
}
|
||||
|
||||
public watch<T>(key: DefaultConfigKey | string): BehaviorSubject<T>{
|
||||
public watch<T>(key: DefaultConfigKey | string): Observable<T>{
|
||||
if(this.observers.has(key)){ return this.observers.get(key); }
|
||||
this.observers.set(key, new BehaviorSubject(this.get(key)));
|
||||
return this.observers.get(key);
|
||||
return this.observers.get(key).asObservable();
|
||||
}
|
||||
}
|
||||
@@ -51,7 +51,7 @@ export class MapsDownloaderService {
|
||||
while(this.mapsQueue$.value.at(0)){
|
||||
const toDownload = this.mapsQueue$.value.at(0);
|
||||
this.currentDownload$.next(toDownload);
|
||||
const downloaded = await this.downloadMap(toDownload.map, toDownload.version).toPromise();
|
||||
const downloaded = await this.downloadMap(toDownload.map, toDownload.version)?.toPromise();
|
||||
|
||||
if(downloaded){
|
||||
this.downloadedListerners.forEach(func => func(downloaded, toDownload.version));
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
import { BehaviorSubject, Observable, Subscription, distinctUntilChanged, filter, map, shareReplay } from "rxjs";
|
||||
import { BSVersion } from "shared/bs-version.interface";
|
||||
import { BsmLocalModel } from "shared/models/models/bsm-local-model.interface";
|
||||
import { MSModel, MSModelType } from "shared/models/models/model-saber.model";
|
||||
import { ModalResponse, ModalService } from "../modale.service";
|
||||
import { IpcService } from "../ipc.service";
|
||||
import { DownloadMapsModal } from "renderer/components/modal/modal-types/download-maps-modal.component";
|
||||
|
||||
export class ModelsDownloaderService {
|
||||
|
||||
private static instance: ModelsDownloaderService;
|
||||
|
||||
public static getInstance(): ModelsDownloaderService{
|
||||
if(!ModelsDownloaderService.instance){ ModelsDownloaderService.instance = new ModelsDownloaderService(); }
|
||||
return ModelsDownloaderService.instance;
|
||||
}
|
||||
|
||||
private readonly ipc: IpcService;
|
||||
private readonly modal: ModalService
|
||||
|
||||
private readonly lastDownloadedModel$ = new BehaviorSubject<ModelDownload>(null);
|
||||
private readonly queue$ = new BehaviorSubject<ModelDownload[]>([]);
|
||||
private readonly currentDownload$ = this.queue$.pipe(map(queue => queue.at(0)), distinctUntilChanged(), shareReplay(1));
|
||||
|
||||
private constructor(){
|
||||
|
||||
this.ipc = IpcService.getInstance();
|
||||
this.modal = ModalService.getInsance();
|
||||
|
||||
this.currentDownload$.pipe(filter(v => !!v)).subscribe(model => this.downloadModel(model));
|
||||
}
|
||||
|
||||
private downloadModel(model: ModelDownload){
|
||||
// TODO: Download model
|
||||
}
|
||||
|
||||
public addModelToDownload(model: ModelDownload): ModelDownload{
|
||||
const queue = this.queue$.value;
|
||||
queue.push(model);
|
||||
this.queue$.next(queue);
|
||||
return model;
|
||||
}
|
||||
|
||||
public removeFromDownloadQueue(model: ModelDownload){
|
||||
const queue = this.queue$.value;
|
||||
const index = queue.findIndex(m => m.hash === model.hash);
|
||||
|
||||
if(index === -1){ return; }
|
||||
|
||||
queue.splice(index, 1);
|
||||
this.queue$.next(queue);
|
||||
}
|
||||
|
||||
public onModelsDownloaded$(cb: (model: ModelDownload) => void): Subscription{
|
||||
return this.lastDownloadedModel$.pipe(filter(v => !!v)).subscribe(cb);
|
||||
}
|
||||
|
||||
public isDownloading$(model: ModelDownload): Observable<boolean>{
|
||||
return this.currentDownload$.pipe(map(current => {
|
||||
if(!current){ return false; }
|
||||
return current.hash === model.hash && current.version === model.version
|
||||
}), distinctUntilChanged());
|
||||
}
|
||||
|
||||
public isPending$(model: ModelDownload): Observable<boolean>{
|
||||
return this.queue$.pipe(map(queue => queue.at(0).hash !== model.hash && queue.at(0).version !== model.version && queue.some(m => m.hash === model.hash && m.version === model.version)), distinctUntilChanged());
|
||||
}
|
||||
|
||||
public openDownloadModelsModal(version: BSVersion, type?: MSModelType): Promise<ModalResponse<void>>{
|
||||
return this.modal.openModal(DownloadMapsModal, {version: null, ownedMaps: []}); // TODO MODELS
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export type ModelDownload = Partial<MSModel> & Pick<MSModel, "hash"> & {version: BSVersion};
|
||||
export type ModelDownloaded = BsmLocalModel & {version: BSVersion};
|
||||
@@ -131,6 +131,8 @@ export class ModelsManagerService {
|
||||
|
||||
public async deleteModels(models: BsmLocalModel[], version?: BSVersion): Promise<boolean>{
|
||||
|
||||
if(!models){ return Promise.resolve(false); }
|
||||
|
||||
const askModal = models.length > 1 || !this.config.get<boolean>(ModelsManagerService.REMEMBER_CHOICE_DELETE_MODEL_KEY);
|
||||
|
||||
if(askModal){
|
||||
|
||||
Reference in New Issue
Block a user