Merge branch 'v1.5.0' into feature/playlists/107

This commit is contained in:
MathieuG-P
2024-03-22 15:12:26 +01:00
59 changed files with 695 additions and 1024 deletions
+11 -53
View File
@@ -1,63 +1,21 @@
import { ipcMain } from "electron";
import { UtilsService } from "../services/utils.service";
import { IpcRequest } from "shared/models/ipc";
import { SearchParams } from "shared/models/maps/beat-saver.model";
import { BeatSaverService } from "../services/thrid-party/beat-saver/beat-saver.service";
import log from "electron-log";
import { IpcService } from "../services/ipc.service";
import { from } from "rxjs";
ipcMain.on("bsv-search-map", async (event, request: IpcRequest<SearchParams>) => {
const utlis = UtilsService.getInstance();
const ipc = IpcService.getInstance();
ipc.on("bsv-search-map", (args, reply) => {
const bsvService = BeatSaverService.getInstance();
bsvService
.searchMaps(request.args)
.then(maps => {
utlis.ipcSend(request.responceChannel, { success: true, data: maps });
})
.catch(e => {
utlis.ipcSend(request.responceChannel, { success: false, error: e });
});
reply(from(bsvService.searchMaps(args)));
});
ipcMain.on("bsv-get-map-details-from-hashs", async (event, request: IpcRequest<string[]>) => {
const utlis = UtilsService.getInstance();
ipc.on("bsv-get-map-details-from-hashs", (args, reply) => {
const bsvService = BeatSaverService.getInstance();
bsvService
.getMapDetailsFromHashs(request.args)
.then(maps => {
utlis.ipcSend(request.responceChannel, { success: true, data: maps });
})
.catch(e => {
log.error(e);
utlis.ipcSend(request.responceChannel, { success: false, error: e });
});
reply(from(bsvService.getMapDetailsFromHashs(args)));
});
ipcMain.on("bsv-get-map-details-by-id", async (event, request: IpcRequest<string>) => {
const utlis = UtilsService.getInstance();
ipc.on("bsv-get-map-details-by-id", (args, reply) => {
const bsvService = BeatSaverService.getInstance();
bsvService
.getMapDetailsById(request.args)
.then(maps => {
utlis.ipcSend(request.responceChannel, { success: true, data: maps });
})
.catch(e => {
utlis.ipcSend(request.responceChannel, { success: false, error: e });
});
});
ipcMain.on("bsv-get-playlist-details-by-id", async (event, request: IpcRequest<string>) => {
const utlis = UtilsService.getInstance();
const bsvService = BeatSaverService.getInstance();
bsvService
.getPlaylistPage(request.args)
.then(maps => {
utlis.ipcSend(request.responceChannel, { success: true, data: maps });
})
.catch(e => {
utlis.ipcSend(request.responceChannel, { success: false, error: e });
});
console.log("AAAAAAZEZE", args);
reply(from(bsvService.getMapDetailsById(args)));
});
+6 -8
View File
@@ -1,22 +1,20 @@
import { LaunchOption } from "shared/models/bs-launch";
import { BSLauncherService } from "../services/bs-launcher/bs-launcher.service"
import { IpcService } from '../services/ipc.service';
import { from } from "rxjs";
import { SteamLauncherService } from "../services/bs-launcher/steam-launcher.service";
import { OculusLauncherService } from "../services/bs-launcher/oculus-launcher.service";
import { SteamService } from "../services/steam.service";
import log from "electron-log";
import isElevated from "is-elevated";
const ipc = IpcService.getInstance();
ipc.on<LaunchOption>('bs-launch.launch', (req, reply) => {
ipc.on('bs-launch.launch', (args, reply) => {
const bsLauncher = BSLauncherService.getInstance();
reply(bsLauncher.launch(req.args));
reply(bsLauncher.launch(args));
});
ipc.on<boolean>("bs-launch.need-start-as-admin", (_, reply) => {
ipc.on("bs-launch.need-start-as-admin", (_, reply) => {
const steam = SteamService.getInstance();
reply(from(isElevated().then(elevated => {
if(elevated){ return false; }
@@ -27,12 +25,12 @@ ipc.on<boolean>("bs-launch.need-start-as-admin", (_, reply) => {
})));
});
ipc.on<LaunchOption>("create-launch-shortcut", (req, reply) => {
ipc.on("create-launch-shortcut", (args, reply) => {
const bsLauncher = BSLauncherService.getInstance();
reply(from(bsLauncher.createLaunchShortcut(req.args)));
reply(from(bsLauncher.createLaunchShortcut(args)));
});
ipc.on<void>("bs-launch.restore-steamvr", (_, reply) => {
ipc.on("bs-launch.restore-steamvr", (_, reply) => {
const steamLauncher = SteamLauncherService.getInstance();
reply(from(steamLauncher.restoreSteamVR()));
});
+29 -84
View File
@@ -1,119 +1,64 @@
import { LocalMapsManagerService } from "../services/additional-content/maps/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";
import log from "electron-log"
import { from, of, throwError } from "rxjs";
import { tryit } from "shared/helpers/error.helpers";
const ipc = IpcService.getInstance();
ipc.on("load-version-maps", async (request: IpcRequest<BSVersion>, reply) => {
ipc.on("load-version-maps", (args, reply) => {
const localMaps = LocalMapsManagerService.getInstance();
reply(localMaps.getMaps(request.args));
reply(localMaps.getMaps(args));
});
ipc.on("verion-have-maps-linked", async (request: IpcRequest<BSVersion>) => {
const utils = UtilsService.getInstance();
ipc.on("delete-maps", (args, reply) => {
const maps = LocalMapsManagerService.getInstance();
utils.ipcSend<boolean>(request.responceChannel, { success: true, data: await maps.versionIsLinked(request.args) });
reply(maps.deleteMaps(args));
});
ipc.on("link-version-maps", async (request: IpcRequest<{ version: BSVersion; keepMaps: boolean }>) => {
const utils = UtilsService.getInstance();
ipc.on("export-maps", async (args, reply) => {
const maps = LocalMapsManagerService.getInstance();
maps.linkVersionMaps(request.args.version, request.args.keepMaps)
.then(() => {
utils.ipcSend<void>(request.responceChannel, { success: true });
})
.catch(err => {
utils.ipcSend<void>(request.responceChannel, { success: true, error: err });
});
reply(await maps.exportMaps(args.version, args.maps, args.outPath));
});
ipc.on("unlink-version-maps", async (request: IpcRequest<{ version: BSVersion; keepMaps: boolean }>) => {
const utils = UtilsService.getInstance();
ipc.on("download-map", async (args, reply) => {
const maps = LocalMapsManagerService.getInstance();
maps.unlinkVersionMaps(request.args.version, request.args.keepMaps)
.then(() => {
utils.ipcSend<void>(request.responceChannel, { success: true });
})
.catch(err => {
utils.ipcSend<void>(request.responceChannel, { success: true, error: err });
});
reply(from(maps.downloadMap(args.map, args.version)));
});
ipc.on("delete-maps", async (request: IpcRequest<BsmLocalMap[]>, reply) => {
ipc.on("one-click-install-map", (args, reply) => {
const maps = LocalMapsManagerService.getInstance();
reply(maps.deleteMaps(request.args));
reply(from(maps.oneClickDownloadMap(args)))
});
ipc.on("export-maps", async (request: IpcRequest<{ version: BSVersion; maps: BsmLocalMap[]; outPath: string }>, reply) => {
ipc.on("register-maps-deep-link", (_, reply) => {
const maps = LocalMapsManagerService.getInstance();
reply(await maps.exportMaps(request.args.version, request.args.maps, request.args.outPath));
});
const { error, result } = tryit(() => maps.enableDeepLinks());
ipc.on("download-map", async (request: IpcRequest<{ map: BsvMapDetail; version: BSVersion }>, reply) => {
const maps = LocalMapsManagerService.getInstance();
reply(from(maps.downloadMap(request.args.map, request.args.version)));
});
ipc.on("one-click-install-map", async (request: IpcRequest<BsvMapDetail>) => {
const utils = UtilsService.getInstance();
const maps = LocalMapsManagerService.getInstance();
maps.oneClickDownloadMap(request.args)
.then(() => {
utils.ipcSend(request.responceChannel, { success: true });
})
.catch(err => {
log.error(err);
utils.ipcSend(request.responceChannel, { success: false, error: err });
});
});
ipc.on("register-maps-deep-link", async (request: IpcRequest<void>) => {
const maps = LocalMapsManagerService.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 });
if(error) {
return reply(throwError(() => error));
}
reply(of(result));
});
ipc.on("unregister-maps-deep-link", async (request: IpcRequest<void>) => {
ipc.on("unregister-maps-deep-link", (_, reply) => {
const maps = LocalMapsManagerService.getInstance();
const utils = UtilsService.getInstance();
const { error, result } = tryit(() => maps.disableDeepLinks());
try {
const res = maps.disableDeepLinks();
utils.ipcSend(request.responceChannel, { success: true, data: res });
} catch (e) {
utils.ipcSend(request.responceChannel, { success: false });
if(error) {
return reply(throwError(() => error));
}
reply(of(result));
});
ipc.on("is-map-deep-links-enabled", async (request: IpcRequest<void>) => {
ipc.on("is-map-deep-links-enabled", (_, reply) => {
const maps = LocalMapsManagerService.getInstance();
const utils = UtilsService.getInstance();
const { error, result } = tryit(() => maps.isDeepLinksEnabled());
try {
const res = maps.isDeepLinksEnabled();
utils.ipcSend(request.responceChannel, { success: true, data: res });
} catch (e) {
utils.ipcSend(request.responceChannel, { success: false });
if(error) {
return reply(throwError(() => error));
}
});
ipc.on("get-version-maps-path", async (req: IpcRequest<BSVersion>, reply) => {
const maps = LocalMapsManagerService.getInstance();
reply(from(maps.getMapsFolderPath(req.args)));
reply(of(result));
});
+23 -60
View File
@@ -1,82 +1,45 @@
import { ipcMain } from "electron";
import { UtilsService } from "../services/utils.service";
import { IpcRequest } from "shared/models/ipc";
import { MSModel, MSModelType } from "shared/models/models/model-saber.model";
import { LocalModelsManagerService } from "../services/additional-content/local-models-manager.service";
import { IpcService } from "../services/ipc.service";
import { BSVersion } from "shared/bs-version.interface";
import { BsmLocalModel } from "shared/models/models/bsm-local-model.interface";
import { ModelDownload } from "renderer/services/models-management/models-downloader.service";
import { from, of } from "rxjs";
const ipc = IpcService.getInstance();
ipcMain.on("one-click-install-model", async (event, request: IpcRequest<MSModel>) => {
const utils = UtilsService.getInstance();
ipc.on("one-click-install-model", (args, reply) => {
const models = LocalModelsManagerService.getInstance();
models
.oneClickDownloadModel(request.args)
.then(() => {
utils.ipcSend(request.responceChannel, { success: true });
})
.catch(e => {
utils.ipcSend(request.responceChannel, { success: false, error: e });
});
reply(from(models.oneClickDownloadModel(args)));
});
ipcMain.on("register-models-deep-link", async (event, request: IpcRequest<void>) => {
ipc.on("register-models-deep-link", (_, reply) => {
const models = LocalModelsManagerService.getInstance();
reply(of(models.enableDeepLinks()));
});
ipc.on("unregister-models-deep-link", (_, reply) => {
const models = LocalModelsManagerService.getInstance();
reply(of(models.disableDeepLinks()));
});
ipc.on("is-models-deep-links-enabled", (_, reply) => {
const maps = LocalModelsManagerService.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 });
}
reply(of(maps.isDeepLinksEnabled()));
});
ipcMain.on("unregister-models-deep-link", async (event, request: IpcRequest<void>) => {
const maps = LocalModelsManagerService.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-models-deep-links-enabled", async (event, request: IpcRequest<void>) => {
const maps = LocalModelsManagerService.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 });
}
});
ipc.on<ModelDownload>("download-model", async (req, reply) => {
ipc.on("download-model", (args, reply) => {
const models = LocalModelsManagerService.getInstance();
reply(models.downloadModel(req.args.model, req.args.version));
reply(models.downloadModel(args.model, args.version));
});
ipc.on<{ version: BSVersion; type: MSModelType }>("get-version-models", async (req, reply) => {
ipc.on("get-version-models", (args, reply) => {
const models = LocalModelsManagerService.getInstance();
const res = await models.getModels(req.args.type, req.args.version);
reply(res);
reply(from(models.getModels(args.type, args.version)));
});
ipc.on<{ version: BSVersion; models: BsmLocalModel[]; outPath: string }>("export-models", async (req, reply) => {
ipc.on("export-models", (args, reply) => {
const models = LocalModelsManagerService.getInstance();
reply(models.exportModels(req.args.outPath, req.args.version, req.args.models));
reply(models.exportModels(args.outPath, args.version, args.models));
});
ipc.on<BsmLocalModel[]>("delete-models", async (req, reply) => {
ipc.on("delete-models", (args, reply) => {
const models = LocalModelsManagerService.getInstance();
reply(models.deleteModels(req.args));
reply(models.deleteModels(args));
});
+10 -47
View File
@@ -1,67 +1,30 @@
import { ipcMain } from "electron";
import { BsModsManagerService } from "../services/mods/bs-mods-manager.service";
import { UtilsService } from "../services/utils.service";
import { BSVersion } from "shared/bs-version.interface";
import { IpcRequest } from "shared/models/ipc";
import { Mod } from "shared/models/mods/mod.interface";
import { InstallModsResult } from "shared/models/mods";
import log from "electron-log";
import { IpcService } from "../services/ipc.service";
import { from } from "rxjs";
const ipc = IpcService.getInstance();
ipc.on<BSVersion>("get-available-mods", (req, reply) => {
ipc.on("get-available-mods", (args, reply) => {
const modsManager = BsModsManagerService.getInstance();
reply(from(modsManager.getAvailableMods(req.args)));
reply(from(modsManager.getAvailableMods(args)));
});
ipc.on<BSVersion>("get-installed-mods", (req, reply) => {
ipc.on("get-installed-mods", (args, reply) => {
const modsManager = BsModsManagerService.getInstance();
reply(from(modsManager.getInstalledMods(req.args)));
reply(from(modsManager.getInstalledMods(args)));
});
ipcMain.on("install-mods", (event, request: IpcRequest<{ mods: Mod[]; version: BSVersion }>) => {
const utils = UtilsService.getInstance();
ipc.on("install-mods", (args, reply) => {
const modsManager = BsModsManagerService.getInstance();
modsManager
.installMods(request.args.mods, request.args.version)
.then(nbInstalled => {
utils.ipcSend<InstallModsResult>(request.responceChannel, { success: true, data: nbInstalled });
})
.catch(err => {
utils.ipcSend(request.responceChannel, { success: false, error: err });
log.error("ipc", "install-mods", err, request);
});
reply(from(modsManager.installMods(args.mods, args.version)));
});
ipcMain.on("uninstall-mods", (event, request: IpcRequest<{ mods: Mod[]; version: BSVersion }>) => {
const utils = UtilsService.getInstance();
ipc.on("uninstall-mods", (args, reply) => {
const modsManager = BsModsManagerService.getInstance();
modsManager
.uninstallMods(request.args.mods, request.args.version)
.then(nbInstalled => {
utils.ipcSend(request.responceChannel, { success: true, data: nbInstalled });
})
.catch(err => {
utils.ipcSend(request.responceChannel, { success: false, error: err });
log.error("ipc", "uninstall-mods", err, request);
});
reply(from(modsManager.uninstallMods(args.mods, args.version)));
});
ipcMain.on("uninstall-all-mods", (event, request: IpcRequest<BSVersion>) => {
const utils = UtilsService.getInstance();
ipc.on("uninstall-all-mods", (args, reply) => {
const modsManager = BsModsManagerService.getInstance();
modsManager
.uninstallAllMods(request.args)
.then(nbInstalled => {
utils.ipcSend(request.responceChannel, { success: true, data: nbInstalled });
})
.catch(err => {
utils.ipcSend(request.responceChannel, { success: false, error: err });
log.error("ipc", "uninstall-all-mods", err, request);
});
reply(from(modsManager.uninstallAllMods(args)));
});
+27 -44
View File
@@ -1,63 +1,46 @@
import { BSVersion } from "shared/bs-version.interface";
import { LocalPlaylistsManagerService } from "../services/additional-content/local-playlists-manager.service";
import { IpcService } from "../services/ipc.service";
import { of, throwError } from "rxjs";
import { BPList } from "shared/models/playlists/playlist.interface";
import { of } from "rxjs";
const ipc = IpcService.getInstance();
ipc.on<string>("one-click-install-playlist", (req, reply) => {
const playlists = LocalPlaylistsManagerService.getInstance();
reply(playlists.oneClickInstallPlaylist(req.args));
ipc.on("one-click-install-playlist", (args, reply) => {
const mapsManager = LocalPlaylistsManagerService.getInstance();
reply(mapsManager.oneClickInstallPlaylist(args));
});
ipc.on<{playlist: BPList, version: BSVersion}>("install-playlist", (req, reply) => {
ipc.on("register-playlists-deep-link", (args, reply) => {
const maps = LocalPlaylistsManagerService.getInstance();
reply(of(maps.enableDeepLinks()));
});
ipc.on("unregister-playlists-deep-link", (args, reply) => {
const maps = LocalPlaylistsManagerService.getInstance();
reply(of(maps.disableDeepLinks()));
});
ipc.on("is-playlists-deep-links-enabled", (args, reply) => {
const maps = LocalPlaylistsManagerService.getInstance();
reply(of(maps.isDeepLinksEnabled()));
});
ipc.on("install-playlist", (args, reply) => {
const playlists = LocalPlaylistsManagerService.getInstance();
if(req.args.playlist?.customData?.syncURL){
return reply(playlists.downloadPlaylist(req.args.playlist.customData.syncURL, req.args.version));
if(args.playlist?.customData?.syncURL){
return reply(playlists.downloadPlaylist(args.playlist.customData.syncURL, args.version));
}
reply(playlists.downloadPlaylistSongs(req.args.playlist.songs, req.args.version));
reply(playlists.downloadPlaylistSongs(args.playlist.songs, args.version));
});
ipc.on("register-playlists-deep-link", (_, reply) => {
ipc.on("get-version-playlists-details", (args, reply) => {
const playlists = LocalPlaylistsManagerService.getInstance();
try {
reply(of(playlists.enableDeepLinks()));
} catch (e) {
reply(throwError(() => e));
}
reply(playlists.getVersionPlaylistsDetails(args));
});
ipc.on("unregister-playlists-deep-link", (_, reply) => {
ipc.on("delete-playlist", (args, reply) => {
const playlists = LocalPlaylistsManagerService.getInstance();
try {
reply(of(playlists.disableDeepLinks()));
} catch (e) {
reply(throwError(() => e));
}
});
ipc.on("is-playlists-deep-links-enabled", (_, reply) => {
const playlists = LocalPlaylistsManagerService.getInstance();
try {
reply(of(playlists.isDeepLinksEnabled()));
} catch (e) {
reply(throwError(() => e));
}
});
ipc.on<BSVersion>("get-version-playlists-details", (req, reply) => {
const playlists = LocalPlaylistsManagerService.getInstance();
reply(playlists.getVersionPlaylistsDetails(req.args));
});
ipc.on<{path: string, deleteMaps?: boolean}>("delete-playlist", (req, reply) => {
const playlists = LocalPlaylistsManagerService.getInstance();
reply(playlists.deletePlaylist(req.args));
reply(playlists.deletePlaylist(args));
});
+2 -4
View File
@@ -1,12 +1,10 @@
import { BSVersion } from "shared/bs-version.interface";
import { BSLocalVersionService } from "../services/bs-local-version.service";
import { IpcService } from "../services/ipc.service";
import { from } from "rxjs";
const ipc = IpcService.getInstance();
ipc.on<BSVersion>("bs.uninstall", (req, reply) => {
ipc.on("bs.uninstall", (args, reply) => {
const bsLocalVersionService = BSLocalVersionService.getInstance();
reply(from(bsLocalVersionService.deleteVersion(req.args)));
reply(from(bsLocalVersionService.deleteVersion(args)));
});
@@ -1,18 +1,18 @@
import { BsOculusDownloaderService } from "../../services/bs-version-download/bs-oculus-downloader.service";
import { BsSteamDownloaderService, DownloadInfo, DownloadSteamInfo } from "../../services/bs-version-download/bs-steam-downloader.service";
import { BsSteamDownloaderService } from "../../services/bs-version-download/bs-steam-downloader.service";
import { InstallationLocationService } from "../../services/installation-location.service";
import { IpcService } from "../../services/ipc.service";
import { from, of } from "rxjs";
import { BSLocalVersionService, ImportVersionOptions } from "../../services/bs-local-version.service";
import { BSLocalVersionService } from "../../services/bs-local-version.service";
const ipc = IpcService.getInstance();
ipc.on<ImportVersionOptions>("import-version", (req, reply) => {
ipc.on("import-version", (args, reply) => {
const versionManager = BSLocalVersionService.getInstance();
reply(versionManager.importVersion(req.args));
reply(versionManager.importVersion(args));
});
// #region Steam
// #region Steam
ipc.on("is-dotnet-6-installed", (_, reply) => {
const installer = BsSteamDownloaderService.getInstance();
@@ -24,24 +24,24 @@ ipc.on("bs-download.installation-folder", (_, reply) => {
reply(from(installLocation.installationDirectory()));
});
ipc.on<string>("bs-download.set-installation-folder", (req, reply) => {
ipc.on("bs-download.set-installation-folder", (args, reply) => {
const installerService = InstallationLocationService.getInstance();
reply(from(installerService.setInstallationDirectory(req.args)));
reply(from(installerService.setInstallationDirectory(args)));
});
ipc.on<DownloadSteamInfo>("auto-download-bs-version", (req, reply) => {
ipc.on("auto-download-bs-version", (args, reply) => {
const bsInstaller = BsSteamDownloaderService.getInstance();
reply(bsInstaller.autoDownloadBsVersion(req.args));
reply(bsInstaller.autoDownloadBsVersion(args));
});
ipc.on<DownloadSteamInfo>("download-bs-version", (req, reply) => {
ipc.on("download-bs-version", (args, reply) => {
const bsInstaller = BsSteamDownloaderService.getInstance();
reply(bsInstaller.downloadBsVersion(req.args))
reply(bsInstaller.downloadBsVersion(args))
});
ipc.on<DownloadSteamInfo>("download-bs-version-qr", (req, reply) => {
ipc.on("download-bs-version-qr", (args, reply) => {
const bsInstaller = BsSteamDownloaderService.getInstance();
reply(bsInstaller.downloadBsVersionWithQRCode(req.args))
reply(bsInstaller.downloadBsVersionWithQRCode(args))
});
ipc.on("stop-download-bs-version", (_, reply) => {
@@ -49,23 +49,18 @@ ipc.on("stop-download-bs-version", (_, reply) => {
reply(of(bsInstaller.stopDownload()));
});
ipc.on<string>("send-input-bs-download", (req, reply) => {
ipc.on("send-input-bs-download", (args, reply) => {
const bsInstaller = BsSteamDownloaderService.getInstance();
reply(of(bsInstaller.sendInput(req.args)));
reply(of(bsInstaller.sendInput(args)));
});
// #endregion
// #region Oculus
ipc.on<DownloadInfo>("bs-oculus-download", async (req, reply) => {
ipc.on("bs-oculus-download", async (args, reply) => {
const oculusDownloader = BsOculusDownloaderService.getInstance();
reply(oculusDownloader.downloadVersion(req.args));
});
ipc.on<DownloadInfo>("bs-oculus-auto-download", async (req, reply) => {
const oculusDownloader = BsOculusDownloaderService.getInstance();
reply(oculusDownloader.autoDownloadVersion(req.args));
reply(oculusDownloader.downloadVersion(args));
});
ipc.on("bs-oculus-stop-download", async (_, reply) => {
@@ -73,14 +68,4 @@ ipc.on("bs-oculus-stop-download", async (_, reply) => {
reply(of(oculusDownloader.stopDownload()));
});
ipc.on("bs-oculus-has-auth-token", async (_, reply) => {
const oculusDownloader = BsOculusDownloaderService.getInstance();
reply(from(oculusDownloader.getAuthToken().then(token => !!token)));
});
ipc.on("bs-oculus-clear-auth-token", async (_, reply) => {
const oculusDownloader = BsOculusDownloaderService.getInstance();
reply(from(oculusDownloader.clearAuthToken()));
});
// #endregion
// #endregion
+38 -142
View File
@@ -1,173 +1,69 @@
import { ipcMain, shell } from "electron";
import { UtilsService } from "../services/utils.service";
import { shell } from "electron";
import { BSVersionLibService } from "../services/bs-version-lib.service";
import { BSVersion } from "shared/bs-version.interface";
import { IpcRequest } from "shared/models/ipc";
import { BSLocalVersionService } from "../services/bs-local-version.service";
import { BsmException } from "shared/models/bsm-exception.model";
import { IpcService } from "../services/ipc.service";
import { from } from "rxjs";
import path from "path";
import { pathExist } from "../helpers/fs.helpers";
import { FolderLinkerService, LinkOptions } from "../services/folder-linker.service";
import { LocalMapsManagerService } from "../services/additional-content/maps/local-maps-manager.service";
import { readJSON, writeJSON } from "fs-extra";
import log from "electron-log";
import { VersionLinkerAction } from "renderer/services/version-folder-linker.service";
import { pathExists } from "fs-extra";
import { VersionFolderLinkerService } from "../services/version-folder-linker.service";
const ipc = IpcService.getInstance();
ipcMain.on("bs-version.get-version-dict", (_event, req: IpcRequest<void>) => {
BSVersionLibService.getInstance()
.getAvailableVersions()
.then(versions => {
UtilsService.getInstance().ipcSend(req.responceChannel, { success: true, data: versions });
})
.catch(() => {
UtilsService.getInstance().ipcSend(req.responceChannel, { success: false });
});
ipc.on("bs-version.get-version-dict", (_, reply) => {
const versionsLib = BSVersionLibService.getInstance();
reply(from(versionsLib.getAvailableVersions()));
});
ipcMain.on("bs-version.installed-versions", async (_event, req: IpcRequest<void>) => {
BSLocalVersionService.getInstance()
.getInstalledVersions()
.then(versions => {
UtilsService.getInstance().ipcSend(req.responceChannel, { success: true, data: versions });
})
.catch(() => {
UtilsService.getInstance().ipcSend(req.responceChannel, { success: false });
});
ipc.on("bs-version.installed-versions", (_, reply) => {
const versions = BSLocalVersionService.getInstance();
reply(from(versions.getInstalledVersions()));
});
ipcMain.on("bs-version.open-folder", async (_event, req: IpcRequest<BSVersion>) => {
const localVersionService = BSLocalVersionService.getInstance();
const versionFolder = await localVersionService.getVersionPath(req.args);
if (!(await pathExist(versionFolder))) return;
shell.openPath(versionFolder);
});
ipcMain.on("bs-version.edit", async (__event, req: IpcRequest<{ version: BSVersion; name: string; color: string }>) => {
BSLocalVersionService.getInstance()
.editVersion(req.args.version, req.args.name, req.args.color)
.then(res => {
UtilsService.getInstance().ipcSend(req.responceChannel, { success: !!res, data: res });
})
.catch((error: BsmException) => {
UtilsService.getInstance().ipcSend(req.responceChannel, { success: false, error });
});
});
ipcMain.on("bs-version.clone", async (_event, req: IpcRequest<{ version: BSVersion; name: string; color: string }>) => {
BSLocalVersionService.getInstance()
.cloneVersion(req.args.version, req.args.name, req.args.color)
.then(res => {
UtilsService.getInstance().ipcSend(req.responceChannel, { success: !!res, data: res });
})
.catch((error: BsmException) => {
UtilsService.getInstance().ipcSend(req.responceChannel, { success: false, error });
});
});
ipc.on("get-version-full-path", async (req: IpcRequest<BSVersion>, reply) => {
const localVersions = BSLocalVersionService.getInstance();
reply(from(localVersions.getVersionPath(req.args)));
});
ipc.on("relative-version-path-to-full", async (req: IpcRequest<{ version: BSVersion; relative: string }>, reply) => {
path.isAbsolute(req.args.relative) && reply(from(Promise.resolve(req.args.relative)));
const localVersions = BSLocalVersionService.getInstance();
const promise = localVersions
.getVersionPath(req.args.version)
.catch(() => null)
.then(versionPath => {
return path.join(versionPath, req.args.relative);
});
ipc.on("bs-version.open-folder", (args, reply) => {
const versions = BSLocalVersionService.getInstance();
const promise = versions.getVersionPath(args).then(versionFolder => {
if(!versionFolder || !pathExists(versionFolder)) return;
shell.openPath(versionFolder);
})
reply(from(promise));
});
ipc.on("full-version-path-to-relative", async (req: IpcRequest<{ version: BSVersion; fullPath: string }>, reply) => {
ipc.on("bs-version.edit", (args, reply) => {
const versions = BSLocalVersionService.getInstance();
reply(from(versions.editVersion(args.version, args.name, args.color)));
});
ipc.on("bs-version.clone", (args, reply) => {
const versions = BSLocalVersionService.getInstance();
reply(from(versions.cloneVersion(args.version, args.name, args.color)));
});
ipc.on("get-version-full-path", (args, reply) => {
const localVersions = BSLocalVersionService.getInstance();
const promise = localVersions
.getVersionPath(req.args.version)
.catch(() => null)
.then(versionPath => {
return path.relative(versionPath, req.args.fullPath);
});
reply(from(promise));
reply(from(localVersions.getVersionPath(args)));
});
ipc.on("get-linked-folders", async (req: IpcRequest<{ version: BSVersion; options?: { relative?: boolean } }>, reply) => {
ipc.on("full-version-path-to-relative", (args, reply) => {
const localVersions = BSLocalVersionService.getInstance();
reply(from(localVersions.getVersionPath(args.version).then(versionPath => path.relative(versionPath, args.fullPath))));
});
ipc.on("get-linked-folders", (args, reply) => {
const versionLinker = VersionFolderLinkerService.getInstance();
reply(from(versionLinker.getLinkedFolders(req.args.version, req.args.options)));
reply(from(versionLinker.getLinkedFolders(args.version, args.options)));
});
ipc.on("link-folder", async (req: IpcRequest<{ folder: string; options?: LinkOptions }>, reply) => {
req.args.options ??= {};
const linker = FolderLinkerService.getInstance();
const relativeMapsFolder = path.join(LocalMapsManagerService.LEVELS_ROOT_FOLDER, LocalMapsManagerService.CUSTOM_LEVELS_FOLDER);
if (req.args.folder.includes(relativeMapsFolder)) {
return reply(from(linker.linkFolder(req.args.folder, { keepContents: req.args.options?.keepContents, intermediateFolder: LocalMapsManagerService.SHARED_MAPS_FOLDER })));
}
if (req.args.folder.includes("UserData")) {
req.args.options = { ...req.args.options, backup: true };
}
const res = from(linker.linkFolder(req.args.folder, req.args.options));
const jsonIPAPath = path.join(req.args.folder, "Beat Saber IPA.json");
if (!(await pathExist(jsonIPAPath))) {
return reply(res);
}
await res.toPromise();
try {
const ipaData = (await readJSON(jsonIPAPath)) ?? ({} as any);
ipaData.YeetMods = false;
await writeJSON(jsonIPAPath, ipaData, { spaces: 4 });
} catch (e) {
log.error("Disable YeetMods", e);
}
reply(res);
});
ipc.on("link-version-folder-action", async (req: IpcRequest<VersionLinkerAction>, reply) => {
ipc.on("link-version-folder-action", (args, reply) => {
const versionLinker = VersionFolderLinkerService.getInstance();
reply(from(versionLinker.doAction(req.args)));
reply(from(versionLinker.doAction(args)));
});
ipc.on("is-version-folder-linked", async (req: IpcRequest<{ version: BSVersion; relativeFolder: string }>, reply) => {
ipc.on("is-version-folder-linked", (args, reply) => {
const versionLinker = VersionFolderLinkerService.getInstance();
reply(from(versionLinker.isFolderLinked(req.args.version, req.args.relativeFolder)));
reply(from(versionLinker.isFolderLinked(args.version, args.relativeFolder)));
});
ipc.on("unlink-folder", async (req: IpcRequest<{ folder: string; options?: LinkOptions }>, reply) => {
req.args.options ??= {};
const linker = FolderLinkerService.getInstance();
const relativeMapsFolder = path.join(LocalMapsManagerService.LEVELS_ROOT_FOLDER, LocalMapsManagerService.CUSTOM_LEVELS_FOLDER);
if (req.args.folder.includes(relativeMapsFolder)) {
return reply(from(linker.unlinkFolder(req.args.folder, { ...req.args.options, intermediateFolder: LocalMapsManagerService.SHARED_MAPS_FOLDER })));
}
if (req.args.folder.includes("UserData")) {
req.args.options = { ...req.args.options, backup: true };
}
reply(from(linker.unlinkFolder(req.args.folder, req.args.options)));
});
ipc.on("relink-all-versions-folders", async (req: IpcRequest<void>, reply) => {
ipc.on("relink-all-versions-folders", (_, reply) => {
const versionLinker = VersionFolderLinkerService.getInstance();
reply(from(versionLinker.relinkAllVersionsFolders()));
});
+5 -13
View File
@@ -1,20 +1,12 @@
import { ipcMain } from "electron";
import { AutoUpdaterService } from "../services/auto-updater.service";
import { IpcRequest } from "shared/models/ipc";
import { UtilsService } from "../services/utils.service";
import { IpcService } from "../services/ipc.service";
import { from } from "rxjs";
import { from, of } from "rxjs";
const ipc = IpcService.getInstance();
ipcMain.on("download-update", async (event, request: IpcRequest<void>) => {
ipc.on("download-update", (_, reply) => {
const updaterService = AutoUpdaterService.getInstance();
const utilsService = UtilsService.getInstance();
updaterService
.downloadUpdate()
.then(res => utilsService.ipcSend(request.responceChannel, { success: res }))
.catch(() => utilsService.ipcSend(request.responceChannel, { success: false }));
reply(from(updaterService.downloadUpdate()));
});
ipc.on("check-update", (_, reply) => {
@@ -22,7 +14,7 @@ ipc.on("check-update", (_, reply) => {
reply(from(updaterService.isUpdateAvailable()));
});
ipcMain.on("install-update", async (event, request: IpcRequest<void>) => {
ipc.on("install-update", (_, reply) => {
const updaterService = AutoUpdaterService.getInstance();
updaterService.quitAndInstall();
reply(of(updaterService.quitAndInstall()));
});
+5 -16
View File
@@ -1,26 +1,15 @@
import { ipcMain } from "electron";
import { IpcRequest } from "shared/models/ipc";
import { ModelSaberService } from "../services/thrid-party/model-saber/model-saber.service";
import { UtilsService } from "../services/utils.service";
import { IpcService } from "../services/ipc.service";
import { MSGetQuery } from "shared/models/models/model-saber.model";
import { from } from "rxjs";
const ipc = IpcService.getInstance();
ipcMain.on("ms-get-model-by-id", async (event, request: IpcRequest<string | number>) => {
const utils = UtilsService.getInstance();
ipc.on("ms-get-model-by-id", (args, reply) => {
const ms = ModelSaberService.getInstance();
ms.getModelById(request.args)
.then(model => {
utils.ipcSend(request.responceChannel, { success: true, data: model });
})
.catch(e => {
utils.ipcSend(request.responceChannel, { success: false, error: e });
});
reply(from(ms.getModelById(args)));
});
ipc.on<MSGetQuery>("search-models", async (req, reply) => {
ipc.on("search-models", async (args, reply) => {
const ms = ModelSaberService.getInstance();
reply(ms.searchModels(req.args));
reply(ms.searchModels(args));
});
+18 -38
View File
@@ -1,9 +1,5 @@
import { ipcMain, shell, dialog, app, BrowserWindow } from "electron";
import { UtilsService } from "../services/utils.service";
import { IpcRequest } from "shared/models/ipc";
import { SystemNotificationOptions } from "shared/models/notification/system-notification.model";
import { shell, dialog, app, BrowserWindow } from "electron";
import { NotificationService } from "../services/notification.service";
import { SteamService } from "../services/steam.service";
import { IpcService } from "../services/ipc.service";
import { from, of } from "rxjs";
@@ -11,53 +7,37 @@ import { from, of } from "rxjs";
const ipc = IpcService.getInstance();
ipcMain.on("new-window", (event, request: IpcRequest<string>) => {
shell.openExternal(request.args);
ipc.on("new-window", (args, reply) => {
reply(from(shell.openExternal(args)));
});
ipc.on<string>("choose-folder", (req, reply) => {
reply(from(dialog.showOpenDialog({ properties: ["openDirectory"], defaultPath: req.args ?? "" })));
ipc.on("choose-folder", (args, reply) => {
reply(from(dialog.showOpenDialog({ properties: ["openDirectory"], defaultPath: args ?? "" })));
});
ipc.on<string>("view-path-in-explorer", (req, reply) => {
reply(of(shell.showItemInFolder(req.args)));
ipc.on("window.progression",(args, reply, sender) => {
BrowserWindow.fromWebContents(sender)?.setProgressBar(args / 100);
reply(of(undefined));
});
ipcMain.on("window.progression", async (event, request: IpcRequest<number>) => {
BrowserWindow.fromWebContents(event.sender)?.setProgressBar(request.args / 100);
});
ipcMain.on("save-file", async (event, request: IpcRequest<{ filename?: string; filters?: Electron.FileFilter[] }>) => {
dialog.showSaveDialog({ properties: ["showOverwriteConfirmation"], defaultPath: request.args.filename, filters: request.args.filters }).then(res => {
const utils = UtilsService.getInstance();
ipc.on("save-file", (args, reply) => {
reply(from(dialog.showSaveDialog({ properties: ["showOverwriteConfirmation"], defaultPath: args.filename, filters: args.filters }).then(res => {
if (res.canceled || !res.filePath) {
utils.ipcSend(request.responceChannel, { success: false });
throw new Error("No file path selected");
}
UtilsService.getInstance().ipcSend(request.responceChannel, { success: true, data: res.filePath });
});
return res.filePath;
})));
});
ipc.on("current-version", (_, reply) => {
reply(of(app.getVersion()));
});
ipcMain.on("open-logs", async (event, request: IpcRequest<void>) => {
shell.openPath(app.getPath("logs"));
ipc.on("open-logs", (_, reply) => {
reply(from(shell.openPath(app.getPath("logs"))));
});
ipcMain.on("notify-system", async (event, request: IpcRequest<SystemNotificationOptions>) => {
NotificationService.getInstance().notify(request.args);
});
ipcMain.on("open-steam", async (event, request: IpcRequest<void>) => {
const steam = SteamService.getInstance();
const utils = UtilsService.getInstance();
steam
.openSteam()
.then(res => {
utils.ipcSend(request.responceChannel, { success: true, data: res });
})
.catch(e => {
utils.ipcSend(request.responceChannel, { success: false, error: e });
});
ipc.on("notify-system", (args, reply) => {
const systemNotification = NotificationService.getInstance();
reply(of(systemNotification.notify(args)));
});
+6 -14
View File
@@ -1,18 +1,10 @@
import { ipcMain } from "electron";
import { SupportersService } from "../services/supporters.service";
import { IpcRequest } from "shared/models/ipc";
import { UtilsService } from "../services/utils.service";
import { IpcService } from "../services/ipc.service";
import { from } from "rxjs";
ipcMain.on("get-supporters", (event, request: IpcRequest<void>) => {
const utils = UtilsService.getInstance();
const ipc = IpcService.getInstance();
ipc.on("get-supporters", (_, reply) => {
const supportersService = SupportersService.getInstance();
supportersService
.getSupporters()
.then(supporters => {
utils.ipcSend(request.responceChannel, { success: true, data: supporters });
})
.catch(() => {
utils.ipcSend(request.responceChannel, { success: false });
});
reply(from(supportersService.getSupporters()));
});
+15 -16
View File
@@ -1,40 +1,39 @@
import { WindowManagerService } from "../services/window-manager.service";
import { AppWindow } from "shared/models/window-manager/app-window.model";
import { IpcService } from "../services/ipc.service";
import { from } from "rxjs";
import { BrowserWindow, ipcMain } from "electron";
import { from, of } from "rxjs";
import { BrowserWindow } from "electron";
const ipc = IpcService.getInstance();
// Native windows control, do not pass through IPC service
ipcMain.on("close-window", async (event) => {
BrowserWindow.fromWebContents(event.sender)?.close();
ipc.on("close-window", (_, reply, sender) => {
reply(of(BrowserWindow.fromWebContents(sender)?.close()));
});
ipcMain.on("maximise-window", async (event) => {
BrowserWindow.fromWebContents(event.sender)?.maximize();
ipc.on("maximise-window", (_, reply, sender) => {
reply(of(BrowserWindow.fromWebContents(sender)?.maximize()));
});
ipcMain.on("minimise-window", async (event) => {
BrowserWindow.fromWebContents(event.sender)?.minimize();
ipc.on("minimise-window", (_, reply, sender) => {
reply(of(BrowserWindow.fromWebContents(sender)?.minimize()));
});
ipcMain.on("unmaximise-window", async (event) => {
BrowserWindow.fromWebContents(event.sender)?.unmaximize();
ipc.on("unmaximise-window", (_, reply, sender) => {
reply(of(BrowserWindow.fromWebContents(sender)?.unmaximize()));
});
ipc.on<AppWindow>("open-window-then-close-all", (req, reply) => {
ipc.on("open-window-then-close-all", (args, reply) => {
const windowManager = WindowManagerService.getInstance();
const res = windowManager.openWindow(req.args).then(() => {
windowManager.closeAllWindows(req.args);
const res = windowManager.openWindow(args).then(() => {
windowManager.closeAllWindows(args);
});
reply(from(res));
});
ipc.on<AppWindow>("open-window-or-focus", (req, reply) => {
ipc.on("open-window-or-focus", (args, reply) => {
const windowManager = WindowManagerService.getInstance();
reply(from(windowManager.openWindowOrFocus(req.args)));
reply(from(windowManager.openWindowOrFocus(args)));
});