From b32d07d2d6c9b637ad5a48ad2f128f7200d409fb Mon Sep 17 00:00:00 2001 From: silentrald Date: Thu, 5 Dec 2024 12:31:46 +0800 Subject: [PATCH] [bugfix] added special handling for NixOS --- electron-builder.config.js | 2 +- .../bs-launcher/abstract-launcher.service.ts | 2 +- .../bs-launcher/steam-launcher.service.ts | 2 +- src/main/services/linux.service.ts | 38 ++++++++++++++++--- 4 files changed, 35 insertions(+), 9 deletions(-) diff --git a/electron-builder.config.js b/electron-builder.config.js index 4775cb77..465ba255 100644 --- a/electron-builder.config.js +++ b/electron-builder.config.js @@ -63,7 +63,7 @@ const config = { // Read/write home directory access "--filesystem=~/BSManager:create", // Default BSManager installation folder "--filesystem=~/.steam/steam/steamapps:ro", // for the libraryfolders.vdf - "--filesystem=~/.steam/steam/steamapps/common:ro", // Steam game folder + "--filesystem=~/.steam/steam/steamapps/common:create", // Steam game folder "--filesystem=~/.steam/steam/steamapps/common/Beat Saber:create", // For installing mods/maps to original Beat Saber version // Allow communication with network "--share=network", diff --git a/src/main/services/bs-launcher/abstract-launcher.service.ts b/src/main/services/bs-launcher/abstract-launcher.service.ts index 347c17eb..6ed46121 100644 --- a/src/main/services/bs-launcher/abstract-launcher.service.ts +++ b/src/main/services/bs-launcher/abstract-launcher.service.ts @@ -52,7 +52,7 @@ export abstract class AbstractLauncherService { spawnOptions.shell = true; // For windows to spawn properly return bsmSpawn(`"${bsExePath}"`, { args, options: spawnOptions, log: true, - linux: { prefix: this.linux.getProtonCommand() }, + linux: { prefix: this.linux.getProtonPrefix() }, flatpak: { host: IS_FLATPAK, env: [ diff --git a/src/main/services/bs-launcher/steam-launcher.service.ts b/src/main/services/bs-launcher/steam-launcher.service.ts index 57075038..8b8816cf 100644 --- a/src/main/services/bs-launcher/steam-launcher.service.ts +++ b/src/main/services/bs-launcher/steam-launcher.service.ts @@ -106,7 +106,7 @@ export class SteamLauncherService extends AbstractLauncherService implements Sto // Linux setup if (process.platform === "linux") { - this.linux.setupLaunch(launchOptions, steamPath, bsFolderPath, env); + await this.linux.setupLaunch(launchOptions, steamPath, bsFolderPath, env); } obs.next({type: BSLaunchEvent.BS_LAUNCHING}); diff --git a/src/main/services/linux.service.ts b/src/main/services/linux.service.ts index f08fba3d..5985eaee 100644 --- a/src/main/services/linux.service.ts +++ b/src/main/services/linux.service.ts @@ -1,12 +1,13 @@ import fs from "fs-extra"; import log from "electron-log"; import path from "path"; -import { BS_APP_ID, PROTON_BINARY_PREFIX, WINE_BINARY_PREFIX } from "main/constants"; +import { BS_APP_ID, IS_FLATPAK, PROTON_BINARY_PREFIX, WINE_BINARY_PREFIX } from "main/constants"; import { StaticConfigurationService } from "./static-configuration.service"; import { CustomError } from "shared/models/exceptions/custom-error.class"; import { BSLaunchError, LaunchOption } from "shared/models/bs-launch"; import { app } from "electron"; import config from "../../../electron-builder.config"; +import { bsmExec } from "main/helpers/os.helpers"; export class LinuxService { private static instance: LinuxService; @@ -19,7 +20,9 @@ export class LinuxService { } private readonly staticConfig: StaticConfigurationService; - private protonCommand = ""; + private protonPrefix = ""; + + private nixOS: boolean | undefined; private constructor() { this.staticConfig = StaticConfigurationService.getInstance(); @@ -27,7 +30,7 @@ export class LinuxService { // === Launching === // - public setupLaunch( + public async setupLaunch( launchOptions: LaunchOption, steamPath: string, bsFolderPath: string, @@ -64,7 +67,10 @@ export class LinuxService { BSLaunchError.PROTON_NOT_FOUND ); } - this.protonCommand = `"${protonPath}" run`; + + this.protonPrefix = await this.isNixOS() + ? `steam-run "${protonPath}" run` + : `"${protonPath}" run`; // Setup Proton environment variables Object.assign(env, { @@ -111,9 +117,9 @@ export class LinuxService { return winePath; } - public getProtonCommand(): string { + public getProtonPrefix(): string { // Set in setupLaunch - return this.protonCommand; + return this.protonPrefix; } // === Flatpak Specific === // @@ -126,4 +132,24 @@ export class LinuxService { ); } + // === NixOS Specific === // + + private async isNixOS(): Promise { + if (this.nixOS !== undefined) { + return this.nixOS; + } + + try { + await bsmExec("nixos-version", { + log: true, + flatpak: { host: IS_FLATPAK }, + }); + this.nixOS = true; + } catch (error) { + log.info("Not NixOS", error); + this.nixOS = false; + } + + return this.nixOS; + } }