From a54f81de423a4df9a59431841c6e78386a521de7 Mon Sep 17 00:00:00 2001 From: silentrald Date: Sat, 21 Dec 2024 22:59:11 +0800 Subject: [PATCH] [feat] add proton logs in advance launch settings for linux --- assets/jsons/translations/en.json | 4 +- .../bs-launcher/bs-launcher.service.ts | 2 + src/main/services/linux.service.ts | 13 ++++-- .../slides/launch/launch-slide.component.tsx | 45 ++++++++++++------- .../bs-launch/launch-option.interface.ts | 1 + 5 files changed, 45 insertions(+), 20 deletions(-) diff --git a/assets/jsons/translations/en.json b/assets/jsons/translations/en.json index 1ef9eab9..5d74e9f8 100644 --- a/assets/jsons/translations/en.json +++ b/assets/jsons/translations/en.json @@ -56,7 +56,9 @@ "skipsteam": "Skip Steam", "skipsteam-description": "Stops Steam from opening automatically with Beat Saber, enable if you are using a different VR runtime like WiVRn or Monado that SteamVR may interfere with.", "map-editor": "Map Editor", - "map-editor-description": "Start the official Beat Saber map editor instead of the game." + "map-editor-description": "Start the official Beat Saber map editor instead of the game.", + "proton-logs": "Proton Logs", + "proton-logs-description": "Writes the proton logs within the Beat Saber version. To access logs, go to \"Version Settings ⚙️ > Open Folder > Open `Logs` Folder\"." }, "maps": { "search-bar": { diff --git a/src/main/services/bs-launcher/bs-launcher.service.ts b/src/main/services/bs-launcher/bs-launcher.service.ts index 5afe996e..96011b9b 100644 --- a/src/main/services/bs-launcher/bs-launcher.service.ts +++ b/src/main/services/bs-launcher/bs-launcher.service.ts @@ -131,6 +131,7 @@ export class BSLauncherService { if(launchOptions.launchMods?.includes(LaunchMods.DEBUG)){ res.debug = "true"; } if(launchOptions.additionalArgs){ res.additionalArgs = launchOptions.additionalArgs; } if(launchOptions.launchMods?.includes(LaunchMods.SKIP_STEAM)){ res.skipSteam = "true"; } + if(launchOptions.launchMods?.includes(LaunchMods.PROTON_LOGS)){ res.protonLogs = "true"; } return res; } @@ -248,6 +249,7 @@ type ShortcutParams = { debug?: string; additionalArgs?: string[]; skipSteam?: string; + protonLogs?: string; version: string; versionName?: string; versionIno?: string; diff --git a/src/main/services/linux.service.ts b/src/main/services/linux.service.ts index 88b22df3..0dba7c0f 100644 --- a/src/main/services/linux.service.ts +++ b/src/main/services/linux.service.ts @@ -6,6 +6,7 @@ import { StaticConfigurationService } from "./static-configuration.service"; import { CustomError } from "shared/models/exceptions/custom-error.class"; import { BSLaunchError, LaunchOption } from "shared/models/bs-launch"; import { bsmExec } from "main/helpers/os.helpers"; +import { LaunchMods } from "shared/models/bs-launch/launch-option.interface"; export class LinuxService { private static instance: LinuxService; @@ -78,11 +79,15 @@ export class LinuxService { "STEAM_COMPAT_CLIENT_INSTALL_PATH": steamPath, "STEAM_COMPAT_APP_ID": BS_APP_ID, // Run game in steam environment; fixes #585 for unicode song titles - "SteamEnv": "1", - // Uncomment these to create a proton log file in the Beat Saber install directory. - // "PROTON_LOG": 1, - // "PROTON_LOG_DIR": bsFolderPath, + "SteamEnv": 1, }); + + if (launchOptions.launchMods?.includes(LaunchMods.PROTON_LOGS)) { + Object.assign(env, { + "PROTON_LOG": 1, + "PROTON_LOG_DIR": path.join(bsFolderPath, "Logs"), + }); + } } public verifyProtonPath(protonFolder: string = ""): boolean { diff --git a/src/renderer/components/version-viewer/slides/launch/launch-slide.component.tsx b/src/renderer/components/version-viewer/slides/launch/launch-slide.component.tsx index b705b132..05ddbb8b 100644 --- a/src/renderer/components/version-viewer/slides/launch/launch-slide.component.tsx +++ b/src/renderer/components/version-viewer/slides/launch/launch-slide.component.tsx @@ -62,6 +62,14 @@ export function LaunchSlide({ version }: Props) { } }, [activeLaunchMods]); + const toggleActiveLaunchMod = (checked: boolean, launchMod: LaunchMod) => checked + ? setActiveLaunchMods(prev => [...prev, launchMod]) + : setActiveLaunchMods(prev => prev.filter(mod => mod !== launchMod)); + + const togglePinnedLaunchMod = (pinned: boolean, launchMod: LaunchMod) => pinned + ? setPinnedLaunchMods(prev => [...prev, launchMod]) + : setPinnedLaunchMods(prev => prev.filter(mod => mod !== launchMod)); + useEffect(() => { setLaunchModItems(() => [ { @@ -72,8 +80,8 @@ export function LaunchSlide({ version }: Props) { active: activeLaunchMods.includes(LaunchMods.OCULUS), visible: !(version.metadata?.store === BsStore.OCULUS), pinned: pinnedLaunchMods.includes(LaunchMods.OCULUS), - onChange: checked => checked ? setActiveLaunchMods(prev => [...prev, LaunchMods.OCULUS]) : setActiveLaunchMods(prev => prev.filter(mod => mod !== LaunchMods.OCULUS)), - onPinChange: pinned => pinned ? setPinnedLaunchMods(prev => [...prev, LaunchMods.OCULUS]) : setPinnedLaunchMods(prev => prev.filter(mod => mod !== LaunchMods.OCULUS)), + onChange: (checked) => toggleActiveLaunchMod(checked, LaunchMods.OCULUS), + onPinChange: (pinned) => togglePinnedLaunchMod(pinned, LaunchMods.OCULUS), }, { id: LaunchMods.FPFC, @@ -82,8 +90,8 @@ export function LaunchSlide({ version }: Props) { description: t("pages.version-viewer.launch-mods.desktop-description"), active: activeLaunchMods.includes(LaunchMods.FPFC), pinned: pinnedLaunchMods.includes(LaunchMods.FPFC), - onChange: checked => checked ? setActiveLaunchMods(prev => [...prev, LaunchMods.FPFC]) : setActiveLaunchMods(prev => prev.filter(mod => mod !== LaunchMods.FPFC)), - onPinChange: pinned => pinned ? setPinnedLaunchMods(prev => [...prev, LaunchMods.FPFC]) : setPinnedLaunchMods(prev => prev.filter(mod => mod !== LaunchMods.FPFC)), + onChange: (checked) => toggleActiveLaunchMod(checked, LaunchMods.FPFC), + onPinChange: (pinned) => togglePinnedLaunchMod(pinned, LaunchMods.FPFC), }, { id: LaunchMods.DEBUG, @@ -92,8 +100,8 @@ export function LaunchSlide({ version }: Props) { description: t("pages.version-viewer.launch-mods.debug-description"), active: activeLaunchMods.includes(LaunchMods.DEBUG), pinned: pinnedLaunchMods.includes(LaunchMods.DEBUG), - onChange: checked => checked ? setActiveLaunchMods(prev => [...prev, LaunchMods.DEBUG]) : setActiveLaunchMods(prev => prev.filter(mod => mod !== LaunchMods.DEBUG)), - onPinChange: pinned => pinned ? setPinnedLaunchMods(prev => [...prev, LaunchMods.DEBUG]) : setPinnedLaunchMods(prev => prev.filter(mod => mod !== LaunchMods.DEBUG)), + onChange: (checked) => toggleActiveLaunchMod(checked, LaunchMods.DEBUG), + onPinChange: (pinned) => togglePinnedLaunchMod(pinned, LaunchMods.DEBUG), }, { id: LaunchMods.SKIP_STEAM, @@ -101,8 +109,8 @@ export function LaunchSlide({ version }: Props) { description: t("pages.version-viewer.launch-mods.skipsteam-description"), active: activeLaunchMods.includes(LaunchMods.SKIP_STEAM), pinned: pinnedLaunchMods.includes(LaunchMods.SKIP_STEAM), - onChange: checked => checked ? setActiveLaunchMods(prev => [...prev, LaunchMods.SKIP_STEAM]) : setActiveLaunchMods(prev => prev.filter(mod => mod !== LaunchMods.SKIP_STEAM)), - onPinChange: pinned => pinned ? setPinnedLaunchMods(prev => [...prev, LaunchMods.SKIP_STEAM]) : setPinnedLaunchMods(prev => prev.filter(mod => mod !== LaunchMods.SKIP_STEAM)), + onChange: (checked) => toggleActiveLaunchMod(checked, LaunchMods.SKIP_STEAM), + onPinChange: (pinned) => togglePinnedLaunchMod(pinned, LaunchMods.SKIP_STEAM), }, { id: LaunchMods.EDITOR, @@ -112,14 +120,23 @@ export function LaunchSlide({ version }: Props) { active: activeLaunchMods.includes(LaunchMods.EDITOR), pinned: pinnedLaunchMods.includes(LaunchMods.EDITOR), visible: !safeLt(version.BSVersion, "1.23.0"), - onChange: checked => checked ? setActiveLaunchMods(prev => [...prev, LaunchMods.EDITOR]) : setActiveLaunchMods(prev => prev.filter(mod => mod !== LaunchMods.EDITOR)), - onPinChange: pinned => pinned ? setPinnedLaunchMods(prev => [...prev, LaunchMods.EDITOR]) : setPinnedLaunchMods(prev => prev.filter(mod => mod !== LaunchMods.EDITOR)), - - } + onChange: (checked) => toggleActiveLaunchMod(checked, LaunchMods.EDITOR), + onPinChange: (pinned) => togglePinnedLaunchMod(pinned, LaunchMods.EDITOR), + }, + { + id: LaunchMods.PROTON_LOGS, + label: t("pages.version-viewer.launch-mods.proton-logs"), + description: t("pages.version-viewer.launch-mods.proton-logs-description"), + active: activeLaunchMods.includes(LaunchMods.PROTON_LOGS), + pinned: pinnedLaunchMods.includes(LaunchMods.PROTON_LOGS), + visible: window.electron.platform === "linux", + onChange: (checked) => toggleActiveLaunchMod(checked, LaunchMods.PROTON_LOGS), + onPinChange: (pinned) => togglePinnedLaunchMod(pinned, LaunchMods.PROTON_LOGS), + }, ]); }, [activeLaunchMods, pinnedLaunchMods, version]); - const launch = () => { + const launch = async () => { const additionalArgs = additionalArgsString?.split(";").map(arg => arg.trim()).filter(arg => arg.length > 0); const launch$ = bsLauncherService.launch({ @@ -193,5 +210,3 @@ export function LaunchSlide({ version }: Props) { ); } - - diff --git a/src/shared/models/bs-launch/launch-option.interface.ts b/src/shared/models/bs-launch/launch-option.interface.ts index 21455b5a..6199fdde 100644 --- a/src/shared/models/bs-launch/launch-option.interface.ts +++ b/src/shared/models/bs-launch/launch-option.interface.ts @@ -6,6 +6,7 @@ export const LaunchMods = { DEBUG: "debug", SKIP_STEAM: "skip_steam", EDITOR: "editor", + PROTON_LOGS: "proton_logs", } as const; export type LaunchMod = typeof LaunchMods[keyof typeof LaunchMods];