From 9862dfa78d3efaeb3e3f8b1cab4f412f7cb35211 Mon Sep 17 00:00:00 2001 From: MathieuG-P <40181755+Zagrios@users.noreply.github.com> Date: Mon, 13 Mar 2023 23:55:22 +0100 Subject: [PATCH] force not launch steamvr when desktop mode --- src/main/constants.ts | 2 ++ src/main/ipcs/window-manager-ipcs.ts | 5 +++ src/main/main.ts | 11 ++---- src/main/services/bs-launcher.service.ts | 43 +++++++++++++++++++++--- src/main/services/steam.service.ts | 2 +- 5 files changed, 50 insertions(+), 13 deletions(-) diff --git a/src/main/constants.ts b/src/main/constants.ts index 74ca8198..f9fb7319 100644 --- a/src/main/constants.ts +++ b/src/main/constants.ts @@ -3,3 +3,5 @@ export const OCULUS_BS_DIR = "hyperbolic-magnetism-beat-saber" export const BS_APP_ID = "620980"; export const BS_DEPOT = "620981"; export const APP_NAME = "BSManager"; + +export const STEAMVR_APP_ID = "250820"; diff --git a/src/main/ipcs/window-manager-ipcs.ts b/src/main/ipcs/window-manager-ipcs.ts index e0393d68..1da08082 100644 --- a/src/main/ipcs/window-manager-ipcs.ts +++ b/src/main/ipcs/window-manager-ipcs.ts @@ -2,6 +2,9 @@ import { ipcMain } from "electron"; import { WindowManagerService } from "../services/window-manager.service"; import { IpcRequest } from "shared/models/ipc"; import { AppWindow } from "shared/models/window-manager/app-window.model"; +import { BSLauncherService } from "../services/bs-launcher.service"; + +const launcher = BSLauncherService.getInstance(); ipcMain.on("open-window-then-close-all", async (event, request: IpcRequest) => { const windowManager = WindowManagerService.getInstance(); @@ -12,11 +15,13 @@ ipcMain.on("open-window-then-close-all", async (event, request: IpcRequest) => { + await launcher.restoreSteamVR(); const windowManager = WindowManagerService.getInstance(); windowManager.closeAllWindows(request.args); }); ipcMain.on("close-windows", async (event, request: IpcRequest) => { + await launcher.restoreSteamVR(); const windowManager = WindowManagerService.getInstance(); windowManager.close(...request.args); }); \ No newline at end of file diff --git a/src/main/main.ts b/src/main/main.ts index 10bd4c52..d3366433 100644 --- a/src/main/main.ts +++ b/src/main/main.ts @@ -20,6 +20,7 @@ import { LocalMapsManagerService } from './services/additional-content/local-map import { LocalPlaylistsManagerService } from './services/additional-content/local-playlists-manager.service'; import { LocalModelsManagerService } from './services/additional-content/local-models-manager.service'; import { APP_NAME } from './constants'; +import { BSLauncherService } from './services/bs-launcher.service'; const isDebug = process.env.NODE_ENV === 'development' || process.env.DEBUG_PROD === 'true'; @@ -63,14 +64,6 @@ const initServicesMustBeInitialized = () => { // Model } -app.on('window-all-closed', () => { - // Respect the OSX convention of having the application in memory even - // after all windows have been closed - if (process.platform !== 'darwin') { - app.quit(); - } -}); - const gotTheLock = app.requestSingleInstanceLock(); if(!gotTheLock){ @@ -108,5 +101,7 @@ else{ callback(pathname); }); + BSLauncherService.getInstance().restoreSteamVR(); + }).catch(log.error); } \ No newline at end of file diff --git a/src/main/services/bs-launcher.service.ts b/src/main/services/bs-launcher.service.ts index 23bdbaac..443b4acb 100644 --- a/src/main/services/bs-launcher.service.ts +++ b/src/main/services/bs-launcher.service.ts @@ -1,12 +1,15 @@ import path from "path"; import { LaunchResult, LauchOption } from "shared/models/bs-launch"; import { UtilsService } from "./utils.service"; -import { BS_EXECUTABLE, BS_APP_ID } from "../constants"; +import { BS_EXECUTABLE, BS_APP_ID, STEAMVR_APP_ID } from "../constants"; import { ChildProcessWithoutNullStreams, spawn } from "child_process"; import { SteamService } from "./steam.service"; import { BSLocalVersionService } from "./bs-local-version.service"; import { OculusService } from "./oculus.service"; import { pathExist } from "../helpers/fs.helpers"; +import { rename } from "fs/promises"; +import log from "electron-log"; +import { timer } from "rxjs"; export class BSLauncherService{ @@ -31,6 +34,23 @@ export class BSLauncherService{ this.localVersionService = BSLocalVersionService.getInstance(); } + private getSteamVRPath(): Promise{ + return this.steamService.getGameFolder(STEAMVR_APP_ID, "SteamVR"); + } + + private async backupSteamVR(): Promise{ + const steamVrFolder = await this.getSteamVRPath(); + if(!await pathExist(steamVrFolder)){ return; } + return rename(steamVrFolder, steamVrFolder + ".bak"); + } + + public async restoreSteamVR(): Promise{ + const steamVrFolder = await this.getSteamVRPath(); + const steamVrBackup = steamVrFolder + ".bak"; + if(!await pathExist(steamVrBackup)){ return; } + return rename(steamVrFolder + ".bak", steamVrFolder); + } + public isBsRunning(): boolean{ return this.bsProcess?.connected || this.utilsService.taskRunning(BS_EXECUTABLE); } @@ -55,6 +75,19 @@ export class BSLauncherService{ launchArgs = Array.from(new Set(launchArgs).values()); + if(launchArgs.includes("fpfc")){ + await this.backupSteamVR().catch(e => { + log.error(e); + this.restoreSteamVR(); + }).finally(() => { + setTimeout(() => this.restoreSteamVR(), 20_000); + }); + await timer(2_000).toPromise(); + } + else{ + await this.restoreSteamVR(); + } + if(launchOptions.debug){ this.bsProcess = spawn(`\"${exePath}\"`, launchArgs, {shell: true, cwd, env: {...process.env, "SteamAppId": BS_APP_ID}, detached: true, windowsVerbatimArguments: true }); } @@ -62,9 +95,11 @@ export class BSLauncherService{ this.bsProcess = spawn(`\"${exePath}\"`, launchArgs, {shell: true, cwd, env: {...process.env, "SteamAppId": BS_APP_ID} }); } - this.bsProcess.on('message', msg => console.log(msg)); - this.bsProcess.on('error', err => console.log(err)); - this.bsProcess.on('exit', code => this.utilsService.ipcSend("bs-launch.exit", {data: code, success: code === 0})); + this.bsProcess.on('error', err => log.error(err)); + this.bsProcess.on('exit', code => { + this.restoreSteamVR(); + this.utilsService.ipcSend("bs-launch.exit", {data: code, success: code === 0}) + }); return "LAUNCHED"; } diff --git a/src/main/services/steam.service.ts b/src/main/services/steam.service.ts index ad6aacb6..80ec8f43 100644 --- a/src/main/services/steam.service.ts +++ b/src/main/services/steam.service.ts @@ -59,7 +59,7 @@ export class SteamService{ for(const libKey in Object.keys(libraryFolders)){ if(!libraryFolders[libKey] || !libraryFolders[libKey]["apps"]){ continue; } - if(libraryFolders[libKey]["apps"][gameId]){ return path.join(libraryFolders[libKey]["path"], "steamapps", "common", gameFolder); }; + if(libraryFolders[libKey]["apps"][gameId] != null){ return path.join(libraryFolders[libKey]["path"], "steamapps", "common", gameFolder); }; } return null; }