Skip to content

Commit

Permalink
[feat] inject env vars to launch options with steam format %command%
Browse files Browse the repository at this point in the history
  • Loading branch information
silentrald committed Jan 20, 2025
1 parent 3046519 commit af28909
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
5 changes: 5 additions & 0 deletions assets/jsons/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
"pin": "Pin",
"unpin": "Unpin"
},
"generic": {
"env": {
"parse": "Could not properly parse the enviroment variables passed in the launch options."
}
},
"title-bar": {
"outdated": "outdated"
},
Expand Down
4 changes: 2 additions & 2 deletions src/main/helpers/env.helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
);
}
}
Expand All @@ -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"
);
}
20 changes: 20 additions & 0 deletions src/main/services/linux.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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() {
Expand Down Expand Up @@ -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;
}

Expand Down
7 changes: 6 additions & 1 deletion src/renderer/services/bs-launcher.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)})
Expand Down

0 comments on commit af28909

Please sign in to comment.