mirror of
https://github.com/Zagrios/bs-manager.git
synced 2026-07-03 14:08:25 +02:00
[bugfix] Launch Oculus when launching Oculus BS version to avoid crashs
This commit is contained in:
@@ -61,13 +61,13 @@ export class OculusLauncherService extends AbstractLauncherService implements St
|
||||
log.info("Symlinks found in Oculus library", symlinks);
|
||||
|
||||
const bsSymlinks = symlinks.filter(dirent => dirent.startsWith(OCULUS_BS_DIR));
|
||||
|
||||
|
||||
const bsmSymlinks = (await Promise.all(bsSymlinks.map(async symlink => {
|
||||
const symlinkPath = path.join(oculusLibPath, symlink);
|
||||
const targetPath = await readlink(symlinkPath).catch(err => log.error(err));
|
||||
|
||||
log.info("Oculus Symlink", symlink, "target", targetPath);
|
||||
|
||||
|
||||
if(!targetPath){ return null; }
|
||||
|
||||
const bsmVersionsDir = path.join(this.pathsService.INSTALLATION_FOLDER, this.pathsService.VERSIONS_FOLDER);
|
||||
@@ -138,20 +138,24 @@ export class OculusLauncherService extends AbstractLauncherService implements St
|
||||
if(bsRunning){
|
||||
throw CustomError.fromError(new Error("Cannot start two instance of Beat Saber for Oculus"), BSLaunchError.BS_ALREADY_RUNNING);
|
||||
}
|
||||
|
||||
|
||||
// Remove previously symlinks created by BSM
|
||||
await this.deleteBsSymlinks().catch(err => log.error("Error while deleting BSM symlinks", err));
|
||||
|
||||
const bsPath = await (launchOptions.version.oculus ? prepareOriginalVersion() : prepareDowngradedVersion());
|
||||
|
||||
// Launch Beat Saber
|
||||
const exePath = path.join(bsPath, BS_EXECUTABLE);
|
||||
|
||||
if(!(await pathExists(exePath))){
|
||||
throw CustomError.fromError(new Error(`BS Path not exist ${bsPath}`), BSLaunchError.BS_NOT_FOUND);
|
||||
}
|
||||
|
||||
// Make sure Oculus is running
|
||||
await this.oculus.startOculus().catch(err => log.error("Error while starting Oculus", err));
|
||||
|
||||
obs.next({type: BSLaunchEvent.BS_LAUNCHING});
|
||||
|
||||
// Launch Beat Saber
|
||||
return this.launchBs(exePath, this.buildBsLaunchArgs(launchOptions)).catch(err => {
|
||||
throw CustomError.fromError(err, BSLaunchError.BS_EXIT_ERROR);
|
||||
});
|
||||
@@ -170,4 +174,4 @@ export class OculusLauncherService extends AbstractLauncherService implements St
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,9 @@ import { pathExist, resolveGUIDPath } from "../helpers/fs.helpers";
|
||||
import log from "electron-log";
|
||||
import { lstat } from "fs-extra";
|
||||
import { tryit } from "../../shared/helpers/error.helpers";
|
||||
import { shell } from "electron";
|
||||
import { taskRunning } from "../helpers/os.helpers";
|
||||
import { sToMs } from "../../shared/helpers/time.helpers";
|
||||
|
||||
export class OculusService {
|
||||
private static instance: OculusService;
|
||||
@@ -42,11 +45,11 @@ export class OculusService {
|
||||
const libsPath: OculusLibrary[] = (
|
||||
await Promise.all(libsRegData.keys.map(async key => {
|
||||
const originalPath = await list([`${oculusLibsRegKey}\\${key}`]).then(res => res[`${oculusLibsRegKey}\\${key}`]);
|
||||
|
||||
|
||||
if (originalPath.values?.OriginalPath) {
|
||||
return { id: key, path: originalPath.values.OriginalPath.value, isDefault: defaultLibraryId === key } as OculusLibrary;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(originalPath.values?.Path) {
|
||||
const { result } = tryit(() => resolveGUIDPath(originalPath.values.Path.value as string));
|
||||
return result ? { id: key, path: result, isDefault: defaultLibraryId === key } as OculusLibrary : null;
|
||||
@@ -82,7 +85,7 @@ export class OculusService {
|
||||
|
||||
/**
|
||||
* Return the first game folder found in the list
|
||||
* @param {string[]} gameFolders
|
||||
* @param {string[]} gameFolders
|
||||
*/
|
||||
public async tryGetGameFolder(gameFolders: string[]): Promise<string> {
|
||||
for(const gameFolder of gameFolders){
|
||||
@@ -92,6 +95,29 @@ export class OculusService {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public oculusRunning(): Promise<boolean> {
|
||||
return taskRunning("OculusClient");
|
||||
}
|
||||
|
||||
public async startOculus(): Promise<void>{
|
||||
if(await this.oculusRunning()){ return; }
|
||||
|
||||
await shell.openPath("oculus://view/homepage");
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
const interval = setInterval(async () => {
|
||||
if(!(await this.oculusRunning())){ return; }
|
||||
clearInterval(interval);
|
||||
resolve();
|
||||
}, sToMs(3));
|
||||
|
||||
setTimeout(() => {
|
||||
clearInterval(interval);
|
||||
reject("Unable to open Oculus");
|
||||
}, sToMs(30));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export interface OculusLibrary {
|
||||
|
||||
Reference in New Issue
Block a user