mirror of
https://github.com/Zagrios/bs-manager.git
synced 2026-07-03 14:08:25 +02:00
[bugfix-627] added finer permissions for flatpak
handled issue with write only directory with bs-versions.json
This commit is contained in:
@@ -3,8 +3,9 @@ import path from "path";
|
||||
import { writeFileSync } from "fs";
|
||||
import { BSVersion } from "shared/bs-version.interface";
|
||||
import { RequestService } from "./request.service";
|
||||
import { readJSON } from "fs-extra";
|
||||
import { pathExistsSync, readJSON } from "fs-extra";
|
||||
import { allSettled } from "../../shared/helpers/promise.helpers";
|
||||
import { LinuxService } from "./linux.service";
|
||||
|
||||
export class BSVersionLibService {
|
||||
private readonly REMOTE_BS_VERSIONS_URL: string = "https://raw.githubusercontent.com/Zagrios/bs-manager/master/assets/jsons/bs-versions.json";
|
||||
@@ -12,12 +13,14 @@ export class BSVersionLibService {
|
||||
|
||||
private static instance: BSVersionLibService;
|
||||
|
||||
private linuxService: LinuxService;
|
||||
private utilsService: UtilsService;
|
||||
private requestService: RequestService;
|
||||
|
||||
private bsVersions: BSVersion[];
|
||||
|
||||
private constructor() {
|
||||
this.linuxService = LinuxService.getInstance();
|
||||
this.utilsService = UtilsService.getInstance();
|
||||
this.requestService = RequestService.getInstance();
|
||||
}
|
||||
@@ -29,17 +32,29 @@ export class BSVersionLibService {
|
||||
return BSVersionLibService.instance;
|
||||
}
|
||||
|
||||
private getRemoteVersions(): Promise<BSVersion[]> {
|
||||
private async getRemoteVersions(): Promise<BSVersion[]> {
|
||||
return this.requestService.getJSON<BSVersion[]>(this.REMOTE_BS_VERSIONS_URL).then(res => res.data);
|
||||
}
|
||||
|
||||
private async getLocalVersions(): Promise<BSVersion[]> {
|
||||
if (this.linuxService.isFlatpak) {
|
||||
const flatpakVersionsPath = path.join(this.linuxService.getFlatpakLocalVersionFolder(), this.VERSIONS_FILE);
|
||||
if (pathExistsSync(flatpakVersionsPath)) {
|
||||
return readJSON(flatpakVersionsPath);
|
||||
}
|
||||
}
|
||||
|
||||
const localVersionsPath = path.join(this.utilsService.getAssestsJsonsPath(), this.VERSIONS_FILE);
|
||||
return readJSON(localVersionsPath);
|
||||
}
|
||||
|
||||
private async updateLocalVersions(versions: BSVersion[]): Promise<void> {
|
||||
const localVersionsPath = path.join(this.utilsService.getAssestsJsonsPath(), this.VERSIONS_FILE);
|
||||
const localVersionsPath = path.join(
|
||||
this.linuxService.isFlatpak
|
||||
? this.linuxService.getFlatpakLocalVersionFolder()
|
||||
: this.utilsService.getAssestsJsonsPath(),
|
||||
this.VERSIONS_FILE
|
||||
);
|
||||
writeFileSync(localVersionsPath, JSON.stringify(versions, null, "\t"), { encoding: "utf-8", flag: "w" });
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import { BS_APP_ID, PROTON_BINARY_PREFIX, WINE_BINARY_PREFIX } from "main/consta
|
||||
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";
|
||||
|
||||
export class LinuxService {
|
||||
private static instance: LinuxService;
|
||||
@@ -93,30 +94,6 @@ export class LinuxService {
|
||||
return spawn(command, spawnOptions);
|
||||
}
|
||||
|
||||
private createFlatpakCommand(protonPath: string, bsExePath: string, args: string[], spawnOptions: SpawnOptionsWithoutStdio): string {
|
||||
|
||||
// DON'T REMOVE: Good for injecting commands while debugging with flatpak
|
||||
// return args.slice(1).join(" ");
|
||||
|
||||
// The env vars are hidden to flatpak-spawn, need to set them manually in --env arg
|
||||
// Minimal copy of the env, don't need to copy them all
|
||||
const envArgs = [
|
||||
"SteamAppId",
|
||||
"SteamOverlayGameId",
|
||||
"SteamGameId",
|
||||
"WINEDLLOVERRIDES",
|
||||
"STEAM_COMPAT_DATA_PATH",
|
||||
"STEAM_COMPAT_INSTALL_PATH",
|
||||
"STEAM_COMPAT_CLIENT_INSTALL_PATH",
|
||||
"STEAM_COMPAT_APP_ID",
|
||||
"SteamEnv",
|
||||
].map(envName => {
|
||||
return `--env=${envName}="${spawnOptions.env[envName]}"`;
|
||||
}).join(" ");
|
||||
|
||||
return `flatpak-spawn --host ${envArgs} "${protonPath}" run "${bsExePath}" ${args.join(" ")}`;
|
||||
}
|
||||
|
||||
public verifyProtonPath(protonFolder: string = ""): boolean {
|
||||
if (protonFolder === "") {
|
||||
if (!this.staticConfig.has("proton-folder")) {
|
||||
@@ -146,4 +123,39 @@ export class LinuxService {
|
||||
|
||||
return winePath;
|
||||
}
|
||||
|
||||
// === Flatpak Specific === //
|
||||
|
||||
private createFlatpakCommand(protonPath: string, bsExePath: string, args: string[], spawnOptions: SpawnOptionsWithoutStdio): string {
|
||||
|
||||
// DON'T REMOVE: Good for injecting commands while debugging with flatpak
|
||||
// return args.slice(1).join(" ");
|
||||
|
||||
// The env vars are hidden to flatpak-spawn, need to set them manually in --env arg
|
||||
// Minimal copy of the env, don't need to copy them all
|
||||
const envArgs = [
|
||||
"SteamAppId",
|
||||
"SteamOverlayGameId",
|
||||
"SteamGameId",
|
||||
"WINEDLLOVERRIDES",
|
||||
"STEAM_COMPAT_DATA_PATH",
|
||||
"STEAM_COMPAT_INSTALL_PATH",
|
||||
"STEAM_COMPAT_CLIENT_INSTALL_PATH",
|
||||
"STEAM_COMPAT_APP_ID",
|
||||
"SteamEnv",
|
||||
].map(envName => {
|
||||
return `--env=${envName}="${spawnOptions.env[envName]}"`;
|
||||
}).join(" ");
|
||||
|
||||
return `flatpak-spawn --host ${envArgs} "${protonPath}" run "${bsExePath}" ${args.join(" ")}`;
|
||||
}
|
||||
|
||||
public getFlatpakLocalVersionFolder(): string {
|
||||
return path.join(
|
||||
app.getPath("home"),
|
||||
".var", "app", "org.erb.BSManager",
|
||||
"resources", "assets", "jsons"
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user