mirror of
https://github.com/Zagrios/bs-manager.git
synced 2026-07-03 14:08:25 +02:00
we can now enable deep links for playlists
This commit is contained in:
@@ -14,4 +14,49 @@ ipcMain.on("one-click-install-playlist", async (event, request: IpcRequest<strin
|
||||
console.log(e);
|
||||
utils.ipcSend(request.responceChannel, {success: false, error: e});
|
||||
});
|
||||
});
|
||||
|
||||
ipcMain.on("register-playlists-deep-link", async (event, request: IpcRequest<void>) => {
|
||||
|
||||
const maps = LocalPlaylistsManagerService.getInstance();
|
||||
const utils = UtilsService.getInstance();
|
||||
|
||||
try{
|
||||
const res = maps.enableDeepLinks();
|
||||
utils.ipcSend(request.responceChannel, {success: true, data: res});
|
||||
}
|
||||
catch(e){
|
||||
utils.ipcSend(request.responceChannel, {success: false});
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
ipcMain.on("unregister-playlists-deep-link", async (event, request: IpcRequest<void>) => {
|
||||
|
||||
const maps = LocalPlaylistsManagerService.getInstance();
|
||||
const utils = UtilsService.getInstance();
|
||||
|
||||
try{
|
||||
const res = maps.disableDeepLinks();
|
||||
utils.ipcSend(request.responceChannel, {success: true, data: res});
|
||||
}
|
||||
catch(e){
|
||||
utils.ipcSend(request.responceChannel, {success: false});
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
ipcMain.on("is-playlists-deep-links-enabled", async (event, request: IpcRequest<void>) => {
|
||||
|
||||
const maps = LocalPlaylistsManagerService.getInstance();
|
||||
const utils = UtilsService.getInstance();
|
||||
|
||||
try{
|
||||
const res = maps.isDeepLinksEnabled();
|
||||
utils.ipcSend(request.responceChannel, {success: true, data: res});
|
||||
}
|
||||
catch(e){
|
||||
utils.ipcSend(request.responceChannel, {success: false});
|
||||
}
|
||||
|
||||
});
|
||||
@@ -15,7 +15,6 @@ import { BPList, DownloadPlaylistProgression } from "shared/models/playlists/pla
|
||||
import { copyFileSync, readFileSync } from "fs";
|
||||
import { BeatSaverService } from "../thrid-party/beat-saver/beat-saver.service";
|
||||
import { copySync } from "fs-extra";
|
||||
import { timer } from "rxjs";
|
||||
|
||||
export class LocalPlaylistsManagerService {
|
||||
|
||||
@@ -116,8 +115,7 @@ export class LocalPlaylistsManagerService {
|
||||
|
||||
private openOneClickDownloadPlaylistWindow(downloadUrl: string): void{
|
||||
|
||||
// TODO make once
|
||||
ipcMain.on("one-click-playlist-info", async (event, req: IpcRequest<void>) => {
|
||||
ipcMain.once("one-click-playlist-info", async (event, req: IpcRequest<void>) => {
|
||||
this.utils.ipcSend(req.responceChannel, {success: true, data: {bpListUrl: downloadUrl, id: this.getPlaylistIdFromDownloadUrl(downloadUrl)}});
|
||||
});
|
||||
|
||||
@@ -213,4 +211,16 @@ export class LocalPlaylistsManagerService {
|
||||
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -28,6 +28,7 @@ import beastSaberIcon from "../../../assets/images/third-party-icons/beast-saber
|
||||
import scoreSaberIcon from "../../../assets/images/third-party-icons/score-saber.png";
|
||||
import Tippy from '@tippyjs/react';
|
||||
import { MapsManagerService } from "renderer/services/maps-manager.service";
|
||||
import { PlaylistsManagerService } from "renderer/services/playlists-manager.service";
|
||||
|
||||
export function SettingsPage() {
|
||||
|
||||
@@ -42,6 +43,7 @@ export function SettingsPage() {
|
||||
const i18nService: I18nService = I18nService.getInstance();
|
||||
const linkOpener: LinkOpenerService = LinkOpenerService.getInstance();
|
||||
const mapsManager = MapsManagerService.getInstance();
|
||||
const playlistsManager = PlaylistsManagerService.getInstance();
|
||||
|
||||
const {firstColor, secondColor} = useThemeColor();
|
||||
const sessionExist = useObservable(authService.sessionExist$);
|
||||
@@ -61,6 +63,7 @@ export function SettingsPage() {
|
||||
const [installationFolder, setInstallationFolder] = useState(null);
|
||||
const [showSupporters, setShowSupporters] = useState(false);
|
||||
const [mapDeepLinksEnabled, setMapDeepLinksEnabled] = useState(false);
|
||||
const [playlistsDeepLinkEnabled, setPlaylistsDeeppLinkEnabled] = useState(false)
|
||||
const [appVersion, setAppVersion] = useState("");
|
||||
const nav = useNavigate();
|
||||
|
||||
@@ -68,6 +71,7 @@ export function SettingsPage() {
|
||||
loadInstallationFolder();
|
||||
ipcService.send<string>("current-version").then(res => setAppVersion(res.data));
|
||||
mapsManager.isDeepLinksEnabled().then(enabled => setMapDeepLinksEnabled(() => enabled));
|
||||
playlistsManager.isDeepLinksEnabled().then(enabled => setPlaylistsDeeppLinkEnabled(() => enabled));
|
||||
}, []);
|
||||
|
||||
const resetColors = () => {
|
||||
@@ -144,6 +148,10 @@ export function SettingsPage() {
|
||||
mapsManager.toogleDeepLinks().finally(() => mapsManager.isDeepLinksEnabled().then(enabled => setMapDeepLinksEnabled(() => enabled)));
|
||||
}
|
||||
|
||||
const tooglePlaylistsDeepLinks = () => {
|
||||
playlistsManager.toogleDeepLinks().finally(() => playlistsManager.isDeepLinksEnabled().then(enabled => setPlaylistsDeeppLinkEnabled(() => enabled)));
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="w-full h-full flex justify-center overflow-y-scroll scrollbar-thin scrollbar-thumb-rounded-full scrollbar-thumb-neutral-900 text-gray-800 dark:text-gray-200">
|
||||
|
||||
@@ -202,7 +210,7 @@ export function SettingsPage() {
|
||||
</li>
|
||||
<li className="bg-main-color-1 rounded-md group-one flex justify-between items-center basis-0 py-2 px-3">
|
||||
<div className="flex items-center gap-2">
|
||||
<BsmCheckbox className="relative z-[1] h-5 w-5"/>
|
||||
<BsmCheckbox className="relative z-[1] h-5 w-5" onChange={tooglePlaylistsDeepLinks} checked={playlistsDeepLinkEnabled}/>
|
||||
<span className="font-extrabold">Playlists</span>
|
||||
</div>
|
||||
<div className="flex h-full">
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
import { IpcService } from "./ipc.service";
|
||||
|
||||
export class PlaylistsManagerService {
|
||||
|
||||
private static instance: PlaylistsManagerService;
|
||||
|
||||
public static getInstance(): PlaylistsManagerService{
|
||||
if(!PlaylistsManagerService.instance){ PlaylistsManagerService.instance = new PlaylistsManagerService(); }
|
||||
return PlaylistsManagerService.instance;
|
||||
}
|
||||
|
||||
private readonly ipc: IpcService;
|
||||
|
||||
private constructor(){
|
||||
this.ipc = IpcService.getInstance();
|
||||
}
|
||||
|
||||
public isDeepLinksEnabled(): Promise<boolean>{
|
||||
return this.ipc.send<boolean>("is-playlists-deep-links-enabled").then(res => (
|
||||
res.success ? res.data : false
|
||||
));
|
||||
}
|
||||
|
||||
public async toogleDeepLinks(): Promise<boolean>{
|
||||
|
||||
const isEnabled = await this.isDeepLinksEnabled();
|
||||
|
||||
const channel = isEnabled ? "unregister-playlists-deep-link" : "register-playlists-deep-link";
|
||||
|
||||
const res = await this.ipc.send<boolean>(channel);
|
||||
|
||||
return res.success ? res.data : false;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user