mirror of
https://github.com/Zagrios/bs-manager.git
synced 2026-07-03 14:08:25 +02:00
[feat] inject env vars to launch options with steam format %command%
This commit is contained in:
@@ -28,6 +28,11 @@
|
||||
"pin": "Pin",
|
||||
"unpin": "Unpin"
|
||||
},
|
||||
"generic": {
|
||||
"env": {
|
||||
"parse": "Could not properly parse the env var string."
|
||||
}
|
||||
},
|
||||
"title-bar": {
|
||||
"outdated": "outdated"
|
||||
},
|
||||
|
||||
@@ -107,7 +107,7 @@ export function parseEnvString(envString: string): Record<string, string> {
|
||||
if (state === EnvParserState.ERROR) {
|
||||
throw new CustomError(
|
||||
`parseEnvString failed: invalid character at position ${pos}`,
|
||||
"env.parse"
|
||||
"generic.env.parse"
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -123,6 +123,6 @@ export function parseEnvString(envString: string): Record<string, string> {
|
||||
|
||||
throw new CustomError(
|
||||
"parseEnvString failed: invalid ending state",
|
||||
"env.parse"
|
||||
"generic.env.parse"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import { BsmShellLog, bsmExec } from "main/helpers/os.helpers";
|
||||
import { LaunchMods } from "shared/models/bs-launch/launch-option.interface";
|
||||
import { SteamShortcutData } from "shared/models/steam/shortcut.model";
|
||||
import { buildBsLaunchArgs } from "./bs-launcher/abstract-launcher.service";
|
||||
import { parseEnvString } from "main/helpers/env.helpers";
|
||||
|
||||
export class LinuxService {
|
||||
private static instance: LinuxService;
|
||||
@@ -24,6 +25,7 @@ export class LinuxService {
|
||||
private readonly installLocationService: InstallationLocationService;
|
||||
private readonly staticConfig: StaticConfigurationService;
|
||||
|
||||
private readonly COMMAND_FORMAT = "%command%";
|
||||
private nixOS: boolean | undefined;
|
||||
|
||||
private constructor() {
|
||||
@@ -112,6 +114,24 @@ export class LinuxService {
|
||||
envVars.PROTON_LOG_DIR = path.join(bsFolderPath, "Logs");
|
||||
}
|
||||
|
||||
if (launchOptions.additionalArgs) {
|
||||
const additionalArgs = launchOptions.additionalArgs.join(" ");
|
||||
const index = additionalArgs.indexOf(this.COMMAND_FORMAT);
|
||||
if (index > -1) {
|
||||
const envString = additionalArgs.substring(0, index);
|
||||
log.info("Parsing env string ", `"${envString}"`)
|
||||
for (const [ key, value ] of Object.entries(parseEnvString(envString))) {
|
||||
if (key in envVars) {
|
||||
log.warn("Ignoring", `${key}=${value}`, "already set env launch command");
|
||||
} else {
|
||||
log.info("Injecting", `${key}="${value}"`, "to the env launch command");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
launchOptions.additionalArgs = [ additionalArgs.substring(index + this.COMMAND_FORMAT.length) ];
|
||||
}
|
||||
|
||||
return envVars;
|
||||
}
|
||||
|
||||
|
||||
@@ -61,7 +61,12 @@ export class BSLauncherService {
|
||||
this.notificationService.notifySuccess({title: `notifications.bs-launch.success.titles.${event.type}`, desc: `notifications.bs-launch.success.msg.${event.type}`});
|
||||
},
|
||||
error: (err: CustomError) => {
|
||||
if(!err?.code || !Object.values(BSLaunchError).includes(err.code as BSLaunchError)){
|
||||
if (err?.code?.startsWith("generic.")) {
|
||||
this.notificationService.notifyError({
|
||||
title: "notifications.bs-launch.errors.titles.UNKNOWN_ERROR",
|
||||
desc: err.code,
|
||||
});
|
||||
} else if(!err?.code || !Object.values(BSLaunchError).includes(err.code as BSLaunchError)){
|
||||
this.notificationService.notifyError({title: "notifications.bs-launch.errors.titles.UNKNOWN_ERROR", desc: "notifications.bs-launch.errors.msg.UNKNOWN_ERROR"});
|
||||
} else {
|
||||
this.notificationService.notifyError({title: `notifications.bs-launch.errors.titles.${err.code}`, desc: `notifications.bs-launch.errors.msg.${err.code}`, duration: sToMs(9)})
|
||||
|
||||
Reference in New Issue
Block a user