force not launch steamvr when desktop mode

This commit is contained in:
MathieuG-P
2023-03-13 23:55:22 +01:00
parent e3f91ea593
commit 9862dfa78d
5 changed files with 50 additions and 13 deletions
+2
View File
@@ -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";
+5
View File
@@ -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<AppWindow>) => {
const windowManager = WindowManagerService.getInstance();
@@ -12,11 +15,13 @@ ipcMain.on("open-window-then-close-all", async (event, request: IpcRequest<AppWi
});
ipcMain.on("close-all-windows", async (event, request: IpcRequest<AppWindow>) => {
await launcher.restoreSteamVR();
const windowManager = WindowManagerService.getInstance();
windowManager.closeAllWindows(request.args);
});
ipcMain.on("close-windows", async (event, request: IpcRequest<AppWindow[]>) => {
await launcher.restoreSteamVR();
const windowManager = WindowManagerService.getInstance();
windowManager.close(...request.args);
});
+3 -8
View File
@@ -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);
}
+39 -4
View File
@@ -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<string>{
return this.steamService.getGameFolder(STEAMVR_APP_ID, "SteamVR");
}
private async backupSteamVR(): Promise<void>{
const steamVrFolder = await this.getSteamVRPath();
if(!await pathExist(steamVrFolder)){ return; }
return rename(steamVrFolder, steamVrFolder + ".bak");
}
public async restoreSteamVR(): Promise<void>{
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";
}
+1 -1
View File
@@ -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;
}