[feature] Added admin launch information modal

This commit is contained in:
MathieuG-P
2024-01-24 23:07:49 +01:00
parent 16b9ca79f2
commit 63d35f678d
13 changed files with 151 additions and 14 deletions
+11 -1
View File
@@ -5,6 +5,8 @@ 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 isElevated from "is-elevated";
const ipc = IpcService.getInstance();
@@ -13,6 +15,14 @@ ipc.on<LaunchOption>('bs-launch.launch', (req, reply) => {
reply(bsLauncher.launch(req.args));
});
ipc.on<boolean>("bs-launch.need-start-as-admin", (_, reply) => {
const steam = SteamService.getInstance();
reply(from(isElevated().then(elevated => {
if(elevated){ return false; }
return steam.isElevated();
})));
})
ipc.on<LaunchOption>("create-launch-shortcut", (req, reply) => {
const bsLauncher = BSLauncherService.getInstance();
reply(from(bsLauncher.createLaunchShortcut(req.args)));
@@ -29,4 +39,4 @@ ipc.on<void>("restore-original-oculus-folder", (_, reply) => {
reply(from(
oculusLauncher.deleteBsSymlinks().then(() => oculusLauncher.restoreOriginalBeatSaber())
));
})
})
@@ -106,17 +106,15 @@ export class SteamLauncherService extends AbstractLauncherService implements Sto
obs.next({type: BSLaunchEvent.BS_LAUNCHING});
const needToStartAsAdmin = await this.needStartBsAsAdmin().catch(err => {
log.error("Error while checking if need to start BS as Admin", err);
return false;
});
const launchPromise = !needToStartAsAdmin ? (
const launchPromise = !launchOptions.admin ? (
this.launchBs(exePath, launchArgs, { env: {...process.env, "SteamAppId": BS_APP_ID} })
) : (
new Promise<number>(resolve => {
const adminProcess = exec(`"${this.getStartBsAsAdminExePath()}" "${exePath}" ${launchArgs.join(" ")}`, { env: {...process.env, "SteamAppId": BS_APP_ID} });
adminProcess.on("error", err => {log.error("Error while starting BS as Admin", err); resolve(-1)});
adminProcess.on("error", err => {
log.error("Error while starting BS as Admin", err);
resolve(-1)
});
setTimeout(() => {
adminProcess.removeAllListeners("error");