mirror of
https://github.com/Zagrios/bs-manager.git
synced 2026-07-03 14:08:25 +02:00
[feature] Added admin launch information modal
This commit is contained in:
@@ -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");
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
import { BsmButton } from "renderer/components/shared/bsm-button.component"
|
||||
import { BsmImage } from "renderer/components/shared/bsm-image.component"
|
||||
import { ModalComponent, ModalExitCode } from "renderer/services/modale.service"
|
||||
import BeatConflict from "../../../../../assets/images/apngs/beat-conflict.png";
|
||||
import { useTranslation } from "renderer/hooks/use-translation.hook";
|
||||
import { BsmCheckbox } from "renderer/components/shared/bsm-checkbox.component";
|
||||
import { useState } from "react";
|
||||
|
||||
export const NeedLaunchAdminModal: ModalComponent<boolean, void> = ({resolver}) => {
|
||||
|
||||
const t = useTranslation();
|
||||
|
||||
const [dontShowAgain, setDontShowAgain] = useState(false);
|
||||
|
||||
return (
|
||||
<form className="text-gray-800 dark:text-gray-200 flex flex-col min-w-[350px]">
|
||||
<h1 className="text-3xl uppercase tracking-wide w-full text-center">{t("modals.launch-as-admin.title")}</h1>
|
||||
<BsmImage className="mx-auto h-24" image={BeatConflict} />
|
||||
<div className="flex flex-col gap-3">
|
||||
<p className="w-0 min-w-full">{t("modals.launch-as-admin.body.info")}</p>
|
||||
<p className="w-0 min-w-full">{t("modals.launch-as-admin.body.info-2")}</p>
|
||||
<p className="w-0 min-w-full text-sm italic">{t("modals.launch-as-admin.body.info-3")}</p>
|
||||
</div>
|
||||
<div className="flex flex-row justify-start items-center gap-1.5 my-4">
|
||||
<BsmCheckbox className="relative z-[1] w-6 aspect-square" checked={dontShowAgain} onChange={setDontShowAgain} />
|
||||
<span>{t("modals.launch-as-admin.not-remind-me")}</span>
|
||||
</div>
|
||||
<div className="grid grid-flow-col grid-cols-2 gap-4">
|
||||
<BsmButton typeColor="cancel" className="rounded-md text-center flex items-center justify-center transition-all h-8" onClick={() => resolver({ exitCode: ModalExitCode.CANCELED })} withBar={false} text="misc.cancel" />
|
||||
<BsmButton typeColor="primary" className="rounded-md text-center flex items-center justify-center transition-all h-8" onClick={() => resolver({ exitCode: ModalExitCode.COMPLETED, data: dontShowAgain })} withBar={false} text="modals.launch-as-admin.launch-as-admin" />
|
||||
</div>
|
||||
</form>
|
||||
)
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import { ModalExitCode, ModalService } from "./modale.service";
|
||||
import { OriginalOculusVersionBackupModal } from "renderer/components/modal/modal-types/original-oculus-version-backup.modal";
|
||||
import { CustomError } from "shared/models/exceptions/custom-error.class";
|
||||
import { sToMs } from "shared/helpers/time.helpers";
|
||||
import { NeedLaunchAdminModal } from "renderer/components/modal/modal-types/need-launch-admin-modal.component";
|
||||
|
||||
export class BSLauncherService {
|
||||
private static instance: BSLauncherService;
|
||||
@@ -21,7 +22,7 @@ export class BSLauncherService {
|
||||
private readonly modals: ModalService;
|
||||
|
||||
public readonly versionRunning$: BehaviorSubject<BSVersion> = new BehaviorSubject(null);
|
||||
|
||||
|
||||
public static getInstance(){
|
||||
if(!BSLauncherService.instance){ BSLauncherService.instance = new BSLauncherService(); }
|
||||
return BSLauncherService.instance;
|
||||
@@ -70,7 +71,17 @@ export class BSLauncherService {
|
||||
}
|
||||
}))
|
||||
}
|
||||
|
||||
|
||||
private async doMustStartAsAdmin(): Promise<boolean> {
|
||||
const needAdmin = await lastValueFrom(this.ipcService.sendV2<boolean, void>("bs-launch.need-start-as-admin"));
|
||||
if(!needAdmin){ return false; }
|
||||
if(this.config.get("dont-remind-admin")){ return true; }
|
||||
const modalRes = await this.modals.openModal(NeedLaunchAdminModal);
|
||||
if(modalRes.exitCode !== ModalExitCode.COMPLETED){ throw new Error("Admin launch canceled"); }
|
||||
this.config.set("dont-remind-admin", modalRes.data);
|
||||
return true;
|
||||
}
|
||||
|
||||
public doLaunch(launchOptions: LaunchOption): Observable<BSLaunchEventData>{
|
||||
return this.ipcService.sendV2<BSLaunchEventData, LaunchOption>("bs-launch.launch", {args: launchOptions});
|
||||
}
|
||||
@@ -79,17 +90,21 @@ export class BSLauncherService {
|
||||
|
||||
return new Observable<BSLaunchEventData>(obs => {
|
||||
(async () => {
|
||||
|
||||
|
||||
if(launchOptions.version.metadata?.store === BsStore.OCULUS && !this.notRewindBackupOculus()){
|
||||
const { exitCode, data: notRewind } = await this.modals.openModal(OriginalOculusVersionBackupModal);
|
||||
if(exitCode !== ModalExitCode.COMPLETED){ return; }
|
||||
this.setNotRewindBackupOculus(notRewind);
|
||||
}
|
||||
|
||||
|
||||
if(launchOptions.version.metadata?.store !== BsStore.OCULUS){
|
||||
launchOptions.admin = await this.doMustStartAsAdmin();
|
||||
}
|
||||
|
||||
const launch$ = this.handleLaunchEvents(this.doLaunch(launchOptions));
|
||||
|
||||
await lastValueFrom(launch$);
|
||||
|
||||
|
||||
})().then(() => {
|
||||
obs.complete();
|
||||
}).catch(err => {
|
||||
|
||||
@@ -5,5 +5,6 @@ export interface LaunchOption {
|
||||
oculus?: boolean,
|
||||
desktop?: boolean,
|
||||
debug?: boolean,
|
||||
additionalArgs?: string[]
|
||||
additionalArgs?: string[],
|
||||
admin?: boolean,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user