mirror of
https://github.com/Zagrios/bs-manager.git
synced 2026-07-03 14:08:25 +02:00
advence on oneclic playlist
This commit is contained in:
@@ -10,6 +10,7 @@ import ReactRefreshWebpackPlugin from '@pmmmwh/react-refresh-webpack-plugin';
|
||||
import baseConfig from './webpack.config.base';
|
||||
import webpackPaths from './webpack.paths';
|
||||
import checkNodeEnv from '../scripts/check-node-env';
|
||||
import { AppWindow } from "../../src/shared/models/window-manager/app-window.model"
|
||||
|
||||
// When an ESLint server is running, we can't set the NODE_ENV so we'll check if it's
|
||||
// at the dev webpack config is not accidentally run in a production environment
|
||||
@@ -39,10 +40,10 @@ if (
|
||||
execSync('npm run postinstall');
|
||||
}
|
||||
|
||||
const getHtmlPageOptions = (page: string): HtmlWebpackPlugin.Options => {
|
||||
const getHtmlPageOptions = (page: AppWindow): HtmlWebpackPlugin.Options => {
|
||||
return {
|
||||
filename: path.join(`${page}.html`),
|
||||
template: path.join(webpackPaths.srcRendererPath, `${page}.ejs`),
|
||||
filename: path.join(page),
|
||||
template: path.join(webpackPaths.srcRendererPath, page.replace(".html", ".ejs")),
|
||||
minify: {
|
||||
collapseWhitespace: true,
|
||||
removeAttributeQuotes: true,
|
||||
@@ -163,9 +164,10 @@ const configuration: webpack.Configuration = {
|
||||
|
||||
new ReactRefreshWebpackPlugin(),
|
||||
|
||||
new HtmlWebpackPlugin(getHtmlPageOptions("index")),
|
||||
new HtmlWebpackPlugin(getHtmlPageOptions("launcher")),
|
||||
new HtmlWebpackPlugin(getHtmlPageOptions("oneclick-download-map")),
|
||||
new HtmlWebpackPlugin(getHtmlPageOptions("index.html")),
|
||||
new HtmlWebpackPlugin(getHtmlPageOptions("launcher.html")),
|
||||
new HtmlWebpackPlugin(getHtmlPageOptions("oneclick-download-map.html")),
|
||||
new HtmlWebpackPlugin(getHtmlPageOptions("oneclick-download-playlist.html")),
|
||||
|
||||
],
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ import baseConfig from './webpack.config.base';
|
||||
import webpackPaths from './webpack.paths';
|
||||
import checkNodeEnv from '../scripts/check-node-env';
|
||||
import deleteSourceMaps from '../scripts/delete-source-maps';
|
||||
import { AppWindow } from "../../src/shared/models/window-manager/app-window.model"
|
||||
|
||||
checkNodeEnv('production');
|
||||
deleteSourceMaps();
|
||||
@@ -26,17 +27,19 @@ const devtoolsConfig =
|
||||
: {};
|
||||
|
||||
|
||||
const getHtmlPageOptions = (page: string): HtmlWebpackPlugin.Options => {
|
||||
const getHtmlPageOptions = (page: AppWindow): HtmlWebpackPlugin.Options => {
|
||||
return {
|
||||
filename: `${page}.html`,
|
||||
template: path.join(webpackPaths.srcRendererPath, `${page}.ejs`),
|
||||
filename: path.join(page),
|
||||
template: path.join(webpackPaths.srcRendererPath, page.replace(".html", ".ejs")),
|
||||
minify: {
|
||||
collapseWhitespace: true,
|
||||
removeAttributeQuotes: true,
|
||||
removeComments: true,
|
||||
},
|
||||
isBrowser: false,
|
||||
env: process.env.NODE_ENV,
|
||||
isDevelopment: process.env.NODE_ENV !== 'production',
|
||||
nodeModules: webpackPaths.appNodeModulesPath,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,9 +146,10 @@ const configuration: webpack.Configuration = {
|
||||
analyzerMode: process.env.ANALYZE === 'true' ? 'server' : 'disabled',
|
||||
}),
|
||||
|
||||
new HtmlWebpackPlugin(getHtmlPageOptions("index")),
|
||||
new HtmlWebpackPlugin(getHtmlPageOptions("launcher")),
|
||||
new HtmlWebpackPlugin(getHtmlPageOptions("oneclick-download-map")),
|
||||
new HtmlWebpackPlugin(getHtmlPageOptions("index.html")),
|
||||
new HtmlWebpackPlugin(getHtmlPageOptions("launcher.html")),
|
||||
new HtmlWebpackPlugin(getHtmlPageOptions("oneclick-download-map.html")),
|
||||
new HtmlWebpackPlugin(getHtmlPageOptions("oneclick-download-playlist.html")),
|
||||
|
||||
],
|
||||
};
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
export function isValidUrl(url: string): boolean{
|
||||
try{
|
||||
new URL(url);
|
||||
return true;
|
||||
}
|
||||
catch(e){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -89,7 +89,7 @@ else{
|
||||
|
||||
app.whenReady().then(() => {
|
||||
|
||||
// process.argv.push("web+bsmap://BDE6A1F8FC7008247443CF3F810BBD8E910DD839"); to force deep-link (oneClick map)
|
||||
process.argv.push("bsplaylist://playlist/https://api.beatsaver.com/playlists/id/11137/download/beatsaver-11137.bplist"); // to force deep-link (oneClick map)
|
||||
|
||||
initServicesMustBeInitialized();
|
||||
|
||||
|
||||
@@ -138,12 +138,12 @@ export class LocalMapsManagerService {
|
||||
}
|
||||
|
||||
private openOneClickDownloadMapWindow(mapId: string, isHash = false): void{
|
||||
|
||||
this.windows.openWindow("oneclick-download-map.html");
|
||||
|
||||
ipcMain.once("one-click-map-info", async (event, req: IpcRequest<void>) => {
|
||||
this.utils.ipcSend(req.responceChannel, {success: true, data: {id: mapId, isHash}});
|
||||
});
|
||||
|
||||
this.windows.openWindow("oneclick-download-map.html");
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -4,9 +4,17 @@ import { Observable } from "rxjs";
|
||||
import { BSVersion } from "shared/bs-version.interface";
|
||||
import { BsvPlaylist, BsvPlaylistPage } from "shared/models/maps/beat-saver.model";
|
||||
import { BSLocalVersionService } from "../bs-local-version.service";
|
||||
import { DeepLinkService } from "../deep-link.service";
|
||||
import { RequestService } from "../request.service";
|
||||
import { UtilsService } from "../utils.service";
|
||||
import { LocalMapsManagerService } from "./local-maps-manager.service";
|
||||
import log from "electron-log"
|
||||
import { isValidUrl } from "../../helpers/url.helpers";
|
||||
import { ipcMain } from "electron";
|
||||
import { WindowManagerService } from "../window-manager.service";
|
||||
import { IpcRequest } from "shared/models/ipc";
|
||||
import { BPList } from "shared/models/playlists/playlist.interface";
|
||||
import { readFileSync } from "fs";
|
||||
|
||||
export class LocalPlaylistsManagerService {
|
||||
|
||||
@@ -25,19 +33,40 @@ export class LocalPlaylistsManagerService {
|
||||
|
||||
private readonly versions: BSLocalVersionService;
|
||||
private readonly maps: LocalMapsManagerService;
|
||||
public readonly utils: UtilsService;
|
||||
public readonly request: RequestService;
|
||||
private readonly utils: UtilsService;
|
||||
private readonly request: RequestService;
|
||||
private readonly deepLink: DeepLinkService;
|
||||
private readonly windows: WindowManagerService;
|
||||
|
||||
private constructor(){
|
||||
this.maps = LocalMapsManagerService.getInstance();
|
||||
this.versions = BSLocalVersionService.getInstance();
|
||||
this.utils = UtilsService.getInstance();
|
||||
this.request = RequestService.getInstance();
|
||||
this.deepLink = DeepLinkService.getInstance();
|
||||
this.windows = WindowManagerService.getInstance();
|
||||
|
||||
this.deepLink.addLinkOpenedListener(this.DEEP_LINKS.BeatSaver, link => {
|
||||
log.info("DEEP-LINK RECEIVED FROM", this.DEEP_LINKS.BeatSaver, link);
|
||||
const url = new URL(link);
|
||||
const bplistUrl = url.host === "playlist" ? url.pathname.replace("/", "") : "";
|
||||
const playlistId = this.getPlaylistIdFromDownloadUrl(bplistUrl);
|
||||
|
||||
this.openOneClickDownloadPlaylistWindow(playlistId);
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private getPlaylistIdFromDownloadUrl(url: string): string{
|
||||
|
||||
if(!isValidUrl(url)){ return ""; }
|
||||
|
||||
const splited = url.split("/")
|
||||
const idIndex = splited.indexOf("id");
|
||||
|
||||
if(idIndex < 0){ return ""; }
|
||||
|
||||
return splited[idIndex + 1];
|
||||
}
|
||||
|
||||
@@ -52,6 +81,26 @@ export class LocalPlaylistsManagerService {
|
||||
|
||||
}
|
||||
|
||||
private async readPlaylistFile(path: string): Promise<BPList>{
|
||||
|
||||
if(!this.utils.pathExist(path)){ return null; }
|
||||
|
||||
const content = readFileSync(path).toJSON();
|
||||
|
||||
|
||||
// TODO
|
||||
}
|
||||
|
||||
private openOneClickDownloadPlaylistWindow(playlistId: string): void{
|
||||
|
||||
ipcMain.once("one-click-playlist-info", async (event, req: IpcRequest<void>) => {
|
||||
this.utils.ipcSend(req.responceChannel, {success: true, data: playlistId});
|
||||
});
|
||||
|
||||
this.windows.openWindow("oneclick-download-playlist.html");
|
||||
|
||||
}
|
||||
|
||||
public downloadPlaylist(playlistPage: BsvPlaylistPage, version: BSVersion): Observable<string[]>{
|
||||
|
||||
const res = new BehaviorSubject<string[]>([]);
|
||||
|
||||
@@ -13,7 +13,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},
|
||||
"oneclick-download-map.html": {width: 350, height: 400, minWidth: 350, minHeight: 400, resizable: false}
|
||||
"oneclick-download-map.html": {width: 350, height: 400, minWidth: 350, minHeight: 400, resizable: false},
|
||||
"oneclick-download-playlist.html": {width: 350, height: 400, minWidth: 350, minHeight: 400, resizable: false},
|
||||
}
|
||||
|
||||
private readonly baseWindowOption: BrowserWindowConstructorOptions = {
|
||||
|
||||
@@ -6,15 +6,20 @@ import Launcher from './windows/Launcher';
|
||||
import 'tailwindcss/tailwind.css';
|
||||
import './index.css'
|
||||
import OneClickDownloadMap from './windows/OneClick/OneClickDownloadMap';
|
||||
import OneClickDownloadPlaylist from './windows/OneClick/OneClickDownloadPlaylist';
|
||||
|
||||
const launcherContainer = document.getElementById('launcher');
|
||||
const oneclickDownloadMapContainer = document.getElementById('oneclick-download-map');
|
||||
const oneclickDownloadPlaylistContainer = document.getElementById('oneclick-download-playlist');
|
||||
|
||||
if(!!launcherContainer){
|
||||
createRoot(launcherContainer).render(<Launcher/>)
|
||||
createRoot(launcherContainer).render(<Launcher/>);
|
||||
}
|
||||
else if(!!oneclickDownloadMapContainer){
|
||||
createRoot(oneclickDownloadMapContainer).render(<OneClickDownloadMap/>)
|
||||
createRoot(oneclickDownloadMapContainer).render(<OneClickDownloadMap/>);
|
||||
}
|
||||
else if(!!oneclickDownloadPlaylistContainer){
|
||||
createRoot(oneclickDownloadPlaylistContainer).render(<OneClickDownloadPlaylist/>);
|
||||
}
|
||||
else{
|
||||
const root = document.getElementById('root');
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<link rel="stylesheet" href="https://use.typekit.net/okr8ven.css">
|
||||
<meta charset="utf-8" />
|
||||
<meta
|
||||
http-equiv="Content-Security-Policy"
|
||||
content="script-src 'self' 'unsafe-inline'"
|
||||
/>
|
||||
</head>
|
||||
<body>
|
||||
<div id="oneclick-download-playlist"></div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -19,7 +19,6 @@ export default function OneClickDownloadMap() {
|
||||
const mapsDownloader = MapsDownloaderService.getInstance();
|
||||
const themeService = ThemeService.getInstance();
|
||||
const progressBar = ProgressBarService.getInstance();
|
||||
const windows = WindowManagerService.getInstance();
|
||||
|
||||
const [mapInfo, setMapInfo] = useState<BsvMapDetail>(null);
|
||||
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
export default function OneClickDownloadPlaylist() {
|
||||
return (
|
||||
<div>OneClickDownloadPlaylist</div>
|
||||
)
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
export interface Playlist {
|
||||
export interface BPList {
|
||||
playlistTitle: string,
|
||||
playlistAuthor: string,
|
||||
playlistDescription?: string,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
export type AppWindow = (
|
||||
"index.html" |
|
||||
"launcher.html" |
|
||||
"oneclick-download-map.html"
|
||||
"oneclick-download-map.html"|
|
||||
"oneclick-download-playlist.html"
|
||||
);
|
||||
Reference in New Issue
Block a user