deep-links models fully work AND add translations

This commit is contained in:
MathieuG-P
2022-12-25 22:18:28 +01:00
parent c674fce0c0
commit 9d7cd708c7
14 changed files with 210 additions and 26 deletions
@@ -6,6 +6,10 @@ import { UtilsService } from "../utils.service";
import { WindowManagerService } from "../window-manager.service";
import { MSModel, MSModelType } from "shared/models/model-saber/model-saber.model";
import { BSVersion } from "shared/bs-version.interface";
import { BSLocalVersionService } from "../bs-local-version.service";
import path from "path";
import { RequestService } from "../request.service";
import { copyFileSync, constants } from "fs-extra";
export class LocalModelsManagerService {
@@ -20,14 +24,25 @@ export class LocalModelsManagerService {
ModelSaber: "modelsaber",
};
private readonly MODEL_TYPE_FOLDER: Record<Exclude<MSModelType, "misc">, string> = {
avatar: "CustomAvatars",
bloq: "CustomNotes",
platform: "CustomPlatforms",
saber: "CustomSabers"
}
private readonly deepLink: DeepLinkService;
private readonly utils: UtilsService;
private readonly windows: WindowManagerService;
private readonly localVersion: BSLocalVersionService;
private readonly request: RequestService;
private constructor(){
this.deepLink = DeepLinkService.getInstance();
this.utils = UtilsService.getInstance();
this.windows = WindowManagerService.getInstance();
this.localVersion = BSLocalVersionService.getInstance();
this.request = RequestService.getInstance();
this.deepLink.addLinkOpenedListener(this.DEEP_LINKS.ModelSaber, (link) => {
log.info("DEEP-LINK RECEIVED FROM", this.DEEP_LINKS.ModelSaber, link);
@@ -42,8 +57,7 @@ export class LocalModelsManagerService {
private openOneClickDownloadModelWindow(id: string, type: string){
// TODO make once
ipcMain.on("one-click-model-info", async (event, req: IpcRequest<void>) => {
ipcMain.once("one-click-model-info", async (event, req: IpcRequest<void>) => {
this.utils.ipcSend(req.responceChannel, {success: true, data: {id, type}});
});
@@ -51,16 +65,61 @@ export class LocalModelsManagerService {
}
private getModelFolderPath(type: MSModelType, version?: BSVersion): Promise<string>{
// TODO : return path of model type of version
private async getModelFolderPath(type: MSModelType, version?: BSVersion): Promise<string>{
if(!version){ throw "will be implemented whith models management" }
if(type === "misc"){ throw "model type not supported"; }
const versionPath = await this.localVersion.getVersionPath(version);
const modelFolderPath = path.join(versionPath, this.MODEL_TYPE_FOLDER[type]);
this.utils.createFolderIfNotExist(modelFolderPath);
return modelFolderPath;
}
public downloadModel(model: MSModel, version: BSVersion): Promise<string>{
// TODO : Download model to the version
public async downloadModel(model: MSModel, version: BSVersion): Promise<string>{
const modelFolder = await this.getModelFolderPath(model.type, version);
const modelDest = path.join(modelFolder, path.basename(model.download));
return this.request.downloadFile(model.download, modelDest);
}
public async oneClickDownloadModel(model: MSModel): Promise<void>{
if(!model){ return; }
const versions = await this.localVersion.getInstalledVersions();
if(versions?.length === 0){ return; }
const fisrtVersion = versions.shift();
const downloaded = await this.downloadModel(model, fisrtVersion);
for(const version of versions){
const modelDest = path.join(await this.getModelFolderPath(model.type, version), path.basename(downloaded));
copyFileSync(downloaded, modelDest);
}
}
public enableDeepLinks(): boolean{
return Array.from(Object.values(this.DEEP_LINKS)).every(link => this.deepLink.registerDeepLink(link));
}
public disableDeepLinks(): boolean{
return Array.from(Object.values(this.DEEP_LINKS)).every(link => this.deepLink.unRegisterDeepLink(link));
}
public isDeepLinksEnabled(): boolean{
return Array.from(Object.values(this.DEEP_LINKS)).every(link => this.deepLink.isDeepLinkRegistred(link));
}
}