mirror of
https://github.com/Zagrios/bs-manager.git
synced 2026-07-03 14:08:25 +02:00
deep-links models fully work AND add translations
This commit is contained in:
@@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user