[feature-136] move one click download in the new models downloader service

This commit is contained in:
MathieuG-P
2023-05-20 23:27:52 +02:00
parent 9d230461de
commit 474deaedcf
3 changed files with 24 additions and 48 deletions
@@ -1,39 +0,0 @@
import { timer } from "rxjs";
import { MSModel } from "shared/models/models/model-saber.model";
import { IpcService } from "./ipc.service";
import { ProgressBarService } from "./progress-bar.service";
export class ModelDownloaderService {
private static instance: ModelDownloaderService;
public static getInstance(): ModelDownloaderService{
if(!ModelDownloaderService.instance){ ModelDownloaderService.instance = new ModelDownloaderService(); }
return ModelDownloaderService.instance;
}
private readonly ipc: IpcService;
private readonly progress: ProgressBarService;
private constructor(){
this.ipc = IpcService.getInstance();
this.progress = ProgressBarService.getInstance();
}
public async oneClickInstallModel(model: MSModel): Promise<boolean>{ // TODO : Put this function in the new ModelDownloaderService
this.progress.showFake(0.04);
const res = await this.ipc.send("one-click-install-model", {args: model});
this.progress.complete();
await timer(500).toPromise();
this.progress.hide(true);
return res.success;
}
}
@@ -1,4 +1,4 @@
import { BehaviorSubject, Observable, Subscription, distinctUntilChanged, filter, lastValueFrom, map, shareReplay, startWith } from "rxjs";
import { BehaviorSubject, Observable, Subscription, distinctUntilChanged, filter, lastValueFrom, map, shareReplay, startWith, timer } 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";
@@ -103,6 +103,20 @@ export class ModelsDownloaderService {
return this.modal.openModal(DownloadModelsModal, {version, type, owned});
}
public async oneClickInstallModel(model: MSModel): Promise<boolean>{
this.progress.showFake(0.04);
const res = await this.ipc.send("one-click-install-model", {args: model});
this.progress.complete();
await timer(500).toPromise();
this.progress.hide(true);
return res.success;
}
}
export type ModelDownload = {