diff --git a/src/utils/options.ts b/src/utils/options.ts index 15200c1..9d6bb20 100644 --- a/src/utils/options.ts +++ b/src/utils/options.ts @@ -1,3 +1,5 @@ +import { Backend } from "./backend"; + export class Options { #options: { [key: string]: string }; #others: string; @@ -5,6 +7,9 @@ export class Options { constructor(input: string) { this.#options = {}; + + // Launch options from Heroic and Emudeck should nerver be changed, + // maybe there are more launchers to be added. this.#isSteam = !(input.includes("heroicgameslauncher") || input.includes("Emulation")); const match = input.match(/(.*)%command%(.*)/); @@ -66,4 +71,15 @@ export class Options { if (this.#others) optionsString += " " + this.#others; return optionsString.trim(); } + + saveOptions(appid: number) { + if (this.#isSteam) { + SteamClient.Apps.SetAppLaunchOptions(appid, this.getOptionsString()); + Backend.sendNotice("Launch Options Saved."); + } + else { + // Never change anything for non-steam games + Backend.sendNotice("Warning: This is not a steam game! settings will not be saved."); + } + }; } diff --git a/src/views/Advanced.tsx b/src/views/Advanced.tsx index 0c7147f..b051dac 100644 --- a/src/views/Advanced.tsx +++ b/src/views/Advanced.tsx @@ -15,7 +15,6 @@ import { FaFolderOpen } from "react-icons/fa"; const Advanced: FC<{ appid: number }> = ({ appid }) => { const [options, setOptions] = useState(new Options("")); - const [isSteam, setIsSteam] = useState(true); const [showPrefix, setShowPrefix] = useState(false); useEffect(() => { @@ -24,7 +23,6 @@ const Advanced: FC<{ appid: number }> = ({ appid }) => { const savedOptions = new Options(optionsString); setShowPrefix(savedOptions.hasField("STEAM_COMPAT_DATA_PATH")); setOptions(savedOptions); - setIsSteam(savedOptions.isSteam()); }); setTimeout(() => { unregister(); @@ -33,7 +31,7 @@ const Advanced: FC<{ appid: number }> = ({ appid }) => { const handleBrowse = async () => { const prefixDir = options.getFieldValue("STEAM_COMPAT_DATA_PATH"); - const defaultDir = prefixDir ? prefixDir : await Backend.getEnv("DECKY_USER_HOME"); + const defaultDir = prefixDir ?? await Backend.getEnv("DECKY_USER_HOME"); const filePickerRes = await Backend.openFilePicker(defaultDir, false); const prefixPath = filePickerRes.path; const newOptions = new Options(options.getOptionsString()); @@ -41,17 +39,6 @@ const Advanced: FC<{ appid: number }> = ({ appid }) => { setOptions(newOptions); }; - const saveOptions = () => { - if (isSteam) { - SteamClient.Apps.SetAppLaunchOptions(appid, options.getOptionsString()); - Backend.sendNotice("Advanced settings saved."); - } - else { - // non steam games is not implemented - Backend.sendNotice("Warning: This is not a steam game! settings will not be saved."); - } - }; - return ( @@ -136,7 +123,7 @@ const Advanced: FC<{ appid: number }> = ({ appid }) => { )} options.saveOptions(appid)} style={{ alignSelf: "center", marginTop: "20px", diff --git a/src/views/Custom/index.tsx b/src/views/Custom/index.tsx index 8fb4cb8..460b153 100644 --- a/src/views/Custom/index.tsx +++ b/src/views/Custom/index.tsx @@ -9,7 +9,6 @@ import { FC, useEffect, useState } from "react"; import { BsPencilFill } from "react-icons/bs"; import { MdAddBox } from "react-icons/md"; -import { Backend } from "../../utils/backend"; import { CustomOption, getCustomOptions } from "../../utils/custom"; import { ModalEdit } from "./ModalEdit"; import { ModalNew } from "./ModalNew"; @@ -39,11 +38,6 @@ const Custom: FC<{ appid: number }> = ({ appid }) => { setCusOptList(updatedOptList); }; - const saveOptions = async () => { - SteamClient.Apps.SetAppLaunchOptions(appid, options.getOptionsString()); - Backend.sendNotice("Custom settings saved."); - }; - return ( <>