From 08bdc03745a104df964cf306e006244b17237a55 Mon Sep 17 00:00:00 2001 From: MathieuG-P <40181755+Zagrios@users.noreply.github.com> Date: Tue, 27 Feb 2024 22:52:18 +0100 Subject: [PATCH] [feature-107] Make playlist discoverable in shared tab + quik fix miss handle params in html file url --- release/app/package.json | 2 +- .../local-playlists-manager.service.ts | 23 ++++++++++--------- src/main/util.ts | 4 ++-- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/release/app/package.json b/release/app/package.json index 264d7c0d..242c90e1 100644 --- a/release/app/package.json +++ b/release/app/package.json @@ -1,6 +1,6 @@ { "name": "bs-manager", - "version": "1.4.4", + "version": "1.5.0", "description": "BSManager", "main": "./dist/main/main.js", "author": { diff --git a/src/main/services/additional-content/local-playlists-manager.service.ts b/src/main/services/additional-content/local-playlists-manager.service.ts index cc72ef0d..c51c75f1 100644 --- a/src/main/services/additional-content/local-playlists-manager.service.ts +++ b/src/main/services/additional-content/local-playlists-manager.service.ts @@ -10,14 +10,15 @@ import { WindowManagerService } from "../window-manager.service"; import { BPList, DownloadPlaylistProgressionData } from "shared/models/playlists/playlist.interface"; import { readFileSync } from "fs"; import { BeatSaverService } from "../thrid-party/beat-saver/beat-saver.service"; -import { copy, copyFile, pathExists, pathExistsSync, readdirSync, realpath } from "fs-extra"; -import { Progression, ensureFolderExist, pathExist } from "../../helpers/fs.helpers"; +import { copy, copyFile, ensureDir, pathExists, pathExistsSync, readdirSync, realpath } from "fs-extra"; +import { Progression, pathExist } from "../../helpers/fs.helpers"; import { FileAssociationService } from "../file-association.service"; import { SongDetailsCacheService } from "./maps/song-details-cache.service"; import { sToMs } from "shared/helpers/time.helpers"; import { LocalBPList, LocalBpListSong } from "shared/models/playlists/local-playlist.models"; import { SongCacheService } from "./maps/song-cache.service"; import { pathToFileURL } from "url"; +import { InstallationLocationService } from "../installation-location.service"; export class LocalPlaylistsManagerService { private static instance: LocalPlaylistsManagerService; @@ -43,6 +44,7 @@ export class LocalPlaylistsManagerService { private readonly bsaver: BeatSaverService; private readonly songDetails: SongDetailsCacheService; private readonly songCache: SongCacheService; + private readonly bsmFs: InstallationLocationService; private constructor() { this.maps = LocalMapsManagerService.getInstance(); @@ -54,6 +56,7 @@ export class LocalPlaylistsManagerService { this.bsaver = BeatSaverService.getInstance(); this.songDetails = SongDetailsCacheService.getInstance(); this.songCache = SongCacheService.getInstance(); + this.bsmFs = InstallationLocationService.getInstance(); this.deepLink.addLinkOpenedListener(this.DEEP_LINKS.BeatSaver, link => { @@ -70,17 +73,12 @@ export class LocalPlaylistsManagerService { } private async getPlaylistsFolder(version?: BSVersion) { - if (!version) { - throw new Error("Playlists are not available to be linked yet"); - } + const rootPath = version ? await this.versions.getVersionPath(version) : await this.bsmFs.sharedContentPath(); + const fullPath = path.join(rootPath, this.PLAYLISTS_FOLDER); - const versionFolder = await this.versions.getVersionPath(version); + await ensureDir(fullPath); - const folder = path.join(versionFolder, this.PLAYLISTS_FOLDER); - - await ensureFolderExist(folder); - - return folder; + return fullPath; } private async installBPListFile(bslistSource: string, version: BSVersion): Promise { @@ -156,6 +154,9 @@ export class LocalPlaylistsManagerService { } public getVersionPlaylists(version: BSVersion): Observable> { + + console.log("getVersionPlaylists", version); + return new Observable>(obs => { this.getPlaylistsFolder(version) .then(folder => this.readLocalBPListsOfFolder(folder, version)) diff --git a/src/main/util.ts b/src/main/util.ts index f7857f7b..c9dac068 100644 --- a/src/main/util.ts +++ b/src/main/util.ts @@ -1,5 +1,5 @@ /* eslint import/prefer-default-export: off, import/no-mutable-exports: off */ -import { URL, pathToFileURL } from "url"; +import { URL } from "url"; import path from "path"; export let resolveHtmlPath: (htmlFileName: string) => string; @@ -12,6 +12,6 @@ if (process.env.NODE_ENV === "development") { }; } else { resolveHtmlPath = (htmlFileName: string) => { - return pathToFileURL(path.resolve(__dirname, "../renderer/", htmlFileName)).href; + return `file://${path.resolve(__dirname, "../renderer/", htmlFileName)}`; }; }