mirror of
https://github.com/Zagrios/bs-manager.git
synced 2026-07-03 14:08:25 +02:00
Compare commits
19 Commits
v1.0.0
...
v1.0.2-alpha.1
| Author | SHA1 | Date | |
|---|---|---|---|
| 6b2879d9dc | |||
| 19e842d721 | |||
| 8d28c3cfc8 | |||
| baec206bf3 | |||
| 3aacd7575b | |||
| d739245e70 | |||
| c88d93b0ab | |||
| 64280509b0 | |||
| a7e81cfa8a | |||
| 2620354888 | |||
| 61a8790448 | |||
| 5b4af58baa | |||
| 6cd3c65362 | |||
| 211a3b9a39 | |||
| a4fd92a014 | |||
| 295d0f90ba | |||
| 5592242963 | |||
| 0212f3ba26 | |||
| 36521a2b1b |
@@ -84,7 +84,7 @@
|
||||
}
|
||||
},
|
||||
"available-versions": {
|
||||
"title": "Choisi une version",
|
||||
"title": "Choisis une version",
|
||||
"steam-release": "Notes de version",
|
||||
"dropdown": {
|
||||
"refresh": "Rafraichir la liste",
|
||||
@@ -99,7 +99,7 @@
|
||||
},
|
||||
"appearance": {
|
||||
"title": "Apparence",
|
||||
"description": "Choisi les deux couleurs principales de BSManager.",
|
||||
"description": "Choisis les deux couleurs principales de BSManager.",
|
||||
"reset": "Réinitialiser",
|
||||
"sub-title": "Thème",
|
||||
"themes": {
|
||||
@@ -115,7 +115,7 @@
|
||||
},
|
||||
"additional-content": {
|
||||
"title": "Contenus additionnels",
|
||||
"description": "Les contenus additionnels te permet de personaliser BeatSaber !",
|
||||
"description": "Les contenus additionnels te permettent de personaliser Beat Saber!",
|
||||
"deep-links": {
|
||||
"sub-title": "Installations OneClick"
|
||||
}
|
||||
@@ -138,7 +138,7 @@
|
||||
},
|
||||
"patreon": {
|
||||
"title": "Soutenir BSManager 💖",
|
||||
"description": "Soutien le projet et aide-nous à fournir des améliorations continues à BSManager.",
|
||||
"description": "Soutiens le projet et aide-nous à fournir des améliorations continues à BSManager.",
|
||||
"buttons": {
|
||||
"support": "Soutenir BSManager 🥰",
|
||||
"supporters": "Supporteurs 👀"
|
||||
@@ -170,7 +170,7 @@
|
||||
},
|
||||
"common": {
|
||||
"msg": {
|
||||
"error-occurred": "Une erreur c'est produite"
|
||||
"error-occurred": "Une erreur s'est produite"
|
||||
}
|
||||
},
|
||||
"shared": {
|
||||
@@ -180,8 +180,8 @@
|
||||
"no-internet": "Pas d'internet"
|
||||
},
|
||||
"msg": {
|
||||
"operation-running": "Attend la fin de l'opération en cours puis recommences.",
|
||||
"no-internet": "Verifie t'a connexion internet et recommence."
|
||||
"operation-running": "Attends la fin de l'opération en cours puis recommence.",
|
||||
"no-internet": "Verifie ta connexion internet et recommence."
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -194,11 +194,11 @@
|
||||
},
|
||||
"warnings": {
|
||||
"msg": {
|
||||
"ManifestChecksum": "Le manifest télécharger précédemment ne correspond pas au nouveau 🤔",
|
||||
"ManifestChecksum": "Le manifest téléchargé précédemment ne correspond pas au nouveau 🤔",
|
||||
"ConnectionTimeout": "Ta connexion internet semble instable 🥶",
|
||||
"ConnectionLost": "La connexion a été perdue, retentative...",
|
||||
"ConnectionError": "Impossible de se connecter à Steam, retentative...",
|
||||
"Unknown": "Quelque chose d'étrange c'est produit 🤔 Votre connexion est surement instable."
|
||||
"ConnectionLost": "La connexion a été perdue, nouvelle tentative...",
|
||||
"ConnectionError": "Impossible de se connecter à Steam, nouvelle tentative...",
|
||||
"Unknown": "Quelque chose d'étrange s'est produit 🤔 Votre connexion est surement instable."
|
||||
}
|
||||
},
|
||||
"errors": {
|
||||
@@ -206,31 +206,31 @@
|
||||
"dotnet-required": ".NET 6 Requis"
|
||||
},
|
||||
"msg": {
|
||||
"401": "Steam semble pas vouloir nous laisser télécharger BeatSaber 😢",
|
||||
"401": "Steam ne semble pas vouloir nous laisser télécharger Beat Saber 😢",
|
||||
"404": "Impossible de contacter les serveurs de Steam.",
|
||||
"Password": "Le mot de passe est invalide.",
|
||||
"InvalidCredentials": "Ton e-mail ou mot de passe est invalide 😴",
|
||||
"InvalidPassword": "Ton mot de passe est invalide 😕",
|
||||
"NoManifest": "Aucun manifest n'a été trouvé.",
|
||||
"DirectoryCreate": "Impossible d'installer les dossiers nécessaires.",
|
||||
"NotAvailableApp": "Tu essayes de télécharger BeatSaber alors que tu ne l'as pas ? 🤣",
|
||||
"DepotNotFound": "Impossible de télécharger BeatSaber 😥 réessaye plus tard 😕",
|
||||
"NotAvailableApp": "Tu essayes de télécharger Beat Saber alors que tu ne l'as pas ? 🤣",
|
||||
"DepotNotFound": "Impossible de télécharger Beat Saber 😥 réessaye plus tard 😕",
|
||||
"NotCompleted": "Le téléchargement n'a pas pu se terminer ¯\\_(ツ)_/¯",
|
||||
"InvalidManifest": "Impossible de télécharger BeatSaber 😥 réessaye plus tard 😕",
|
||||
"NoValidKey": "Impossible de télécharger BeatSaber 😥 réessaye plus tard 😕",
|
||||
"NoManifestCode": "Impossible de télécharger BeatSaber 😥 réessaye plus tard 😕",
|
||||
"Unknown": "Une erreur inconnue c'est produite ¯\\_(ツ)_/¯",
|
||||
"InvalidManifest": "Impossible de télécharger Beat Saber 😥 réessaye plus tard 😕",
|
||||
"NoValidKey": "Impossible de télécharger Beat Saber 😥 réessaye plus tard 😕",
|
||||
"NoManifestCode": "Impossible de télécharger Beat Saber 😥 réessaye plus tard 😕",
|
||||
"Unknown": "Une erreur inconnue s'est produite ¯\\_(ツ)_/¯",
|
||||
"NoServer": "Impossible de contacter les serveurs de Steam.",
|
||||
"NotAllowed": "Apparemment tu n'es pas autorisé à télécharger BeatSaber 🥱",
|
||||
"NotAllowed": "Apparemment tu n'es pas autorisé à télécharger Beat Saber 🥱",
|
||||
"ConnectionTimeout": "Impossible de se connecter à Steam 😕",
|
||||
"SteamLib": "Si tu à cette erreur, report le bug sur GitHub avec les logs stp.",
|
||||
"SteamLib": "Si tu as cette erreur, signale le bug sur GitHub avec les logs stp.",
|
||||
"ConnectionError": "Impossible de se connecter à Steam après 10 essais 🤯",
|
||||
"LicenceError": "Impossible d'obtenir la liste des licences.",
|
||||
"verification-failed": "La vérification a échoué, réessaye plus tard.",
|
||||
"RateLimitExceeded": "Tu as essayé trop de fois attend un peu et recommence plus tard.",
|
||||
"RateLimitExceeded": "Tu as essayé trop de fois attends un peu et recommence plus tard.",
|
||||
"AlreadyDownloading": "Un téléchargement est déjà en cours",
|
||||
"no-internet": "Pas de connexion internet.",
|
||||
"dotnet-required": ".NET 6 Runtime doit être installé pour pouvoir télécharger une version de BeatSaber. Télécharge-le en cliquant sur le bouton ci-dessous."
|
||||
"dotnet-required": ".NET 6 Runtime doit être installé pour pouvoir télécharger une version de Beat Saber. Télécharge-le en cliquant sur le bouton ci-dessous."
|
||||
},
|
||||
"actions":{
|
||||
"download-dotnet": "Télécharger .NET 6"
|
||||
@@ -249,7 +249,7 @@
|
||||
},
|
||||
"errors":{
|
||||
"import-error":{
|
||||
"desc": "Vérifier que le dossier sélectionné est une installation de BeatSaber."
|
||||
"desc": "Vérifier que le dossier sélectionné est une installation de Beat Saber."
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -316,14 +316,14 @@
|
||||
"UNABLE_TO_LAUNCH": "Lancement impossible",
|
||||
"STEAM_NOT_RUNNING": "Steam n'est pas lancé",
|
||||
"OCULUS_NOT_RUNNING": "Oculus n'est pas lancé",
|
||||
"BS_ALREADY_RUNNING": "BeatSaber est déjà lancé",
|
||||
"BS_ALREADY_RUNNING": "Beat Saber est déjà lancé",
|
||||
"EXE_NOT_FINDED": "Fichiers manquants",
|
||||
"EXIT": "Arrêt brutal"
|
||||
},
|
||||
"msg": {
|
||||
"STEAM_NOT_RUNNING": "Steam doit être en cours d'exécution pour lancer BeatSaber.",
|
||||
"OCULUS_NOT_RUNNING": "Oculus doit être en cours d'exécution pour lancer BeatSaber.",
|
||||
"BS_ALREADY_RUNNING": "Ferme BeatSaber avant de le lancer à nouveau.",
|
||||
"STEAM_NOT_RUNNING": "Steam doit être en cours d'exécution pour lancer Beat Saber.",
|
||||
"OCULUS_NOT_RUNNING": "Oculus doit être en cours d'exécution pour lancer Beat Saber.",
|
||||
"BS_ALREADY_RUNNING": "Ferme Beat Saber avant de le lancer à nouveau.",
|
||||
"EXE_NOT_FINDED": "Quelques fichiers semblent manquants. Essaye de vérifier les fichiers.",
|
||||
"EXIT": "BeatSaber s'est arrêté brusquement, essaye de vérifier les fichiers."
|
||||
},
|
||||
@@ -347,12 +347,12 @@
|
||||
"CantClone": "Clonage impossible"
|
||||
},
|
||||
"msg": {
|
||||
"CantEditSteam": "Tu ne peut pas éditer la version Steam. Tu peut la cloner par contre."
|
||||
"CantEditSteam": "Tu ne peux pas éditer la version Steam. Tu peux la cloner par contre."
|
||||
}
|
||||
},
|
||||
"success": {
|
||||
"titles": {
|
||||
"CloningFinished": "Clonage terminer 🎉"
|
||||
"CloningFinished": "Clonage terminé 🎉"
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -363,10 +363,10 @@
|
||||
"warning": "Mods installés 🤔"
|
||||
},
|
||||
"msg": {
|
||||
"success": "Tous les mods on été installés.",
|
||||
"success": "Tous les mods ont été installés.",
|
||||
"warning": "Un ou plusieurs mods n'ont pas pu être installés.",
|
||||
"errors": {
|
||||
"no-mods": "Aucun mods à installer.",
|
||||
"no-mods": "Aucun mod à installer.",
|
||||
"cannot-install-bsipa": "L'installation de BSIPA à échoué 😨"
|
||||
}
|
||||
}
|
||||
@@ -386,7 +386,7 @@
|
||||
"success": "Mods désintallés 🎉"
|
||||
},
|
||||
"msg": {
|
||||
"success": "Tous les mods on été désintallés.",
|
||||
"success": "Tous les mods ont été désintallés.",
|
||||
"errors": {
|
||||
"no-mods": "Aucun mod n'est installé dans dans cette version 😑"
|
||||
}
|
||||
@@ -456,14 +456,14 @@
|
||||
},
|
||||
"bs-uninstall": {
|
||||
"title": "Désinstaller",
|
||||
"description": "Est-tu sûr de vouloir désinstaller BeatSaber {version} ? Tu vas devoir la retélécharger pour y jouer.",
|
||||
"description": "Es-tu sûr de vouloir désinstaller Beat Saber {version} ? Tu vas devoir la retélécharger pour y jouer.",
|
||||
"buttons": {
|
||||
"submit": "Désinstaller"
|
||||
}
|
||||
},
|
||||
"install-folder": {
|
||||
"title": "Dossier d'installation",
|
||||
"description": "Changer le dossier d'installation par défaut, va engendrer le déplacement de toutes les données installer vers le nouveau dossier.",
|
||||
"description": "Changer le dossier d'installation par défaut, cela va engendrer le déplacement de toutes les données installer vers le nouveau dossier.",
|
||||
"buttons": {
|
||||
"submit": "Choisir un dossier"
|
||||
}
|
||||
@@ -506,12 +506,12 @@
|
||||
"multiple": "Supprimer les maps ?"
|
||||
},
|
||||
"desc": {
|
||||
"single": "Est-tu sur de vouloir supprimer la map {name} ?",
|
||||
"multiple": "Est-tu sur de vouloir supprimer les {nb} maps ?"
|
||||
"single": "Es-tu sur de vouloir supprimer la map {name} ?",
|
||||
"multiple": "Es-tu sur de vouloir supprimer les {nb} maps ?"
|
||||
},
|
||||
"info": {
|
||||
"desc": {
|
||||
"single": "Cette map fait partie des maps paratagées",
|
||||
"single": "Cette map fait partie des maps partagées",
|
||||
"multiple": "Ces maps font parties des maps partagées"
|
||||
},
|
||||
"title": {
|
||||
@@ -552,7 +552,7 @@
|
||||
"li-1": "Vous pouvez rencontrer des problèmes qui n'existent pas dans le jeu de base. 99.9% des bugs, plantages et ralentissements sont dus aux mods.",
|
||||
"li-2": "Les mods sont susceptibles de ne plus fonctionner à cause des mises à jour et c'est normal - soyez patient et respectueux lorsque cela se produit, parce que les moddeurs sont bénévoles et ont une vie.",
|
||||
"li-3": "Beat Games ne cherche pas volontairement à casser les mods. Ils souhaitent améliorer la base du jeu et parfois cela casse les mods, mais ce n'est pas dans leur objectif de tuer les mods.",
|
||||
"p-2": "N'attaquez pas les développeurs pour des problèmes relatifs aux mods, et inversement - les moddeurs et les développeurs sont deux groupes distincts. Ne sois pas idiot, d'accord ?"
|
||||
"p-2": "N'attaquez pas les développeurs pour des problèmes relatifs aux mods, et inversement - les moddeurs et les développeurs sont deux groupes distincts. Ne soyez pas idiots, d'accord ?"
|
||||
}
|
||||
},
|
||||
"maps": {
|
||||
@@ -694,4 +694,4 @@
|
||||
"PM"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Generated
+426
-153
File diff suppressed because it is too large
Load Diff
@@ -226,6 +226,9 @@
|
||||
"dependencies": {
|
||||
"@node-steam/vdf": "^2.2.0",
|
||||
"@tippyjs/react": "^4.2.6",
|
||||
"@types/react-virtualized-auto-sizer": "^1.0.1",
|
||||
"@types/react-window": "^1.8.5",
|
||||
"@types/recursive-readdir": "^2.2.1",
|
||||
"archiver": "^5.3.1",
|
||||
"dateformat": "^5.0.3",
|
||||
"dot-prop": "^7.2.0",
|
||||
@@ -246,6 +249,9 @@
|
||||
"react-dom": "^18.2.0",
|
||||
"react-range": "^1.8.14",
|
||||
"react-router-dom": "^6.3.0",
|
||||
"react-virtualized-auto-sizer": "^1.0.7",
|
||||
"react-window": "^1.8.8",
|
||||
"recursive-readdir": "^2.2.3",
|
||||
"regedit": "^5.1.1",
|
||||
"rfdc": "^1.3.0",
|
||||
"rxjs": "^7.5.6",
|
||||
|
||||
Generated
+1228
-10
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "bs-manager",
|
||||
"version": "1.0.0",
|
||||
"version": "1.0.2-alpha.1",
|
||||
"description": "A foundation for scalable desktop apps",
|
||||
"main": "./dist/main/main.js",
|
||||
"author": {
|
||||
|
||||
@@ -1,24 +1,21 @@
|
||||
import { ipcMain } from "electron";
|
||||
|
||||
import { LocalMapsManagerService } from "../services/additional-content/local-maps-manager.service";
|
||||
import { UtilsService } from "../services/utils.service";
|
||||
import { BSVersion } from "shared/bs-version.interface";
|
||||
import { IpcRequest } from "shared/models/ipc";
|
||||
import { BsmLocalMap } from "shared/models/maps/bsm-local-map.interface";
|
||||
import { BsvMapDetail } from "shared/models/maps";
|
||||
import { IpcService } from "../services/ipc.service";
|
||||
import { from } from "rxjs";
|
||||
|
||||
ipcMain.on('get-version-maps', (event, request: IpcRequest<BSVersion>) => {
|
||||
const utilsService = UtilsService.getInstance();
|
||||
const ipc = IpcService.getInstance();
|
||||
|
||||
ipc.on('load-version-maps', async (request: IpcRequest<BSVersion>, reply) => {
|
||||
const localMaps = LocalMapsManagerService.getInstance();
|
||||
|
||||
localMaps.getMaps(request.args).then(maps => {
|
||||
utilsService.ipcSend<BsmLocalMap[]>(request.responceChannel, {success: true, data: maps});
|
||||
}).catch(() => {
|
||||
utilsService.ipcSend(request.responceChannel, {success: false});
|
||||
})
|
||||
|
||||
reply(localMaps.getMaps(request.args));
|
||||
});
|
||||
|
||||
ipcMain.on("verion-have-maps-linked", async (event, request: IpcRequest<BSVersion>) => {
|
||||
ipc.on("verion-have-maps-linked", async (request: IpcRequest<BSVersion>) => {
|
||||
const utils = UtilsService.getInstance();
|
||||
const maps = LocalMapsManagerService.getInstance();
|
||||
|
||||
@@ -26,7 +23,7 @@ ipcMain.on("verion-have-maps-linked", async (event, request: IpcRequest<BSVersio
|
||||
|
||||
});
|
||||
|
||||
ipcMain.on("link-version-maps", async (event, request: IpcRequest<{version: BSVersion, keepMaps: boolean}>) => {
|
||||
ipc.on("link-version-maps", async (request: IpcRequest<{version: BSVersion, keepMaps: boolean}>) => {
|
||||
const utils = UtilsService.getInstance();
|
||||
const maps = LocalMapsManagerService.getInstance();
|
||||
|
||||
@@ -38,7 +35,7 @@ ipcMain.on("link-version-maps", async (event, request: IpcRequest<{version: BSVe
|
||||
|
||||
});
|
||||
|
||||
ipcMain.on("unlink-version-maps", async (event, request: IpcRequest<{version: BSVersion, keepMaps: boolean}>) => {
|
||||
ipc.on("unlink-version-maps", async (request: IpcRequest<{version: BSVersion, keepMaps: boolean}>) => {
|
||||
const utils = UtilsService.getInstance();
|
||||
const maps = LocalMapsManagerService.getInstance();
|
||||
|
||||
@@ -50,40 +47,22 @@ ipcMain.on("unlink-version-maps", async (event, request: IpcRequest<{version: BS
|
||||
|
||||
});
|
||||
|
||||
ipcMain.on("delete-maps", async (event, request: IpcRequest<{version: BSVersion, maps: BsmLocalMap[]}>) => {
|
||||
const utils = UtilsService.getInstance();
|
||||
ipc.on("delete-maps", async (request: IpcRequest<BsmLocalMap[]>, reply) => {
|
||||
const maps = LocalMapsManagerService.getInstance();
|
||||
|
||||
maps.deleteMaps(request.args.maps, request.args.version).then(() => {
|
||||
utils.ipcSend<void>(request.responceChannel, {success: true});
|
||||
}).catch(err => {
|
||||
utils.ipcSend<void>(request.responceChannel, {success: false, error: err});
|
||||
});
|
||||
reply(maps.deleteMaps(request.args));
|
||||
});
|
||||
|
||||
ipcMain.on("export-maps", async (event, request: IpcRequest<{version: BSVersion, maps: BsmLocalMap[], outPath: string}>) => {
|
||||
const utils = UtilsService.getInstance();
|
||||
ipc.on("export-maps", async (request: IpcRequest<{version: BSVersion, maps: BsmLocalMap[], outPath: string}>, reply) => {
|
||||
const maps = LocalMapsManagerService.getInstance();
|
||||
|
||||
maps.exportMaps(request.args.version, request.args.maps, request.args.outPath).then(() => {
|
||||
utils.ipcSend<void>(request.responceChannel, {success: true});
|
||||
}).catch(err => {
|
||||
utils.ipcSend<void>(request.responceChannel, {success: false, error: err});
|
||||
});
|
||||
reply(await maps.exportMaps(request.args.version, request.args.maps, request.args.outPath));
|
||||
});
|
||||
|
||||
ipcMain.on("download-map", async (event, request: IpcRequest<{map: BsvMapDetail, version: BSVersion}>) => {
|
||||
const utils = UtilsService.getInstance();
|
||||
ipc.on("download-map", async (request: IpcRequest<{map: BsvMapDetail, version: BSVersion}>, reply) => {
|
||||
const maps = LocalMapsManagerService.getInstance();
|
||||
|
||||
maps.downloadMap(request.args.map, request.args.version).then(() => {
|
||||
utils.ipcSend(request.responceChannel, {success: true});
|
||||
}).catch(err => {
|
||||
utils.ipcSend(request.responceChannel, {success: false, error: err});
|
||||
});
|
||||
reply(from(maps.downloadMap(request.args.map, request.args.version)))
|
||||
});
|
||||
|
||||
ipcMain.on("one-click-install-map", async (event, request: IpcRequest<BsvMapDetail>) => {
|
||||
ipc.on("one-click-install-map", async (request: IpcRequest<BsvMapDetail>) => {
|
||||
const utils = UtilsService.getInstance();
|
||||
const maps = LocalMapsManagerService.getInstance();
|
||||
|
||||
@@ -94,7 +73,7 @@ ipcMain.on("one-click-install-map", async (event, request: IpcRequest<BsvMapDeta
|
||||
});
|
||||
});
|
||||
|
||||
ipcMain.on("register-maps-deep-link", async (event, request: IpcRequest<void>) => {
|
||||
ipc.on("register-maps-deep-link", async (request: IpcRequest<void>) => {
|
||||
|
||||
const maps = LocalMapsManagerService.getInstance();
|
||||
const utils = UtilsService.getInstance();
|
||||
@@ -109,7 +88,7 @@ ipcMain.on("register-maps-deep-link", async (event, request: IpcRequest<void>) =
|
||||
|
||||
});
|
||||
|
||||
ipcMain.on("unregister-maps-deep-link", async (event, request: IpcRequest<void>) => {
|
||||
ipc.on("unregister-maps-deep-link", async (request: IpcRequest<void>) => {
|
||||
|
||||
const maps = LocalMapsManagerService.getInstance();
|
||||
const utils = UtilsService.getInstance();
|
||||
@@ -124,7 +103,7 @@ ipcMain.on("unregister-maps-deep-link", async (event, request: IpcRequest<void>)
|
||||
|
||||
});
|
||||
|
||||
ipcMain.on("is-map-deep-links-enabled", async (event, request: IpcRequest<void>) => {
|
||||
ipc.on("is-map-deep-links-enabled", async (request: IpcRequest<void>) => {
|
||||
|
||||
const maps = LocalMapsManagerService.getInstance();
|
||||
const utils = UtilsService.getInstance();
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
import archiver from "archiver";
|
||||
import { createWriteStream } from "fs";
|
||||
import { Observable } from "rxjs";
|
||||
import recursive from "recursive-readdir";
|
||||
import { lstatSync } from "fs";
|
||||
import * as _path from "path";
|
||||
import { ArchiveProgress } from "shared/models/archive.interface";
|
||||
|
||||
export class Archive{
|
||||
|
||||
private archive: archiver.Archiver;
|
||||
private readonly output: string;
|
||||
|
||||
private readonly directories: string[] = [];
|
||||
private readonly files: string[] = [];
|
||||
|
||||
constructor(output: string, options?: archiver.ArchiverOptions){
|
||||
this.output = output;
|
||||
this.initArchive(options);
|
||||
}
|
||||
|
||||
private initArchive(options?: archiver.ArchiverOptions): void{
|
||||
const defaultOptions: archiver.ArchiverOptions = {
|
||||
zlib: {level: 9}
|
||||
};
|
||||
|
||||
this.archive = archiver("zip", {...defaultOptions, ...options});
|
||||
}
|
||||
|
||||
private async loadTotalFiles(): Promise<number>{
|
||||
let totalFiles = this.files.length;
|
||||
for(const path of this.directories){
|
||||
const files = await recursive(path);
|
||||
totalFiles += files.length;
|
||||
}
|
||||
return totalFiles;
|
||||
}
|
||||
|
||||
public addDirectory(path: string, destPath?: string|false): void{
|
||||
this.directories.push(path);
|
||||
destPath = destPath === false ? false : _path.basename(path);
|
||||
this.archive.directory(path, destPath);
|
||||
}
|
||||
|
||||
public addFile(path: string, destPath?: string): void{
|
||||
this.files.push(path);
|
||||
destPath = destPath ||= _path.basename(path);
|
||||
this.archive.file(path, {name: destPath});
|
||||
}
|
||||
|
||||
|
||||
public finalize(): Observable<ArchiveProgress>{
|
||||
|
||||
const progress: ArchiveProgress = {
|
||||
totalFiles: 0,
|
||||
prossesedFiles: 0
|
||||
};
|
||||
|
||||
return new Observable<ArchiveProgress>(observer => {
|
||||
(async () => {
|
||||
|
||||
progress.totalFiles = await this.loadTotalFiles();
|
||||
|
||||
this.archive.on("entry", e => {
|
||||
if(e.stats.isDirectory()){ return; }
|
||||
progress.prossesedFiles++;
|
||||
observer.next(progress);
|
||||
});
|
||||
|
||||
this.archive.pipe(createWriteStream(this.output));
|
||||
|
||||
this.archive.on("error", err => observer.error(err));
|
||||
this.archive.finalize().then(() => observer.complete());
|
||||
})();
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
+7
-5
@@ -1,21 +1,23 @@
|
||||
import { contextBridge, ipcRenderer, IpcRendererEvent } from 'electron';
|
||||
|
||||
export type Channels = any;
|
||||
import { IpcChannel } from 'shared/models/ipc/ipc-response.interface';
|
||||
|
||||
contextBridge.exposeInMainWorld('electron', {
|
||||
ipcRenderer: {
|
||||
sendMessage(channel: Channels, args: unknown[]) {
|
||||
sendMessage(channel: IpcChannel, args: unknown[]) {
|
||||
ipcRenderer.send(channel, args);
|
||||
},
|
||||
on(channel: Channels, func: (...args: unknown[]) => void) {
|
||||
on(channel: IpcChannel, func: (...args: unknown[]) => void) {
|
||||
const subscription = (_event: IpcRendererEvent, ...args: unknown[]) =>
|
||||
func(...args);
|
||||
ipcRenderer.on(channel, subscription);
|
||||
|
||||
return () => ipcRenderer.removeListener(channel, subscription);
|
||||
},
|
||||
once(channel: Channels, func: (...args: unknown[]) => void) {
|
||||
once(channel: IpcChannel, func: (...args: unknown[]) => void) {
|
||||
ipcRenderer.once(channel, (_event, ...args) => func(...args));
|
||||
},
|
||||
removeAllListeners(channel: IpcChannel) {
|
||||
ipcRenderer.removeAllListeners(channel);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import path from "path";
|
||||
import { BSVersion } from "shared/bs-version.interface";
|
||||
import { BsvMapDetail, RawMapInfoData } from "shared/models/maps";
|
||||
import { BsmLocalMap } from "shared/models/maps/bsm-local-map.interface";
|
||||
import { BsmLocalMap, BsmLocalMapsProgress, DeleteMapsProgress } from "shared/models/maps/bsm-local-map.interface";
|
||||
import { BSLocalVersionService } from "../bs-local-version.service";
|
||||
import { InstallationLocationService } from "../installation-location.service";
|
||||
import { UtilsService } from "../utils.service";
|
||||
import crypto from "crypto";
|
||||
import { lstatSync, symlinkSync, unlinkSync, readdirSync, createWriteStream } from "fs";
|
||||
import { copySync } from "fs-extra";
|
||||
import { copy, copySync } from "fs-extra";
|
||||
import StreamZip from "node-stream-zip";
|
||||
import { RequestService } from "../request.service";
|
||||
import sanitize from "sanitize-filename";
|
||||
@@ -17,6 +17,9 @@ import log from 'electron-log';
|
||||
import { WindowManagerService } from "../window-manager.service";
|
||||
import { ipcMain } from "electron";
|
||||
import { IpcRequest } from 'shared/models/ipc';
|
||||
import { Observable } from "rxjs";
|
||||
import { defer } from "rxjs";
|
||||
import { Archive } from "../../models/archive.class";
|
||||
|
||||
export class LocalMapsManagerService {
|
||||
|
||||
@@ -62,6 +65,7 @@ export class LocalMapsManagerService {
|
||||
}
|
||||
|
||||
public async getMapsFolderPath(version?: BSVersion): Promise<string>{
|
||||
|
||||
if(version){ return path.join(await this.localVersion.getVersionPath(version), this.LEVELS_ROOT_FOLDER, this.CUSTOM_LEVELS_FOLDER); }
|
||||
const sharedMapsPath = path.join(this.installLocation.sharedMapsPath, this.CUSTOM_LEVELS_FOLDER);
|
||||
if(!(await this.utils.pathExist(sharedMapsPath))){
|
||||
@@ -100,7 +104,7 @@ export class LocalMapsManagerService {
|
||||
|
||||
const hash = await this.computeMapHash(mapPath, rawInfoString);
|
||||
|
||||
return {rawInfo, coverUrl, songUrl, hash};
|
||||
return {rawInfo, coverUrl, songUrl, hash, path: mapPath};
|
||||
}
|
||||
|
||||
private async downloadMapZip(zipUrl: string): Promise<{zip: StreamZip.StreamZipAsync, zipPath: string}>{
|
||||
@@ -115,28 +119,6 @@ export class LocalMapsManagerService {
|
||||
return {zip, zipPath};
|
||||
}
|
||||
|
||||
private async getAbsoluteFolderOfMaps(maps: BsmLocalMap[], version: BSVersion): Promise<string[]>{
|
||||
|
||||
const mapsFolder = await this.getMapsFolderPath(version);
|
||||
|
||||
const res: string[] = [];
|
||||
const mapHashs = maps.map(map => map.hash);
|
||||
|
||||
const mapsFolders = readdirSync(mapsFolder, {withFileTypes: true});
|
||||
|
||||
for(const content of mapsFolders){
|
||||
if(!content.isDirectory()){ continue; }
|
||||
const mapFolderPath = path.join(mapsFolder, content.name);
|
||||
const { hash } = await this.loadMapInfoFromPath(mapFolderPath);
|
||||
if(mapHashs.includes(hash)){
|
||||
res.push(mapFolderPath);
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
|
||||
}
|
||||
|
||||
private openOneClickDownloadMapWindow(mapId: string, isHash = false): void{
|
||||
|
||||
ipcMain.once("one-click-map-info", async (event, req: IpcRequest<void>) => {
|
||||
@@ -147,14 +129,36 @@ export class LocalMapsManagerService {
|
||||
|
||||
}
|
||||
|
||||
public async getMaps(version?: BSVersion): Promise<BsmLocalMap[]>{
|
||||
const levelsFolder = await this.getMapsFolderPath(version);
|
||||
public getMaps(version?: BSVersion): Observable<BsmLocalMapsProgress>{
|
||||
|
||||
const levelsPath = (await this.utils.pathExist(levelsFolder)) ? this.utils.listDirsInDir(levelsFolder, true) : [];
|
||||
const progression: BsmLocalMapsProgress = {
|
||||
total: 0,
|
||||
loaded: 0,
|
||||
maps: []
|
||||
};
|
||||
|
||||
const mapsInfo = await Promise.all(levelsPath.map(levelPath => this.loadMapInfoFromPath(levelPath)));
|
||||
return new Observable<BsmLocalMapsProgress>(observer => {
|
||||
(async () => {
|
||||
const levelsFolder = await this.getMapsFolderPath(version);
|
||||
|
||||
return mapsInfo.filter(info => !!info);
|
||||
const levelsPaths = (await this.utils.pathExist(levelsFolder)) ? this.utils.listDirsInDir(levelsFolder, true) : [];
|
||||
|
||||
progression.total = levelsPaths.length;
|
||||
|
||||
for(const levelPath of levelsPaths){
|
||||
const mapInfo = await this.loadMapInfoFromPath(levelPath);
|
||||
if(mapInfo){
|
||||
progression.maps.push(mapInfo);
|
||||
progression.loaded = progression.maps.length;
|
||||
observer.next({...progression, maps: []});
|
||||
}
|
||||
}
|
||||
|
||||
observer.next(progression);
|
||||
|
||||
observer.complete();
|
||||
})();
|
||||
});
|
||||
}
|
||||
|
||||
public async versionIsLinked(version: BSVersion): Promise<boolean>{
|
||||
@@ -196,26 +200,37 @@ export class LocalMapsManagerService {
|
||||
this.utils.createFolderIfNotExist(versionMapsPath);
|
||||
|
||||
if(keepMaps){
|
||||
copySync(sharedMapsPath, versionMapsPath);
|
||||
await copy(sharedMapsPath, versionMapsPath);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public async deleteMaps(maps: BsmLocalMap[], verion?: BSVersion){
|
||||
public deleteMaps(maps: BsmLocalMap[]): Observable<DeleteMapsProgress>{
|
||||
|
||||
const mapsFolders = await this.getAbsoluteFolderOfMaps(maps, verion);
|
||||
const mapsFolders = maps.map(map => map.path);
|
||||
const mapsHashsToDelete = maps.map(map => map.hash);
|
||||
|
||||
for(const folder of mapsFolders){
|
||||
const { hash } = await this.loadMapInfoFromPath(folder);
|
||||
if(mapsHashsToDelete.includes(hash)){
|
||||
await this.utils.deleteFolder(folder);
|
||||
}
|
||||
}
|
||||
|
||||
return new Observable<DeleteMapsProgress>(observer => {
|
||||
(async () => {
|
||||
const progress: DeleteMapsProgress = { total: maps.length, deleted: 0 };
|
||||
try{
|
||||
for(const folder of mapsFolders){
|
||||
const detail = await this.loadMapInfoFromPath(folder);
|
||||
if(!mapsHashsToDelete.includes(detail?.hash)){ continue; }
|
||||
await this.utils.deleteFolder(folder);
|
||||
progress.deleted++;
|
||||
observer.next(progress);
|
||||
}
|
||||
}catch(e){
|
||||
console.log(e);
|
||||
observer.error(e);
|
||||
}
|
||||
observer.complete();
|
||||
})();
|
||||
});
|
||||
}
|
||||
|
||||
public async downloadMap(map: BsvMapDetail, version?: BSVersion): Promise<string>{
|
||||
public async downloadMap(map: BsvMapDetail, version?: BSVersion): Promise<BsmLocalMap>{
|
||||
|
||||
if(!map.versions.at(0).hash){ throw "Cannot download map, no hash found"; }
|
||||
|
||||
@@ -238,34 +253,26 @@ export class LocalMapsManagerService {
|
||||
|
||||
unlinkSync(zipPath);
|
||||
|
||||
return mapPath;
|
||||
const localMap = await this.loadMapInfoFromPath(mapPath);
|
||||
localMap.bsaverInfo = map;
|
||||
|
||||
return localMap;
|
||||
}
|
||||
|
||||
public async exportMaps(version: BSVersion, maps: BsmLocalMap[], outPath: string){
|
||||
|
||||
const output = createWriteStream(outPath);
|
||||
const archive = archiver("zip", {zlib: {level: 9}});
|
||||
|
||||
archive.pipe(output);
|
||||
archive.on("error", (e) => {throw e});
|
||||
const archive = new Archive(outPath);
|
||||
|
||||
if(!maps || maps.length === 0){
|
||||
|
||||
const mapsFolder = await this.getMapsFolderPath(version);
|
||||
archive.directory(mapsFolder, false);
|
||||
|
||||
archive.addDirectory(mapsFolder, false);
|
||||
}
|
||||
else{
|
||||
|
||||
const mapsFolders = await this.getAbsoluteFolderOfMaps(maps, version);
|
||||
|
||||
for(const folder of mapsFolders){
|
||||
archive.directory(folder, path.basename(folder));
|
||||
}
|
||||
|
||||
const mapsFolders = maps.map(map => map.path);
|
||||
mapsFolders.forEach(maps => archive.addDirectory(maps));
|
||||
}
|
||||
|
||||
await archive.finalize();
|
||||
return archive.finalize()
|
||||
|
||||
}
|
||||
|
||||
@@ -283,7 +290,7 @@ export class LocalMapsManagerService {
|
||||
|
||||
this.utils.createFolderIfNotExist(versionMapsPath);
|
||||
|
||||
copySync(downloadedMap, path.join(versionMapsPath, path.basename(downloadedMap)), {overwrite: true});
|
||||
copySync(downloadedMap.path, path.join(versionMapsPath, path.basename(downloadedMap.path)), {overwrite: true});
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -163,7 +163,7 @@ export class LocalPlaylistsManagerService {
|
||||
...res.value,
|
||||
current: null,
|
||||
downloadedMaps: [...res.value.downloadedMaps, map],
|
||||
mapsPath: [...res.value.mapsPath, mapPath],
|
||||
mapsPath: [...res.value.mapsPath, mapPath.path],
|
||||
progression
|
||||
});
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ export class BSInstallerService{
|
||||
this.localVersionService = BSLocalVersionService.getInstance();
|
||||
this.windows = WindowManagerService.getInstance();
|
||||
|
||||
this.windows.getWindows("index.html")?.on("close", () => {
|
||||
this.windows.getWindow("index.html")?.on("close", () => {
|
||||
this.killDownloadProcess();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
import { IpcResponse, IpcRequest } from "shared/models/ipc";
|
||||
import { ipcMain } from "electron";
|
||||
import { Observable } from "rxjs";
|
||||
import { IpcChannel, IpcCompleteChannel, IpcErrorChannel } from "shared/models/ipc/ipc-response.interface";
|
||||
import { AppWindow } from "shared/models/window-manager/app-window.model";
|
||||
import { WindowManagerService } from "./window-manager.service";
|
||||
import { IpcReplier } from "shared/models/ipc/ipc-request.interface";
|
||||
|
||||
export class IpcService {
|
||||
|
||||
private static instance: IpcService;
|
||||
|
||||
public static getInstance(): IpcService {
|
||||
if (!IpcService.instance) { IpcService.instance = new IpcService(); }
|
||||
return IpcService.instance;
|
||||
}
|
||||
|
||||
private readonly windows: WindowManagerService;
|
||||
|
||||
private constructor() {
|
||||
this.windows = WindowManagerService.getInstance();
|
||||
}
|
||||
|
||||
private getErrorChannel(channel: IpcChannel): IpcErrorChannel {
|
||||
return `${channel}_error`;
|
||||
}
|
||||
|
||||
private getCompleteChannel(channel: IpcChannel): IpcCompleteChannel {
|
||||
return `${channel}_complete`;
|
||||
}
|
||||
|
||||
private buildProxyListener<T>(listener: (req: IpcRequest<T>, replier: IpcReplier) => void) {
|
||||
|
||||
return (event: Electron.IpcMainEvent, req: IpcRequest<T>) => {
|
||||
const window = this.windows.getAppWindowFromWebContents(event.sender);
|
||||
const replier = (data: Observable<unknown>) => this.connectStream(req.responceChannel, window, data);
|
||||
listener(req, replier);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public send<T>(channel: IpcChannel, window: AppWindow, response?: T|Error): void{
|
||||
this.windows.getWindow(window).webContents.send(channel, response);
|
||||
}
|
||||
|
||||
public connectStream(channel: IpcChannel, window: AppWindow, observable: Observable<unknown>): void{
|
||||
observable.subscribe(data => {
|
||||
this.send(channel, window, data);
|
||||
}, error => {
|
||||
console.log("LAAAA 2", error);
|
||||
this.send(this.getErrorChannel(channel), window, error);
|
||||
}, () => {
|
||||
this.send(this.getCompleteChannel(channel), window);
|
||||
});
|
||||
}
|
||||
|
||||
public on<T>(channel: IpcChannel, listener: (req: IpcRequest<T>, replier: IpcReplier) => void): void{
|
||||
ipcMain.on(channel, this.buildProxyListener(listener));
|
||||
}
|
||||
|
||||
public once<T>(channel: IpcChannel, listener: (req: IpcRequest<T>, replier: IpcReplier) => void): void{
|
||||
ipcMain.once(channel, this.buildProxyListener(listener));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -32,8 +32,7 @@ export class BeatSaverService {
|
||||
return res;
|
||||
}, [] as BsvMapDetail[]);
|
||||
|
||||
for(const hashs of chunkHash){
|
||||
|
||||
await Promise.all(chunkHash.map(async hashs => {
|
||||
const res = await this.bsaverApi.getMapsDetailsByHashs(hashs);
|
||||
|
||||
if(res.status === 200){
|
||||
@@ -42,7 +41,7 @@ export class BeatSaverService {
|
||||
this.cachedMapsDetails.set(detail.versions.at(0).hash.toLowerCase(), detail);
|
||||
});
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
return mapDetails;
|
||||
}
|
||||
|
||||
@@ -75,8 +75,12 @@ export class WindowManagerService{
|
||||
});
|
||||
}
|
||||
|
||||
public getWindows(window: AppWindow): BrowserWindow{
|
||||
public getWindow(window: AppWindow): BrowserWindow{
|
||||
return this.windows.get(window);
|
||||
}
|
||||
|
||||
public getAppWindowFromWebContents(sender: Electron.WebContents): AppWindow{
|
||||
return Array.from(this.windows.entries()).find(([key, value]) => value.webContents.id === sender.id)[0];
|
||||
}
|
||||
|
||||
}
|
||||
+152
-85
@@ -3,15 +3,21 @@ import { BSVersion } from "shared/bs-version.interface"
|
||||
import { forwardRef, useCallback, useEffect, useImperativeHandle, useRef, useState } from "react"
|
||||
import { BsmLocalMap } from "shared/models/maps/bsm-local-map.interface"
|
||||
import { Subscription } from "rxjs"
|
||||
import { MapItem, ParsedMapDiff } from "./map-item.component"
|
||||
import { BsvMapCharacteristic, MapFilter } from "shared/models/maps/beat-saver.model"
|
||||
import { MapFilter } from "shared/models/maps/beat-saver.model"
|
||||
import { useInView } from "framer-motion"
|
||||
import { MapsDownloaderService } from "renderer/services/maps-downloader.service"
|
||||
import { BsmImage } from "../shared/bsm-image.component"
|
||||
import BeatConflict from "../../../../assets/images/apngs/beat-conflict.png"
|
||||
import { BsmButton } from "../shared/bsm-button.component"
|
||||
import { VariableSizeList } from "react-window"
|
||||
import { MapsRow } from "./maps-row.component"
|
||||
import { BehaviorSubject } from "rxjs"
|
||||
import { debounceTime, last, map, mergeMap, throttleTime } from "rxjs/operators"
|
||||
import { BeatSaverService } from "renderer/services/thrird-partys/beat-saver.service"
|
||||
import { OsDiagnosticService } from "renderer/services/os-diagnostic.service"
|
||||
import { useTranslation } from "renderer/hooks/use-translation.hook"
|
||||
import BeatWaitingImg from "../../../../assets/images/apngs/beat-waiting.png"
|
||||
import BeatConflict from "../../../../assets/images/apngs/beat-conflict.png"
|
||||
import { BsmImage } from "../shared/bsm-image.component"
|
||||
import { BsmButton } from "../shared/bsm-button.component"
|
||||
import TextProgressBar from "../progress-bar/text-progress-bar.component"
|
||||
|
||||
type Props = {
|
||||
version: BSVersion,
|
||||
@@ -24,23 +30,36 @@ export const LocalMapsListPanel = forwardRef(({version, className, filter, searc
|
||||
|
||||
const mapsManager = MapsManagerService.getInstance();
|
||||
const mapsDownloader = MapsDownloaderService.getInstance();
|
||||
const bsaver = BeatSaverService.getInstance();
|
||||
const os = OsDiagnosticService.getInstance();
|
||||
|
||||
const t = useTranslation();
|
||||
const ref = useRef(null)
|
||||
const isVisible = useInView(ref, {once: true});
|
||||
const [maps, setMaps] = useState<BsmLocalMap[]>(null);
|
||||
const [subs] = useState<Subscription[]>([]);
|
||||
const [selectedMaps, setSelectedMaps] = useState([]);
|
||||
const t = useTranslation();
|
||||
const [selectedMaps$] = useState(new BehaviorSubject<BsmLocalMap[]>([]));
|
||||
const [itemPerRow, setItemPerRow] = useState(2);
|
||||
const [listHeight, setListHeight] = useState(0);
|
||||
|
||||
const [loadPercent$] = useState(new BehaviorSubject(0));
|
||||
|
||||
useImperativeHandle(forwardRef ,()=>({
|
||||
deleteMaps(){
|
||||
const mapsToDelete = selectedMaps.length === 0 ? maps : selectedMaps
|
||||
mapsManager.deleteMaps(mapsToDelete, version).finally(loadMaps);
|
||||
const mapsToDelete = selectedMaps$.value.length === 0 ? maps : selectedMaps$.value;
|
||||
mapsManager.deleteMaps(mapsToDelete, version).then(res => {
|
||||
if(!res){ return; }
|
||||
removeMapsFromList(mapsToDelete);
|
||||
selectedMaps$.next([]);
|
||||
});
|
||||
},
|
||||
exportMaps(){
|
||||
mapsManager.exportMaps(version, selectedMaps)
|
||||
mapsManager.exportMaps(version, selectedMaps$.value);
|
||||
},
|
||||
getMaps(){
|
||||
return maps;
|
||||
}
|
||||
}), [selectedMaps, maps, version]);
|
||||
}), [selectedMaps$.value, maps, version]);
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
@@ -48,58 +67,100 @@ export const LocalMapsListPanel = forwardRef(({version, className, filter, searc
|
||||
loadMaps();
|
||||
subs.push(mapsManager.versionLinked$.subscribe(loadMaps));
|
||||
subs.push(mapsManager.versionUnlinked$.subscribe(loadMaps));
|
||||
mapsDownloader.addOnMapDownloadedListener(loadMaps);
|
||||
mapsDownloader.addOnMapDownloadedListener((map, targerVersion) => {
|
||||
if(targerVersion !== version){ return; }
|
||||
setMaps(maps => maps ? [map, ...maps] : [map]);
|
||||
});
|
||||
}
|
||||
|
||||
return () => {
|
||||
setMaps(() => null);
|
||||
loadPercent$.next(0);
|
||||
subs.forEach(s => s.unsubscribe());
|
||||
mapsDownloader.removeOnMapDownloadedListene(loadMaps);
|
||||
mapsDownloader.removeOnMapDownloadedListener(loadMaps);
|
||||
}
|
||||
}, [isVisible, version]);
|
||||
|
||||
const loadMaps = () => {
|
||||
subs.push(mapsManager.getMaps(version).subscribe(localMaps => setMaps(() => [...localMaps])));
|
||||
}
|
||||
useEffect(() => {
|
||||
|
||||
if(!isVisible){ return () => {}; }
|
||||
|
||||
const handleDelete = useCallback((map: BsmLocalMap) => {
|
||||
mapsManager.deleteMaps([map], version).then(res => res && loadMaps())
|
||||
}, [version]);
|
||||
const updateItemPerRow = (listWidth: number) => {
|
||||
const newPerRow = Math.min(Math.floor(listWidth / 400), 3);
|
||||
if(newPerRow === itemPerRow){ return; }
|
||||
setItemPerRow(newPerRow);
|
||||
};
|
||||
|
||||
const extractMapDiffs = (map: BsmLocalMap): Map<BsvMapCharacteristic, ParsedMapDiff[]> => {
|
||||
const res = new Map<BsvMapCharacteristic, ParsedMapDiff[]>();
|
||||
if(map.bsaverInfo?.versions[0]?.diffs){
|
||||
map.bsaverInfo.versions[0].diffs.forEach(diff => {
|
||||
const arr = res.get(diff.characteristic) || [];
|
||||
const diffName = map.rawInfo._difficultyBeatmapSets.find(set => set._beatmapCharacteristicName === diff.characteristic)._difficultyBeatmaps.find(rawDiff => rawDiff._difficulty === diff.difficulty)?._customData?._difficultyLabel || diff.difficulty
|
||||
arr.push({name: diffName, type: diff.difficulty, stars: diff.stars});
|
||||
res.set(diff.characteristic, arr);
|
||||
});
|
||||
return res;
|
||||
}
|
||||
const heightObserver$ = new BehaviorSubject(0);
|
||||
|
||||
map.rawInfo._difficultyBeatmapSets.forEach(set => {
|
||||
set._difficultyBeatmaps.forEach(diff => {
|
||||
const arr = res.get(set._beatmapCharacteristicName) || [];
|
||||
arr.push({name: diff._customData?._difficultyLabel || diff._difficulty, type: diff._difficulty, stars: null});
|
||||
res.set(set._beatmapCharacteristicName, arr);
|
||||
});
|
||||
const observer = new ResizeObserver(() => {
|
||||
updateItemPerRow(ref.current?.clientWidth || 0);
|
||||
heightObserver$.next(ref.current?.clientHeight || 0)
|
||||
});
|
||||
|
||||
return res;
|
||||
observer.observe(ref.current);
|
||||
|
||||
const sub = heightObserver$.pipe(debounceTime(100)).subscribe(setListHeight);
|
||||
|
||||
return () => {
|
||||
observer.disconnect();
|
||||
sub.unsubscribe();
|
||||
}
|
||||
|
||||
}, [isVisible, itemPerRow])
|
||||
|
||||
const loadMaps = () => {
|
||||
|
||||
setMaps(() => null);
|
||||
loadPercent$.next(0);
|
||||
|
||||
const loadMapsObs$ = mapsManager.getMaps(version);
|
||||
|
||||
loadMapsObs$.pipe(map(progess => {
|
||||
console.log(progess);
|
||||
return Math.floor(((progess.loaded / progess.total) * 100));
|
||||
})).subscribe(percent => loadPercent$.next(percent));
|
||||
|
||||
subs.push(loadMapsObs$.pipe(
|
||||
last(),
|
||||
mergeMap(async progress => {
|
||||
if(os.isOffline){ return progress.maps; }
|
||||
const maps = progress.maps;
|
||||
const details = await bsaver.getMapDetailsFromHashs(maps.map(map => map.hash));
|
||||
return maps.map(map => {
|
||||
map.bsaverInfo = details.find(d => d.versions.at(0).hash === map.hash);
|
||||
return map;
|
||||
})
|
||||
})
|
||||
).subscribe({
|
||||
next: maps => setMaps(() => maps),
|
||||
complete: () => loadPercent$.next(0)
|
||||
}));
|
||||
}
|
||||
|
||||
const removeMapsFromList = (mapsToRemove: BsmLocalMap[]) => {
|
||||
const filtredMaps = maps.filter(map => !mapsToRemove.some(toDeleteMaps => map.hash === toDeleteMaps.hash));
|
||||
setMaps(() => filtredMaps);
|
||||
};
|
||||
|
||||
const handleDelete = useCallback((map: BsmLocalMap) => {
|
||||
mapsManager.deleteMaps([map], version).then(res => res && removeMapsFromList([map]));
|
||||
}, [version, maps]);
|
||||
|
||||
const onMapSelected = useCallback((map: BsmLocalMap) => {
|
||||
const maps = [...selectedMaps];
|
||||
if(maps.some(selectedMap => selectedMap.hash === map.hash)){
|
||||
const i = maps.findIndex(selectedMap => selectedMap.hash === map.hash);
|
||||
maps.splice(i, 1);
|
||||
|
||||
const mapsCopy = [...selectedMaps$.value];
|
||||
if(mapsCopy.some(selectedMap => selectedMap.hash === map.hash)){
|
||||
const i = mapsCopy.findIndex(selectedMap => selectedMap.hash === map.hash);
|
||||
mapsCopy.splice(i, 1);
|
||||
}
|
||||
else{
|
||||
maps.push(map);
|
||||
mapsCopy.push(map);
|
||||
}
|
||||
setSelectedMaps(() => maps);
|
||||
}, [selectedMaps]);
|
||||
|
||||
selectedMaps$.next(mapsCopy);
|
||||
|
||||
}, [selectedMaps$.value]);
|
||||
|
||||
const isMapFitFilter = (map: BsmLocalMap): boolean => {
|
||||
|
||||
@@ -216,53 +277,59 @@ export const LocalMapsListPanel = forwardRef(({version, className, filter, searc
|
||||
|
||||
}
|
||||
|
||||
const renderMaps = (): JSX.Element[] => {
|
||||
return maps.reduce((acc, current) => {
|
||||
if(isMapFitFilter(current)){
|
||||
acc.push(renderMapItem(current));
|
||||
|
||||
const preppedMaps: BsmLocalMap[][] = (() => {
|
||||
|
||||
if(!maps){ return []; }
|
||||
|
||||
const res: BsmLocalMap[][] = [];
|
||||
let mapsRow: BsmLocalMap[] = []
|
||||
|
||||
for(const map of maps){
|
||||
if(!isMapFitFilter(map)){ continue; }
|
||||
if(mapsRow.length === itemPerRow){
|
||||
res.push(mapsRow);
|
||||
mapsRow = [];
|
||||
}
|
||||
return acc
|
||||
}, []);
|
||||
mapsRow.push(map);
|
||||
}
|
||||
|
||||
if(mapsRow.length){
|
||||
res.push(mapsRow);
|
||||
}
|
||||
|
||||
return res;
|
||||
})();
|
||||
|
||||
if(!maps){
|
||||
return (
|
||||
<div ref={ref} className={className}>
|
||||
<div className="h-full flex flex-col items-center justify-center flex-wrap gap-1">
|
||||
<BsmImage className="w-32 h-32 spin-loading" image={BeatWaitingImg}/>
|
||||
<span className="font-bold">{t("modals.download-maps.loading-maps")}</span>
|
||||
<TextProgressBar value$={loadPercent$}/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const renderMapItem = (map: BsmLocalMap) => {
|
||||
|
||||
return <MapItem
|
||||
key={map.hash}
|
||||
hash={map.hash}
|
||||
title={map.rawInfo._songName}
|
||||
coverUrl={map.coverUrl}
|
||||
songUrl={map.songUrl}
|
||||
autor={map.rawInfo._levelAuthorName}
|
||||
songAutor={map.rawInfo._songAuthorName}
|
||||
bpm={map.rawInfo._beatsPerMinute}
|
||||
duration={map.bsaverInfo?.metadata?.duration}
|
||||
selected={selectedMaps.some(_map => _map.hash === map.hash)}
|
||||
diffs={extractMapDiffs(map)} mapId={map.bsaverInfo?.id} ranked={map.bsaverInfo?.ranked} autorId={map.bsaverInfo?.uploader?.id} likes={map.bsaverInfo?.stats?.upvotes} createdAt={map.bsaverInfo?.createdAt}
|
||||
onDelete={handleDelete}
|
||||
onSelected={onMapSelected}
|
||||
callBackParam={map}
|
||||
/>;
|
||||
if(!maps.length){
|
||||
return (
|
||||
<div ref={ref} className={className}>
|
||||
<div className="h-full flex flex-col items-center justify-center flex-wrap gap-1">
|
||||
<BsmImage className="h-32" image={BeatConflict}/>
|
||||
<span className="font-bold">{t("pages.version-viewer.maps.tabs.maps.empty-maps.text")}</span>
|
||||
<BsmButton className="font-bold rounded-md p-2" text="pages.version-viewer.maps.tabs.maps.empty-maps.button" typeColor="primary" withBar={false} onClick={e => {e.preventDefault(); mapsDownloader.openDownloadMapModal(version)}}/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
return (
|
||||
<div ref={ref} className={className}>
|
||||
<ul className="p-3 w-full grow flex flex-wrap justify-center content-start gap-2 overflow-y-scroll scrollbar-thin scrollbar-thumb-rounded-full scrollbar-thumb-neutral-900">
|
||||
{maps?.length ? renderMaps() : (
|
||||
maps === null ? (
|
||||
<div className="h-full flex flex-col items-center justify-center flex-wrap gap-1">
|
||||
<img className="w-32 h-32 spin-loading" src={BeatWaitingImg} alt=" "/>
|
||||
<span className="font-bold">{t("modals.download-maps.loading-maps")}</span>
|
||||
</div>
|
||||
) : (
|
||||
<div className="h-full flex flex-col items-center justify-center flex-wrap gap-1">
|
||||
<BsmImage className="h-32" image={BeatConflict}/>
|
||||
<span className="font-bold">{t("pages.version-viewer.maps.tabs.maps.empty-maps.text")}</span>
|
||||
<BsmButton className="font-bold rounded-md p-2" text="pages.version-viewer.maps.tabs.maps.empty-maps.button" typeColor="primary" withBar={false} onClick={e => {e.preventDefault(); mapsDownloader.openDownloadMapModal(version)}}/>
|
||||
</div>
|
||||
)
|
||||
)}
|
||||
</ul>
|
||||
<VariableSizeList className="p-0 scrollbar-thin scrollbar-thumb-rounded-full scrollbar-thumb-neutral-900" width={"100%"} height={listHeight} itemSize={() => 108} itemCount={preppedMaps.length} itemData={preppedMaps} layout="vertical" style={{scrollbarGutter: "stable both-edges"}} itemKey={(i, data) => data[i].map(map => map.hash).join()}>
|
||||
{(props) => <MapsRow maps={props.data[props.index]} style={props.style} selectedMaps$={selectedMaps$} onMapSelect={onMapSelected} onMapDelete={handleDelete}/>}
|
||||
</VariableSizeList>
|
||||
</div>
|
||||
)
|
||||
})
|
||||
|
||||
@@ -148,7 +148,7 @@ export const MapItem = memo(({hash, title, autor, songAutor, coverUrl, songUrl,
|
||||
}
|
||||
|
||||
return (
|
||||
<motion.li className="relative h-[100px] min-w-[370px] shrink-0 grow basis-0 text-white group cursor-pointer" onHoverStart={() => setHovered(true)} onHoverEnd={() => setHovered(false)} style={{zIndex: hovered && 5, transform: "translateZ(0) scale(1.0, 1.0)", backfaceVisibility: "hidden"}}>
|
||||
<motion.li className="relative h-[100px] w-[400px] min-w-[370px] shrink-0 grow basis-0 text-white group cursor-pointer" onHoverStart={() => setHovered(true)} onHoverEnd={() => setHovered(false)} style={{zIndex: hovered && 5, transform: "translateZ(0) scale(1.0, 1.0)", backfaceVisibility: "hidden"}}>
|
||||
<GlowEffect visible={hovered || selected && !!onSelected}/>
|
||||
<AnimatePresence>
|
||||
{(diffsPanelHovered || bottomBarHovered) && (
|
||||
@@ -236,8 +236,4 @@ export const MapItem = memo(({hash, title, autor, songAutor, coverUrl, songUrl,
|
||||
</div>
|
||||
</motion.li>
|
||||
)
|
||||
}, areEqual)
|
||||
|
||||
function areEqual(prevProps: MapItemProps, nextProps: MapItemProps): boolean {
|
||||
return equal(prevProps, nextProps);
|
||||
}
|
||||
}, equal);
|
||||
|
||||
+1
-1
@@ -59,7 +59,7 @@ export function MapsPlaylistsPanel({version}: Props) {
|
||||
}
|
||||
|
||||
const handleMapsAddClick = () => {
|
||||
mapsDownloader.openDownloadMapModal(version);
|
||||
mapsDownloader.openDownloadMapModal(version, mapsRef.current.getMaps?.());
|
||||
}
|
||||
|
||||
const renderTab = (props: DetailedHTMLProps<React.HTMLAttributes<HTMLLIElement>, HTMLLIElement>, text: string, index: number): JSX.Element => {
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
import { CSSProperties, memo } from "react"
|
||||
import { useObservable } from "renderer/hooks/use-observable.hook"
|
||||
import { distinctUntilChanged, map } from "rxjs/operators"
|
||||
import { BehaviorSubject } from "rxjs"
|
||||
import { BsvMapCharacteristic } from "shared/models/maps/beat-saver.model"
|
||||
import { BsmLocalMap } from "shared/models/maps/bsm-local-map.interface"
|
||||
import { ParsedMapDiff, MapItem } from "./map-item.component"
|
||||
import equal from "fast-deep-equal/es6"
|
||||
|
||||
type Props = {
|
||||
maps: BsmLocalMap[],
|
||||
style?: CSSProperties,
|
||||
onMapDelete: (map: BsmLocalMap) => void,
|
||||
onMapSelect: (map: BsmLocalMap) => void,
|
||||
selectedMaps$: BehaviorSubject<BsmLocalMap[]>
|
||||
}
|
||||
|
||||
export const MapsRow = memo(({maps, style, selectedMaps$, onMapSelect, onMapDelete}: Props) => {
|
||||
|
||||
const selectedMaps = useObservable<BsmLocalMap[]>(selectedMaps$.pipe(
|
||||
map(selectedMaps => selectedMaps.filter(selected => maps.some(map => map.hash === selected.hash))),
|
||||
distinctUntilChanged(equal)
|
||||
), []);
|
||||
|
||||
const extractMapDiffs = (map: BsmLocalMap): Map<BsvMapCharacteristic, ParsedMapDiff[]> => {
|
||||
const res = new Map<BsvMapCharacteristic, ParsedMapDiff[]>();
|
||||
if(map.bsaverInfo?.versions[0]?.diffs){
|
||||
map.bsaverInfo.versions[0].diffs.forEach(diff => {
|
||||
const arr = res.get(diff.characteristic) || [];
|
||||
const diffName = map.rawInfo._difficultyBeatmapSets.find(set => set._beatmapCharacteristicName === diff.characteristic)._difficultyBeatmaps.find(rawDiff => rawDiff._difficulty === diff.difficulty)?._customData?._difficultyLabel || diff.difficulty
|
||||
arr.push({name: diffName, type: diff.difficulty, stars: diff.stars});
|
||||
res.set(diff.characteristic, arr);
|
||||
});
|
||||
return res;
|
||||
}
|
||||
|
||||
map.rawInfo._difficultyBeatmapSets.forEach(set => {
|
||||
set._difficultyBeatmaps.forEach(diff => {
|
||||
const arr = res.get(set._beatmapCharacteristicName) || [];
|
||||
arr.push({name: diff._customData?._difficultyLabel || diff._difficulty, type: diff._difficulty, stars: null});
|
||||
res.set(set._beatmapCharacteristicName, arr);
|
||||
});
|
||||
});
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
const renderMapItem = (map: BsmLocalMap) => {
|
||||
|
||||
return <MapItem
|
||||
key={map.hash}
|
||||
hash={map.hash}
|
||||
title={map.rawInfo._songName}
|
||||
coverUrl={map.coverUrl}
|
||||
songUrl={map.songUrl}
|
||||
autor={map.rawInfo._levelAuthorName}
|
||||
songAutor={map.rawInfo._songAuthorName}
|
||||
bpm={map.rawInfo._beatsPerMinute}
|
||||
duration={map.bsaverInfo?.metadata?.duration}
|
||||
selected={selectedMaps.some(selected => selected.hash === map.hash)}
|
||||
diffs={extractMapDiffs(map)} mapId={map.bsaverInfo?.id} ranked={map.bsaverInfo?.ranked} autorId={map.bsaverInfo?.uploader?.id} likes={map.bsaverInfo?.stats?.upvotes} createdAt={map.bsaverInfo?.createdAt}
|
||||
onDelete={onMapDelete}
|
||||
onSelected={onMapSelect}
|
||||
callBackParam={map}
|
||||
/>;
|
||||
}
|
||||
|
||||
return (
|
||||
<ul className="h-fit w-full flex flex-nowrap basis-0 gap-x-[8px] py-1 px-3" style={style}>
|
||||
{maps && maps.map(renderMapItem)}
|
||||
</ul>
|
||||
)
|
||||
}, equal);
|
||||
@@ -19,11 +19,11 @@ import equal from "fast-deep-equal/es6";
|
||||
import { ProgressBarService } from "renderer/services/progress-bar.service";
|
||||
import { useTranslation } from "renderer/hooks/use-translation.hook";
|
||||
import { OsDiagnosticService } from "renderer/services/os-diagnostic.service";
|
||||
import { BsmLocalMap } from "shared/models/maps/bsm-local-map.interface";
|
||||
|
||||
export const DownloadMapsModal: ModalComponent<void, BSVersion> = ({data}) => {
|
||||
export const DownloadMapsModal: ModalComponent<void, {version: BSVersion, ownedMaps: BsmLocalMap[]}> = ({resolver, data: { ownedMaps, version }}) => {
|
||||
|
||||
const beatSaver = BeatSaverService.getInstance();
|
||||
const mapsManager = MapsManagerService.getInstance();
|
||||
const mapsDownloader = MapsDownloaderService.getInstance();
|
||||
const progressBar = ProgressBarService.getInstance();
|
||||
const os = OsDiagnosticService.getInstance();
|
||||
@@ -36,7 +36,7 @@ export const DownloadMapsModal: ModalComponent<void, BSVersion> = ({data}) => {
|
||||
const [query, setQuery] = useState("");
|
||||
const [maps, setMaps] = useState<BsvMapDetail[]>([]);
|
||||
const [sortOrder, setSortOrder] = useState<SearchOrder>(BSV_SORT_ORDER.at(0));
|
||||
const [ownedMapHashs, setOwnedMapHashs] = useState<string[]>([]);
|
||||
const [ownedMapHashs, setOwnedMapHashs] = useState<string[]>(ownedMaps?.map(map => map.hash) ?? []);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const isOnline = useObservable(os.isOnline$);
|
||||
const [searchParams, setSearchParams] = useState<SearchParams>({
|
||||
@@ -58,13 +58,12 @@ export const DownloadMapsModal: ModalComponent<void, BSVersion> = ({data}) => {
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
mapsManager.getMaps(data, false).toPromise().then(maps => setOwnedMapHashs(maps.map(map => map.hash)));
|
||||
|
||||
const onMapDownloaded = (map: BsvMapDetail, verion: BSVersion) => {
|
||||
if(!equal(verion, data) || !map?.versions){ return; }
|
||||
const downloadedHash = map.versions.at(0).hash;
|
||||
const onMapDownloaded = (map: BsmLocalMap, targerVersion: BSVersion) => {
|
||||
if(!equal(targerVersion, version)){ return; }
|
||||
const downloadedHash = map.hash;
|
||||
setOwnedMapHashs((prev) => [...prev, downloadedHash]);
|
||||
}
|
||||
|
||||
mapsDownloader.addOnMapDownloadedListener(onMapDownloaded);
|
||||
|
||||
if(mapsDownloader.isDownloading){
|
||||
@@ -72,7 +71,7 @@ export const DownloadMapsModal: ModalComponent<void, BSVersion> = ({data}) => {
|
||||
}
|
||||
|
||||
return () => {
|
||||
mapsDownloader.removeOnMapDownloadedListene(onMapDownloaded);
|
||||
mapsDownloader.removeOnMapDownloadedListener(onMapDownloaded);
|
||||
progressBar.setStyle(null);
|
||||
}
|
||||
}, [])
|
||||
@@ -99,7 +98,7 @@ export const DownloadMapsModal: ModalComponent<void, BSVersion> = ({data}) => {
|
||||
|
||||
const isMapOwned = map.versions.some(version => ownedMapHashs.includes(version.hash));
|
||||
const isDownloading = map.id === currentDownload?.map?.id;
|
||||
const inQueue = mapsInQueue.some(toDownload => equal(toDownload.version, data) && toDownload.map.id === map.id);
|
||||
const inQueue = mapsInQueue.some(toDownload => equal(toDownload.version, version) && toDownload.map.id === map.id);
|
||||
|
||||
return (
|
||||
<MapItem
|
||||
@@ -129,11 +128,11 @@ export const DownloadMapsModal: ModalComponent<void, BSVersion> = ({data}) => {
|
||||
}
|
||||
|
||||
const handleDownloadMap = useCallback((map: BsvMapDetail) => {
|
||||
mapsDownloader.addMapToDownload({map, version: data})
|
||||
mapsDownloader.addMapToDownload({map, version})
|
||||
}, []);
|
||||
|
||||
const handleCancelDownload = useCallback((map: BsvMapDetail) => {
|
||||
mapsDownloader.removeMapToDownload({map, version: data});
|
||||
mapsDownloader.removeMapToDownload({map, version});
|
||||
}, []);
|
||||
|
||||
const handleSortChange = (newSort: string) => {
|
||||
@@ -170,7 +169,7 @@ export const DownloadMapsModal: ModalComponent<void, BSVersion> = ({data}) => {
|
||||
<BsmButton className="shrink-0 rounded-full py-1 px-3 !bg-light-main-color-1 dark:!bg-main-color-1 flex justify-center items-center capitalize" icon="search" text="modals.download-maps.search-btn" withBar={false} onClick={e => {e.preventDefault(); handleSearch()}}/>
|
||||
<BsmSelect className="bg-light-main-color-1 dark:bg-main-color-1 rounded-full px-1 pb-0.5 text-center" options={sortOptions} onChange={handleSortChange}/>
|
||||
</div>
|
||||
<ul className="w-full grow flex content-start flex-wrap gap-2 px-2 overflow-y-scroll overflow-x-hidden scrollbar-thin scrollbar-thumb-rounded-full scrollbar-thumb-neutral-900 z-0" >
|
||||
<ul className="w-full grow flex content-start flex-wrap gap-2 pt-1.5 px-2 overflow-y-scroll overflow-x-hidden scrollbar-thin scrollbar-thumb-rounded-full scrollbar-thumb-neutral-900 z-0" >
|
||||
{maps.length === 0 ? (
|
||||
<div className="w-full h-full flex flex-col items-center justify-center">
|
||||
<img className={`w-32 h-32 ${loading && "spin-loading"}`} src={loading ? BeatWaitingImg : BeatConflictImg} alt=" "/>
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
import { CSSProperties } from "react";
|
||||
import { useObservable } from "renderer/hooks/use-observable.hook";
|
||||
import { Observable } from "rxjs"
|
||||
|
||||
type Props = {
|
||||
value$: Observable<number|string>,
|
||||
className?: string,
|
||||
style?: CSSProperties
|
||||
}
|
||||
|
||||
export default function TextProgressBar({value$, className, style}: Props) {
|
||||
|
||||
const value = useObservable(value$);
|
||||
|
||||
const prefix = typeof value === "number" ? "%" : "";
|
||||
|
||||
return (
|
||||
<span className={className} style={style}>{`${value}${prefix}`}</span>
|
||||
)
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import { BsmIcon, BsmIconType } from "../svgs/bsm-icon.component"
|
||||
import { useRef, CSSProperties } from "react";
|
||||
import { useRef, CSSProperties, MouseEvent } from "react";
|
||||
import { BsmImage } from "./bsm-image.component";
|
||||
import { useTranslation } from "renderer/hooks/use-translation.hook";
|
||||
import { useClickOutside } from "renderer/hooks/use-click-outside.hook";
|
||||
@@ -45,15 +45,17 @@ export function BsmButton({className, style, imgClassName, iconClassName, icon,
|
||||
|
||||
const renderTypeColor = (() => {
|
||||
if(typeColor === "primary"){ return ""; }
|
||||
if(!typeColor){ return `bg-light-main-color-2 dark:bg-main-color-2 ${!withBar && "hover:brightness-125"}`; }
|
||||
if(!typeColor){ return `bg-light-main-color-2 dark:bg-main-color-2 ${(!withBar && !disabled) && "hover:brightness-125"}`; }
|
||||
if(typeColor === "cancel"){ return "bg-gray-500"; }
|
||||
if(typeColor === "error"){ return "bg-red-500"; }
|
||||
if(typeColor === "success"){ return "bg-green-500"; }
|
||||
return "";
|
||||
})();
|
||||
|
||||
const handleClick = (e: MouseEvent) => !disabled && onClick(e);
|
||||
|
||||
return (
|
||||
<div ref={ref} onClick={onClick} title={t(title)} className={`${className} overflow-hidden cursor-pointer group ${(!withBar && !disabled && (!!typeColor || !!color)) && "hover:brightness-[1.15]"} ${disabled && "brightness-75 cursor-not-allowed"} ${renderTypeColor}`} style={{...style, backgroundColor: primaryColor || color}}>
|
||||
<div ref={ref} onClick={handleClick} title={t(title)} className={`${className} overflow-hidden cursor-pointer group ${(!withBar && !disabled && (!!typeColor || !!color)) && "hover:brightness-[1.15]"} ${disabled && "brightness-75 cursor-not-allowed"} ${renderTypeColor}`} style={{...style, backgroundColor: primaryColor || color}}>
|
||||
{ image && <BsmImage image={image} className={imgClassName}/> }
|
||||
{ icon && <BsmIcon icon={icon} className={iconClassName ?? "h-full w-full text-gray-800 dark:text-white"} style={{color: iconColor}}/> }
|
||||
{text && (type === "submit" ? <button type="submit" className={textClassName || "h-full w-full"} style={{...(!!textColor && {color: textColor})}}>{t(text)}</button> : <span className={textClassName} style={{...(!!textColor && {color: `${textColor}`})}}>{t(text)}</span>)}
|
||||
|
||||
@@ -37,6 +37,6 @@ export const BsmImage = forwardRef(({className, image, errorImage, placeholder,
|
||||
|
||||
return (
|
||||
// @ts-ignore
|
||||
<img ref={ref} title={title} className={className} src={image} loading={loading} onLoad={handleLoaded} onError={handleError} style={styles} onClick={(e) => onClick?.(e)} alt=" "/>
|
||||
<img ref={ref} title={title} className={className} src={image} loading={loading} onLoad={handleLoaded} onError={handleError} style={styles} onClick={(e) => onClick?.(e)} alt=" " decoding="async"/>
|
||||
)
|
||||
})
|
||||
|
||||
@@ -4,9 +4,9 @@ export const defaultConfiguration: {[key in DefaultConfigKey]: any} = {
|
||||
"theme": "os",
|
||||
"language": window.navigator.language.length <= 2 ? `${window.navigator.language}-${window.navigator.language.toLocaleUpperCase()}` : window.navigator.language,
|
||||
"supported_languages": ["en-US", "en-EN", "fr-FR", "es-ES"],
|
||||
"default_mods": ["SongCore", "ScoreSaber", "BeatSaverDownloader", "BeatSaverVoting", "PlaylistManager", "ModelDownloader"]
|
||||
"default_mods": ["SongCore", "WhyIsThereNoLeaderboard", "BeatSaverDownloader", "BeatSaverVoting", "PlaylistManager"]
|
||||
}
|
||||
|
||||
export type DefaultConfigKey = "first-color" | "second-color" | "theme" | "language" | "supported_languages" | "default_mods";
|
||||
|
||||
export type ThemeConfig = "dark" | "light" | "os"
|
||||
export type ThemeConfig = "dark" | "light" | "os"
|
||||
|
||||
@@ -293,7 +293,7 @@ export function SettingsPage() {
|
||||
|
||||
<SettingContainer title="pages.settings.patreon.title" description="pages.settings.patreon.description">
|
||||
<div className="flex gap-2">
|
||||
<BsmButton className="flex w-fit rounded-md h-8 px-2 font-bold py-1 whitespace-nowrap !bg-red-500 !text-white" text="pages.settings.patreon.buttons.support" withBar={false} onClick={openSupportPage}/>
|
||||
<BsmButton disabled color="#ef4444" className="flex w-fit rounded-md h-8 px-2 font-bold py-1 whitespace-nowrap !text-white" text="pages.settings.patreon.buttons.support" withBar={false} onClick={openSupportPage}/>
|
||||
<BsmButton className="flex w-fit rounded-md h-8 px-2 font-bold py-1 !text-white" withBar={false} text="pages.settings.patreon.buttons.supporters" color="#6c5ce7" onClick={toogleShowSupporters}/>
|
||||
</div>
|
||||
<SettingContainer className="mt-3" description="pages.settings.discord.description">
|
||||
|
||||
Vendored
+5
-4
@@ -1,15 +1,16 @@
|
||||
import { Channels, ReplyChannels } from 'main/preload';
|
||||
import { IpcChannel } from "shared/models/ipc/ipc-response.interface";
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
electron: {
|
||||
ipcRenderer: {
|
||||
sendMessage(channel: Channels, args: any): void;
|
||||
sendMessage(channel: IpcChannel, args: any): void;
|
||||
on(
|
||||
channel: ReplyChannels,
|
||||
channel: IpcChannel,
|
||||
func: (...args: any) => void
|
||||
): (() => void) | undefined;
|
||||
once(channel: ReplyChannels, func: (...args: any) => void): void;
|
||||
once(channel: IpcChannel, func: (...args: any) => void): void;
|
||||
removeAllListeners(channel: IpcChannel): void;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { defaultIfEmpty } from "rxjs/operators";
|
||||
import { Observable } from "rxjs";
|
||||
import { IpcRequest, IpcResponse } from "shared/models/ipc";
|
||||
import { identity } from "rxjs";
|
||||
|
||||
export class IpcService {
|
||||
|
||||
@@ -47,4 +49,30 @@ export class IpcService {
|
||||
return obs;
|
||||
}
|
||||
|
||||
// TODO : Convert all IPCs calls to V2
|
||||
|
||||
public sendV2<T, U = unknown>(channel: string, request?: IpcRequest<U>, defaultValue?: T): Observable<T>{
|
||||
if(!request){ request = {args: null, responceChannel: null}; }
|
||||
if(!request.responceChannel){ request.responceChannel = `${channel}_responce_${new Date().getTime()}`; }
|
||||
|
||||
const completeChannel = `${request.responceChannel}_complete`;
|
||||
const errorChannel = `${request.responceChannel}_error`;
|
||||
|
||||
const obs = new Observable<T>(observer => {
|
||||
window.electron.ipcRenderer.on(request.responceChannel, (res: T) => observer.next(res));
|
||||
window.electron.ipcRenderer.on(errorChannel, (err: Error) => observer.error(err));
|
||||
window.electron.ipcRenderer.on(completeChannel, () => observer.complete());
|
||||
}).pipe(defaultValue ? defaultIfEmpty(defaultValue) : identity);
|
||||
|
||||
window.electron.ipcRenderer.once(completeChannel, () => {
|
||||
window.electron.ipcRenderer.removeAllListeners(request.responceChannel);
|
||||
window.electron.ipcRenderer.removeAllListeners(errorChannel);
|
||||
window.electron.ipcRenderer.removeAllListeners(completeChannel);
|
||||
});
|
||||
|
||||
window.electron.ipcRenderer.sendMessage(channel, request);
|
||||
|
||||
return obs;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import { IpcService } from "./ipc.service";
|
||||
import { OsDiagnosticService } from "./os-diagnostic.service";
|
||||
import equal from "fast-deep-equal/es6";
|
||||
import { CSSProperties } from "react";
|
||||
import { BsmLocalMap } from "shared/models/maps/bsm-local-map.interface";
|
||||
|
||||
export class MapsDownloaderService {
|
||||
|
||||
@@ -28,7 +29,7 @@ export class MapsDownloaderService {
|
||||
private readonly mapsQueue$: BehaviorSubject<MapDownload[]> = new BehaviorSubject([]);
|
||||
private readonly currentDownload$: BehaviorSubject<MapDownload> = new BehaviorSubject(null);
|
||||
private queueMaxLenght = 0;
|
||||
private downloadedListerners: ((map: BsvMapDetail, version: BSVersion) => void)[] = [];
|
||||
private downloadedListerners: ((map: BsmLocalMap, version: BSVersion) => void)[] = [];
|
||||
public readonly progressBarStyle: CSSProperties = {zIndex: 100000, position: "fixed", bottom: "10px", right: 0};
|
||||
|
||||
private constructor(){
|
||||
@@ -50,10 +51,10 @@ export class MapsDownloaderService {
|
||||
while(this.mapsQueue$.value.at(0)){
|
||||
const toDownload = this.mapsQueue$.value.at(0);
|
||||
this.currentDownload$.next(toDownload);
|
||||
const downloaded = await this.downloadMap(toDownload.map, toDownload.version);
|
||||
const downloaded = await this.downloadMap(toDownload.map, toDownload.version).toPromise();
|
||||
|
||||
if(downloaded){
|
||||
this.downloadedListerners.forEach(func => func(toDownload.map, toDownload.version));
|
||||
this.downloadedListerners.forEach(func => func(downloaded, toDownload.version));
|
||||
}
|
||||
|
||||
const newArr = [...this.mapsQueue$.value];
|
||||
@@ -67,14 +68,13 @@ export class MapsDownloaderService {
|
||||
this.progressBar.hide(true);
|
||||
}
|
||||
|
||||
private async downloadMap(map: BsvMapDetail, version: BSVersion): Promise<boolean>{
|
||||
if(this.os.isOffline){ return false }
|
||||
const res = await this.ipc.send<void, {map: BsvMapDetail, version: BSVersion}>("download-map", {args: {map, version}});
|
||||
return res.success;
|
||||
private downloadMap(map: BsvMapDetail, version: BSVersion): Observable<BsmLocalMap>{
|
||||
if(this.os.isOffline){ return null }
|
||||
return this.ipc.sendV2<BsmLocalMap, {map: BsvMapDetail, version: BSVersion}>("download-map", {args: {map, version}});
|
||||
}
|
||||
|
||||
public async openDownloadMapModal(version?: BSVersion): Promise<ModalResponse<void>>{
|
||||
const res = await this.modals.openModal(DownloadMapsModal, version);
|
||||
public async openDownloadMapModal(version?: BSVersion, ownedMaps: BsmLocalMap[] = []): Promise<ModalResponse<void>>{
|
||||
const res = await this.modals.openModal(DownloadMapsModal, {version, ownedMaps});
|
||||
this.progressBar.setStyle(null);
|
||||
return res;
|
||||
}
|
||||
@@ -109,11 +109,11 @@ export class MapsDownloaderService {
|
||||
return this.mapsQueue$.asObservable();
|
||||
}
|
||||
|
||||
public addOnMapDownloadedListener(func: (map: BsvMapDetail, version: BSVersion) => void){
|
||||
public addOnMapDownloadedListener(func: (map: BsmLocalMap, version: BSVersion) => void){
|
||||
this.downloadedListerners.push(func);
|
||||
}
|
||||
|
||||
public removeOnMapDownloadedListene(func: (map: BsvMapDetail, version: BSVersion) => void){
|
||||
public removeOnMapDownloadedListener(func: (map: BsmLocalMap, version: BSVersion) => void){
|
||||
const funcIndex = this.downloadedListerners.indexOf(func);
|
||||
if(funcIndex < 0){ return; }
|
||||
this.downloadedListerners.splice(funcIndex, 1);
|
||||
|
||||
@@ -2,8 +2,7 @@ import { LinkMapsModal } from "renderer/components/modal/modal-types/link-maps-m
|
||||
import { UnlinkMapsModal } from "renderer/components/modal/modal-types/unlink-maps-modal.component";
|
||||
import { Subject, Observable } from "rxjs";
|
||||
import { BSVersion } from "shared/bs-version.interface";
|
||||
import { BsmLocalMap } from "shared/models/maps/bsm-local-map.interface";
|
||||
import { BeatSaverService } from "./thrird-partys/beat-saver.service";
|
||||
import { BsmLocalMapsProgress, BsmLocalMap, DeleteMapsProgress } from "shared/models/maps/bsm-local-map.interface";
|
||||
import { IpcService } from "./ipc.service";
|
||||
import { ModalExitCode, ModalService } from "./modale.service";
|
||||
import { DeleteMapsModal } from "renderer/components/modal/modal-types/delete-maps-modal.component";
|
||||
@@ -11,6 +10,10 @@ import { ProgressBarService } from "./progress-bar.service";
|
||||
import { OpenSaveDialogOption } from "shared/models/ipc";
|
||||
import { NotificationService } from "./notification.service";
|
||||
import { ConfigurationService } from "./configuration.service";
|
||||
import { ArchiveProgress } from "shared/models/archive.interface";
|
||||
import { map, last, catchError } from "rxjs/operators";
|
||||
import { of } from "rxjs";
|
||||
import { ProgressionInterface } from "shared/models/progress-bar";
|
||||
|
||||
export class MapsManagerService {
|
||||
|
||||
@@ -24,7 +27,6 @@ export class MapsManagerService {
|
||||
public static readonly REMEMBER_CHOICE_DELETE_MAP_KEY = "not-confirm-delete-map"
|
||||
|
||||
private readonly ipcService: IpcService;
|
||||
private readonly bsaver: BeatSaverService;
|
||||
private readonly modal: ModalService;
|
||||
private readonly progressBar: ProgressBarService;
|
||||
private readonly notifications: NotificationService;
|
||||
@@ -35,32 +37,14 @@ export class MapsManagerService {
|
||||
|
||||
private constructor(){
|
||||
this.ipcService = IpcService.getInstance();
|
||||
this.bsaver = BeatSaverService.getInstance();
|
||||
this.modal = ModalService.getInsance();
|
||||
this.progressBar = ProgressBarService.getInstance();
|
||||
this.notifications = NotificationService.getInstance();
|
||||
this.config = ConfigurationService.getInstance();
|
||||
}
|
||||
|
||||
public getMaps(version?: BSVersion, withDetails = true): Observable<BsmLocalMap[]>{
|
||||
return new Observable(obs => {
|
||||
this.ipcService.send<BsmLocalMap[], BSVersion>("get-version-maps", {args: version}).then(res => {
|
||||
if(!res.success){ return obs.complete();}
|
||||
|
||||
obs.next(res.data);
|
||||
|
||||
if(!withDetails){ return obs.complete(); }
|
||||
|
||||
this.bsaver.getMapDetailsFromHashs(res.data.map(localMap => localMap.hash)).then(mapsDetails => {
|
||||
mapsDetails.forEach(details => {
|
||||
const corespondingMap = res.data.find(localMap => localMap.hash === details.versions.find(details => details?.hash === localMap.hash)?.hash);
|
||||
if(!corespondingMap){ return; }
|
||||
res.data.find(localMap => localMap.hash === details.versions.find(details => details?.hash === localMap.hash)?.hash).bsaverInfo = details
|
||||
});
|
||||
obs.next(res.data);
|
||||
})
|
||||
});
|
||||
});
|
||||
public getMaps(version?: BSVersion): Observable<BsmLocalMapsProgress>{
|
||||
return this.ipcService.sendV2<BsmLocalMapsProgress>("load-version-maps", {args: version}, {loaded: 0, total: 0, maps: []});
|
||||
}
|
||||
|
||||
public versionHaveMapsLinked(version: BSVersion): Promise<boolean>{
|
||||
@@ -129,17 +113,15 @@ export class MapsManagerService {
|
||||
|
||||
const showProgressBar = this.progressBar.require();
|
||||
|
||||
if(showProgressBar){
|
||||
this.progressBar.showFake(.008);
|
||||
}
|
||||
const progress$ = this.ipcService.sendV2<DeleteMapsProgress>("delete-maps", {args: maps}).pipe(map(progress => (progress.deleted / progress.total) * 100));
|
||||
|
||||
const res = await this.ipcService.send<void, {version: BSVersion, maps: BsmLocalMap[]}>("delete-maps", {args: {version, maps}});
|
||||
progress$.subscribe(console.log);
|
||||
|
||||
if(showProgressBar){
|
||||
this.progressBar.hide(true);
|
||||
}
|
||||
showProgressBar && this.progressBar.show(progress$, true);
|
||||
|
||||
return res.success;
|
||||
progress$.toPromise().finally(() => this.progressBar.hide(true));
|
||||
|
||||
return progress$.pipe(last(), map(() => true), catchError(() => of(false))).toPromise().catch(() => false);
|
||||
}
|
||||
|
||||
public async exportMaps(version: BSVersion, maps?: BsmLocalMap[]): Promise<void>{
|
||||
@@ -152,18 +134,22 @@ export class MapsManagerService {
|
||||
|
||||
if(!resFile.success){ return; }
|
||||
|
||||
this.progressBar.showFake(.008);
|
||||
|
||||
const resExport = await this.ipcService.send<string, {version: BSVersion, maps: BsmLocalMap[], outPath: string}>("export-maps", {args: {version, maps, outPath: resFile.data}});
|
||||
if(!resExport.success && resExport.error.title){
|
||||
const {title, msg} = resExport.error;
|
||||
this.notifications.notifyError({title, desc: msg});
|
||||
}
|
||||
else {
|
||||
const exportProgress$: Observable<ProgressionInterface> = await this.ipcService.sendV2<ArchiveProgress, {version: BSVersion, maps: BsmLocalMap[], outPath: string}>("export-maps", {args: {version, maps, outPath: resFile.data}}).pipe(
|
||||
map(p => {
|
||||
return { progression: (p.prossesedFiles / p.totalFiles) * 100, label: `${p.prossesedFiles} / ${p.totalFiles}` } as ProgressionInterface
|
||||
})
|
||||
);
|
||||
|
||||
this.progressBar.show(exportProgress$, true);
|
||||
|
||||
await exportProgress$.toPromise().catch(e => {
|
||||
this.notifications.notifyError({title: "notifications.types.error", desc: e.message});
|
||||
}).then(() => {
|
||||
this.notifications.notifySuccess({title: "Export terminé 🎉", duration: 3000});
|
||||
}
|
||||
this.progressBar.complete();
|
||||
this.progressBar.hide(true);
|
||||
this.progressBar.complete();
|
||||
this.progressBar.hide(true);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public async isDeepLinksEnabled(): Promise<boolean>{
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
export interface ArchiveProgress{
|
||||
totalFiles: number;
|
||||
prossesedFiles: number;
|
||||
}
|
||||
@@ -1,4 +1,9 @@
|
||||
import { Observable } from "rxjs";
|
||||
import { IpcResponse } from "./ipc-response.interface";
|
||||
|
||||
export interface IpcRequest<T>{
|
||||
args?: T,
|
||||
responceChannel?: string
|
||||
}
|
||||
responceChannel?: string,
|
||||
}
|
||||
|
||||
export type IpcReplier= <T>(data: Observable<T>) => void;
|
||||
@@ -4,4 +4,8 @@ export interface IpcResponse<T>{
|
||||
data?: T,
|
||||
error?: BsmException,
|
||||
success: boolean,
|
||||
}
|
||||
}
|
||||
|
||||
export type IpcChannel = string;
|
||||
export type IpcErrorChannel = IpcChannel & `${string}_error`;
|
||||
export type IpcCompleteChannel = IpcChannel & `${string}_complete`;
|
||||
@@ -7,4 +7,16 @@ export interface BsmLocalMap {
|
||||
songUrl: string,
|
||||
rawInfo: RawMapInfoData,
|
||||
bsaverInfo?: BsvMapDetail
|
||||
path: string
|
||||
}
|
||||
|
||||
export interface BsmLocalMapsProgress {
|
||||
total: number,
|
||||
loaded: number,
|
||||
maps: BsmLocalMap[],
|
||||
}
|
||||
|
||||
export interface DeleteMapsProgress {
|
||||
total: number,
|
||||
deleted: number
|
||||
}
|
||||
Reference in New Issue
Block a user