mirror of
https://github.com/Zagrios/bs-manager.git
synced 2026-07-03 14:08:25 +02:00
oneclick install map from bsv now work
This commit is contained in:
@@ -16,6 +16,8 @@ export class DeepLinkService {
|
||||
|
||||
private readonly listeners = new Map<string, Listerner[]>()
|
||||
|
||||
private constructor(){}
|
||||
|
||||
public registerDeepLink(protocol: string): boolean{
|
||||
|
||||
if(process.defaultApp && process.argv.length >= 2){
|
||||
@@ -79,6 +81,19 @@ export class DeepLinkService {
|
||||
|
||||
}
|
||||
|
||||
public isDeepLink(link: string): boolean{
|
||||
|
||||
try{
|
||||
const url = new URL(link);
|
||||
const protocol = url.protocol.replace(":", "");
|
||||
return Array.from(this.listeners.keys()).some(key => key === protocol);
|
||||
}
|
||||
catch(e){
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
type Listerner = (link: string) => void;
|
||||
@@ -14,6 +14,9 @@ import sanitize from "sanitize-filename";
|
||||
import archiver from "archiver";
|
||||
import { DeepLinkService } from "../deep-link.service";
|
||||
import log from 'electron-log';
|
||||
import { WindowManagerService } from "../window-manager.service";
|
||||
import { ipcMain } from "electron";
|
||||
import { IpcRequest } from 'shared/models/ipc';
|
||||
|
||||
export class LocalMapsManagerService {
|
||||
|
||||
@@ -37,6 +40,7 @@ export class LocalMapsManagerService {
|
||||
private readonly utils: UtilsService;
|
||||
private readonly reqService: RequestService;
|
||||
private readonly deepLink: DeepLinkService;
|
||||
private readonly windows: WindowManagerService;
|
||||
|
||||
private constructor(){
|
||||
this.localVersion = BSLocalVersionService.getInstance();
|
||||
@@ -44,13 +48,16 @@ export class LocalMapsManagerService {
|
||||
this.utils = UtilsService.getInstance();
|
||||
this.reqService = RequestService.getInstance();
|
||||
this.deepLink = DeepLinkService.getInstance();
|
||||
this.windows = WindowManagerService.getInstance();
|
||||
|
||||
this.deepLink.addLinkOpenedListener(this.DEEP_LINKS.BeatSaver, (link) => {
|
||||
log.info("RECEIVED FROM", this.DEEP_LINKS.BeatSaver, link);
|
||||
log.info("MAP RECEIVED FROM", this.DEEP_LINKS.BeatSaver, link);
|
||||
this.openOneClickDownloadMapWindow(new URL(link).host);
|
||||
});
|
||||
|
||||
this.deepLink.addLinkOpenedListener(this.DEEP_LINKS.ScoreSaber, (link) => {
|
||||
log.info("RECEIVED FROM", this.DEEP_LINKS.ScoreSaber, link);
|
||||
log.info("MAP RECEIVED FROM", this.DEEP_LINKS.ScoreSaber, link);
|
||||
this.openOneClickDownloadMapWindow(new URL(link).host, true);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -130,6 +137,18 @@ export class LocalMapsManagerService {
|
||||
|
||||
}
|
||||
|
||||
private openOneClickDownloadMapWindow(mapId: string, isHash = false): void{
|
||||
|
||||
this.windows.openWindow("oneclick-download-map.html");
|
||||
|
||||
console.log("oui");
|
||||
|
||||
ipcMain.once("one-click-map-info", async (event, req: IpcRequest<void>) => {
|
||||
this.utils.ipcSend(req.responceChannel, {success: true, data: {id: mapId, isHash}});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public async getMaps(version?: BSVersion): Promise<BsmLocalMap[]>{
|
||||
const levelsFolder = await this.getMapsFolderPath(version);
|
||||
|
||||
@@ -185,6 +204,8 @@ export class LocalMapsManagerService {
|
||||
}
|
||||
|
||||
public async deleteMaps(maps: BsmLocalMap[], verion?: BSVersion){
|
||||
|
||||
console.log(verion);
|
||||
|
||||
const mapsFolders = await this.getAbsoluteFolderOfMaps(maps, verion);
|
||||
const mapsHashsToDelete = maps.map(map => map.hash);
|
||||
@@ -198,11 +219,11 @@ export class LocalMapsManagerService {
|
||||
|
||||
}
|
||||
|
||||
public async downloadMap(map: BsvMapDetail, version?: BSVersion){
|
||||
public async downloadMap(map: BsvMapDetail, version?: BSVersion): Promise<string>{
|
||||
|
||||
if(!map.versions.at(0).hash){ throw "Cannot download map, no hash found"; }
|
||||
|
||||
const zipUrl = `https://r2cdn.beatsaver.com/${map.versions.at(0).hash}.zip`
|
||||
const zipUrl = map.versions.at(0).downloadURL;
|
||||
|
||||
const mapsFolder = await this.getMapsFolderPath(version);
|
||||
|
||||
@@ -220,6 +241,8 @@ export class LocalMapsManagerService {
|
||||
await zip.close();
|
||||
|
||||
unlinkSync(zipPath);
|
||||
|
||||
return mapPath;
|
||||
}
|
||||
|
||||
public async exportMaps(version: BSVersion, maps: BsmLocalMap[], outPath: string){
|
||||
@@ -250,6 +273,32 @@ export class LocalMapsManagerService {
|
||||
|
||||
}
|
||||
|
||||
public async oneClickDownloadMap(map: BsvMapDetail): Promise<void>{
|
||||
|
||||
console.log("AALLLOO");
|
||||
|
||||
const downloadedMap = await this.downloadMap(map);
|
||||
|
||||
console.log(downloadedMap);
|
||||
|
||||
const versions = await this.localVersion.getInstalledVersions();
|
||||
|
||||
for(const version of versions){
|
||||
|
||||
if(await this.versionIsLinked(version)){ continue; }
|
||||
|
||||
const versionMapsPath = await this.getMapsFolderPath(version);
|
||||
|
||||
this.utils.createFolderIfNotExist(versionMapsPath);
|
||||
|
||||
console.log(downloadedMap, path.join(versionMapsPath, path.basename(downloadedMap)));
|
||||
|
||||
copySync(downloadedMap, path.join(versionMapsPath, path.basename(downloadedMap)), {overwrite: true});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public enableDeepLinks(): boolean{
|
||||
return Array.from(Object.values(this.DEEP_LINKS)).every(link => this.deepLink.registerDeepLink(link));
|
||||
}
|
||||
|
||||
@@ -89,6 +89,16 @@ export class BeatSaverApiService {
|
||||
|
||||
}
|
||||
|
||||
public async getMapDetailsById(id: string): Promise<ApiResult<BsvMapDetail>>{
|
||||
|
||||
const res = await fetch(`${this.bsaverApiUrl}/maps/id/${id}`);
|
||||
|
||||
const data = await res.json() as BsvMapDetail;
|
||||
|
||||
return {status: res.status, data};
|
||||
|
||||
}
|
||||
|
||||
public async searchMaps(search: SearchParams): Promise<ApiResult<SearchResponse>>{
|
||||
|
||||
console.log(search);
|
||||
|
||||
@@ -47,6 +47,13 @@ export class BeatSaverService {
|
||||
return mapDetails;
|
||||
}
|
||||
|
||||
public async getMapDetailsById(id: string): Promise<BsvMapDetail>{
|
||||
|
||||
const res = await this.bsaverApi.getMapDetailsById(id);
|
||||
return res.data;
|
||||
|
||||
}
|
||||
|
||||
public searchMaps(search: SearchParams): Promise<BsvMapDetail[]>{
|
||||
|
||||
return this.bsaverApi.searchMaps(search).then(res => {
|
||||
|
||||
@@ -12,7 +12,8 @@ export class WindowManagerService{
|
||||
|
||||
private readonly appWindowsOptions: Record<AppWindow, BrowserWindowConstructorOptions> = {
|
||||
"launcher.html": {width: 380, height: 500, minWidth: 380, minHeight: 500, resizable: false},
|
||||
"index.html": {width: 1080, height: 720, minWidth: 900, minHeight: 500}
|
||||
"index.html": {width: 1080, height: 720, minWidth: 900, minHeight: 500},
|
||||
"oneclick-download-map.html": {width: 350, height: 400, minWidth: 350, minHeight: 400, resizable: false}
|
||||
}
|
||||
|
||||
private readonly baseWindowOption: BrowserWindowConstructorOptions = {
|
||||
@@ -32,15 +33,18 @@ export class WindowManagerService{
|
||||
|
||||
private constructor(){}
|
||||
|
||||
public openWindow(windowType: AppWindow): Promise<BrowserWindow>{
|
||||
const window = new BrowserWindow({...this.appWindowsOptions[windowType], ...this.baseWindowOption});
|
||||
public openWindow(windowType: AppWindow, options?: BrowserWindowConstructorOptions): Promise<BrowserWindow>{
|
||||
const window = new BrowserWindow({...this.appWindowsOptions[windowType], ...this.baseWindowOption, ...options});
|
||||
|
||||
console.log({...this.appWindowsOptions[windowType], ...this.baseWindowOption, ...options});
|
||||
|
||||
const promise = window.loadURL(resolveHtmlPath(windowType));
|
||||
window.removeMenu();
|
||||
window.setMenu(null);
|
||||
|
||||
window.once("ready-to-show", () => {
|
||||
if (!window) { throw new Error('"window" is not defined'); }
|
||||
return window.show();
|
||||
window.show();
|
||||
});
|
||||
|
||||
window.once("closed", () => {
|
||||
|
||||
Reference in New Issue
Block a user