summaryrefslogtreecommitdiff
path: root/src/components
diff options
context:
space:
mode:
Diffstat (limited to 'src/components')
-rw-r--r--src/components/ClipboardCommands.tsx10
-rw-r--r--src/components/InstalledGamesSection.tsx566
-rw-r--r--src/components/InstructionCard.tsx6
-rw-r--r--src/components/OptiScalerControls.tsx56
-rw-r--r--src/components/SmartClipboardButton.tsx121
-rw-r--r--src/components/index.ts3
6 files changed, 557 insertions, 205 deletions
diff --git a/src/components/ClipboardCommands.tsx b/src/components/ClipboardCommands.tsx
index 5a6f38f..d822929 100644
--- a/src/components/ClipboardCommands.tsx
+++ b/src/components/ClipboardCommands.tsx
@@ -9,14 +9,14 @@ export function ClipboardCommands({ pathExists }: ClipboardCommandsProps) {
return (
<>
- <SmartClipboardButton
+ <SmartClipboardButton
command="~/fgmod/fgmod %command%"
- buttonText="Copy Patch Command"
+ buttonText="Copy enable launch command"
/>
-
- <SmartClipboardButton
+
+ <SmartClipboardButton
command="~/fgmod/fgmod-uninstaller.sh %command%"
- buttonText="Copy Unpatch Command"
+ buttonText="Copy cleanup launch command"
/>
</>
);
diff --git a/src/components/InstalledGamesSection.tsx b/src/components/InstalledGamesSection.tsx
index 71278d7..5076ffb 100644
--- a/src/components/InstalledGamesSection.tsx
+++ b/src/components/InstalledGamesSection.tsx
@@ -1,124 +1,566 @@
-import { useState, useEffect } from "react";
-import { PanelSection, PanelSectionRow, ButtonItem, DropdownItem, ConfirmModal, showModal } from "@decky/ui";
-import { listInstalledGames, logError } from "../api";
+import { useCallback, useEffect, useMemo, useRef, useState } from "react";
+import {
+ ButtonItem,
+ ConfirmModal,
+ DropdownItem,
+ Field,
+ PanelSection,
+ PanelSectionRow,
+ SliderField,
+ TextField,
+ Router,
+ showModal,
+} from "@decky/ui";
+import {
+ cleanupManagedGame,
+ getGameConfig,
+ listInstalledGames,
+ logError,
+ saveGameConfig,
+} from "../api";
import { safeAsyncOperation } from "../utils";
+import type {
+ ApiResponse,
+ GameConfigResponse,
+ GameConfigSettingSchema,
+ GameInfo,
+} from "../types/index";
import { STYLES } from "../utils/constants";
-import { GameInfo } from "../types/index";
-export function InstalledGamesSection() {
+const DEFAULT_LAUNCH_COMMAND = "~/fgmod/fgmod %COMMAND%";
+const POLL_INTERVAL_MS = 3000;
+const AUTOSAVE_DELAY_MS = 500;
+
+type RunningApp = {
+ appid: string;
+ display_name: string;
+};
+
+interface InstalledGamesSectionProps {
+ isAvailable: boolean;
+}
+
+const formatResult = (result: ApiResponse | null, fallbackSuccess: string) => {
+ if (!result) return "";
+ if (result.status === "success") {
+ return result.message || result.output || fallbackSuccess;
+ }
+ return `Error: ${result.message || result.output || "Operation failed"}`;
+};
+
+const buildSignature = (proxy: string, settings: Record<string, string>) =>
+ JSON.stringify({ proxy, settings });
+
+const valueForSetting = (settings: Record<string, string>, setting: GameConfigSettingSchema) =>
+ settings[setting.id] ?? setting.default ?? "auto";
+
+const defaultNumericValue = (setting: GameConfigSettingSchema) => {
+ const parsedDefault = Number.parseFloat(setting.default ?? "");
+ if (Number.isFinite(parsedDefault)) return parsedDefault;
+ if (typeof setting.rangeMin === "number") return setting.rangeMin;
+ return 0;
+};
+
+export function InstalledGamesSection({ isAvailable }: InstalledGamesSectionProps) {
const [games, setGames] = useState<GameInfo[]>([]);
const [selectedGame, setSelectedGame] = useState<GameInfo | null>(null);
- const [result, setResult] = useState<string>('');
+ const [runningApps, setRunningApps] = useState<RunningApp[]>([]);
+ const [mainRunningApp, setMainRunningApp] = useState<RunningApp | null>(null);
+ const [loadingGames, setLoadingGames] = useState(false);
+ const [enabling, setEnabling] = useState(false);
+ const [disabling, setDisabling] = useState(false);
+ const [configLoading, setConfigLoading] = useState(false);
+ const [configResult, setConfigResult] = useState<string>("");
+ const [config, setConfig] = useState<GameConfigResponse | null>(null);
+ const [settingValues, setSettingValues] = useState<Record<string, string>>({});
+ const [selectedProxy, setSelectedProxy] = useState<string>("winmm");
+ const [selectedSectionId, setSelectedSectionId] = useState<string>("");
+ const [autoSaving, setAutoSaving] = useState(false);
+
+ const skipAutosaveRef = useRef(true);
+ const lastLoadedSignatureRef = useRef<string>("");
+
+ const selectedAppId = selectedGame ? String(selectedGame.appid) : null;
+ const selectedIsRunning = useMemo(
+ () => Boolean(selectedAppId && runningApps.some((app) => String(app.appid) === selectedAppId)),
+ [runningApps, selectedAppId]
+ );
+
+ const sectionOptions = useMemo(
+ () =>
+ (config?.schema || []).map((section) => ({
+ data: section.id,
+ label: `${section.label} (${section.settings.length})`,
+ })),
+ [config?.schema]
+ );
+
+ const activeSection = useMemo(
+ () => (config?.schema || []).find((section) => section.id === selectedSectionId) || config?.schema?.[0] || null,
+ [config?.schema, selectedSectionId]
+ );
+
+ const refreshRunningApps = useCallback(() => {
+ try {
+ const nextRunningApps = ((Router?.RunningApps || []) as RunningApp[])
+ .filter((app) => app?.appid && app?.display_name)
+ .map((app) => ({ appid: String(app.appid), display_name: app.display_name }));
+
+ const nextMainRunningApp = Router?.MainRunningApp
+ ? {
+ appid: String(Router.MainRunningApp.appid),
+ display_name: Router.MainRunningApp.display_name,
+ }
+ : nextRunningApps[0] || null;
+
+ setRunningApps(nextRunningApps);
+ setMainRunningApp(nextMainRunningApp);
+
+ if (!selectedGame && nextMainRunningApp) {
+ setSelectedGame({
+ appid: nextMainRunningApp.appid,
+ name: nextMainRunningApp.display_name,
+ });
+ }
+ } catch (error) {
+ console.error("InstalledGamesSection.refreshRunningApps", error);
+ }
+ }, [selectedGame]);
+
+ const loadConfig = useCallback(
+ async (appid: string) => {
+ setConfigLoading(true);
+ const response = await safeAsyncOperation(() => getGameConfig(appid), `InstalledGamesSection.loadConfig.${appid}`);
+ if (!response) {
+ setConfigLoading(false);
+ return;
+ }
+
+ if (response.status === "success") {
+ skipAutosaveRef.current = true;
+ setConfig(response);
+ setSettingValues(response.settings || {});
+ setSelectedProxy(response.proxy || "winmm");
+ setSelectedSectionId((current) =>
+ current && response.schema?.some((section) => section.id === current)
+ ? current
+ : response.schema?.[0]?.id || ""
+ );
+ setConfigResult("");
+ lastLoadedSignatureRef.current = buildSignature(response.proxy || "winmm", response.settings || {});
+ } else {
+ setConfig(null);
+ setSettingValues({});
+ setSelectedSectionId("");
+ setConfigResult(`Error: ${response.message || response.output || "Failed to load game config"}`);
+ }
+
+ setConfigLoading(false);
+ },
+ []
+ );
useEffect(() => {
+ if (!isAvailable) return;
+
+ let cancelled = false;
+
const fetchGames = async () => {
- const response = await safeAsyncOperation(
- async () => await listInstalledGames(),
- 'fetchGames'
- );
-
- if (response?.status === "success") {
+ setLoadingGames(true);
+ const response = await safeAsyncOperation(async () => await listInstalledGames(), "InstalledGamesSection.fetchGames");
+ if (cancelled || !response) {
+ setLoadingGames(false);
+ return;
+ }
+
+ if (response.status === "success") {
const sortedGames = [...response.games]
- .map(game => ({
+ .map((game) => ({
...game,
- appid: parseInt(game.appid, 10),
+ appid: parseInt(String(game.appid), 10),
}))
.sort((a, b) => a.name.toLowerCase().localeCompare(b.name.toLowerCase()));
setGames(sortedGames);
- } else if (response) {
- logError('fetchGames: ' + JSON.stringify(response));
- console.error('fetchGames: ' + JSON.stringify(response));
+ } else {
+ logError(`InstalledGamesSection.fetchGames: ${JSON.stringify(response)}`);
}
+
+ setLoadingGames(false);
};
-
+
fetchGames();
- }, []);
+ refreshRunningApps();
+ const interval = setInterval(refreshRunningApps, POLL_INTERVAL_MS);
- const handlePatchClick = async () => {
+ return () => {
+ cancelled = true;
+ clearInterval(interval);
+ };
+ }, [isAvailable, refreshRunningApps]);
+
+ useEffect(() => {
+ if (!isAvailable || !selectedAppId) return;
+ void loadConfig(selectedAppId);
+ }, [isAvailable, loadConfig, selectedAppId]);
+
+ useEffect(() => {
+ if (!selectedAppId || !config?.schema?.length) return;
+
+ const currentSignature = buildSignature(selectedProxy, settingValues);
+ if (skipAutosaveRef.current) {
+ skipAutosaveRef.current = false;
+ lastLoadedSignatureRef.current = currentSignature;
+ return;
+ }
+
+ if (currentSignature === lastLoadedSignatureRef.current) {
+ return;
+ }
+
+ const timer = setTimeout(async () => {
+ setAutoSaving(true);
+ try {
+ const response = await saveGameConfig(selectedAppId, settingValues, selectedProxy, selectedIsRunning, null);
+ if (response.status === "success") {
+ const updated = response as GameConfigResponse;
+ skipAutosaveRef.current = true;
+ setConfig(updated);
+ setSettingValues(updated.settings || settingValues);
+ setSelectedProxy(updated.proxy || selectedProxy);
+ setSelectedSectionId((current) =>
+ current && updated.schema?.some((section) => section.id === current)
+ ? current
+ : updated.schema?.[0]?.id || ""
+ );
+ lastLoadedSignatureRef.current = buildSignature(updated.proxy || selectedProxy, updated.settings || settingValues);
+ setConfigResult(
+ response.message ||
+ (selectedIsRunning
+ ? "Applied config immediately to the running game."
+ : "Saved config for the selected game.")
+ );
+ } else {
+ setConfigResult(formatResult(response, "Failed to save config."));
+ }
+ } catch (error) {
+ setConfigResult(error instanceof Error ? `Error: ${error.message}` : "Error saving config");
+ } finally {
+ setAutoSaving(false);
+ }
+ }, AUTOSAVE_DELAY_MS);
+
+ return () => clearTimeout(timer);
+ }, [config?.schema, selectedAppId, selectedIsRunning, selectedProxy, settingValues]);
+
+ const handleEnable = async () => {
if (!selectedGame) return;
- // Show confirmation modal
showModal(
- <ConfirmModal
- strTitle={`Enable Frame Generation for ${selectedGame.name}?`}
+ <ConfirmModal
+ strTitle={`Enable prefix-managed OptiScaler for ${selectedGame.name}?`}
strDescription={
- "⚠️ Important: This plugin does not automatically unpatch games when uninstalled. If you uninstall this plugin or experience game issues, use the 'Disable Frame Generation' option or verify game file integrity through Steam."
+ "This only changes the Steam launch option for the selected game. OptiScaler itself is staged into compatdata/pfx/system32 at launch time and does not write into the game install directory."
}
- strOKButtonText="Enable Frame Generation"
+ strOKButtonText="Enable"
strCancelButtonText="Cancel"
onOK={async () => {
+ setEnabling(true);
try {
- await SteamClient.Apps.SetAppLaunchOptions(selectedGame.appid, '~/fgmod/fgmod %COMMAND%');
- setResult(`✓ Frame generation enabled for ${selectedGame.name}. Launch the game, enable DLSS in graphics settings, then press Insert to access OptiScaler options.`);
+ await SteamClient.Apps.SetAppLaunchOptions(selectedGame.appid, DEFAULT_LAUNCH_COMMAND);
+ setConfigResult(`✓ Enabled prefix-managed OptiScaler for ${selectedGame.name}. Launch the game, enable DLSS if needed, then press Insert for the OptiScaler menu.`);
} catch (error) {
- logError('handlePatchClick: ' + String(error));
- setResult(error instanceof Error ? `Error: ${error.message}` : 'Error enabling frame generation');
+ logError(`InstalledGamesSection.handleEnable: ${String(error)}`);
+ setConfigResult(error instanceof Error ? `Error: ${error.message}` : "Error enabling prefix-managed OptiScaler");
+ } finally {
+ setEnabling(false);
}
}}
/>
);
};
- const handleUnpatchClick = async () => {
+ const handleDisable = async () => {
if (!selectedGame) return;
+ setDisabling(true);
try {
- await SteamClient.Apps.SetAppLaunchOptions(selectedGame.appid, '~/fgmod/fgmod-uninstaller.sh %COMMAND%');
- setResult(`✓ Frame generation will be disabled on next launch of ${selectedGame.name}.`);
+ const cleanupResult = await cleanupManagedGame(String(selectedGame.appid));
+ if (cleanupResult?.status !== "success") {
+ setConfigResult(`Error: ${cleanupResult?.message || cleanupResult?.output || "Failed to clean managed compatdata prefix"}`);
+ return;
+ }
+
+ await SteamClient.Apps.SetAppLaunchOptions(selectedGame.appid, "");
+ setConfig(null);
+ setSettingValues({});
+ setSelectedProxy("winmm");
+ setSelectedSectionId("");
+ setConfigResult(`✓ Cleared launch options and cleaned the managed compatdata prefix for ${selectedGame.name}.`);
} catch (error) {
- logError('handleUnpatchClick: ' + String(error));
- setResult(error instanceof Error ? `Error: ${error.message}` : 'Error disabling frame generation');
+ logError(`InstalledGamesSection.handleDisable: ${String(error)}`);
+ setConfigResult(error instanceof Error ? `Error: ${error.message}` : "Error disabling prefix-managed OptiScaler");
+ } finally {
+ setDisabling(false);
+ }
+ };
+
+ const updateSettingValue = (settingId: string, value: string) => {
+ setSettingValues((prev) => ({ ...prev, [settingId]: value }));
+ };
+
+ const renderSettingControl = (setting: GameConfigSettingSchema) => {
+ const currentValue = valueForSetting(settingValues, setting);
+
+ if (setting.control === "dropdown") {
+ const options = [...setting.options];
+ if (!options.some((option) => option.value === currentValue)) {
+ options.push({ value: currentValue, label: currentValue });
+ }
+
+ return (
+ <PanelSectionRow key={setting.id}>
+ <DropdownItem
+ label={setting.label}
+ description={setting.description}
+ rgOptions={options.map((option) => ({ data: option.value, label: option.label }))}
+ selectedOption={currentValue}
+ onChange={(option) => updateSettingValue(setting.id, String(option.data))}
+ menuLabel={setting.label}
+ strDefaultLabel={setting.label}
+ />
+ </PanelSectionRow>
+ );
}
+
+ if (setting.control === "range") {
+ const isAuto = currentValue === "auto";
+ const numericValue = Number.parseFloat(currentValue);
+ const effectiveValue = Number.isFinite(numericValue) ? numericValue : defaultNumericValue(setting);
+
+ return (
+ <div key={setting.id}>
+ <PanelSectionRow>
+ <DropdownItem
+ label={setting.label}
+ description={setting.description}
+ rgOptions={[
+ { data: "auto", label: "auto" },
+ { data: "custom", label: "custom" },
+ ]}
+ selectedOption={isAuto ? "auto" : "custom"}
+ onChange={(option) => {
+ if (String(option.data) === "auto") {
+ updateSettingValue(setting.id, "auto");
+ } else if (currentValue === "auto") {
+ const baseValue = defaultNumericValue(setting);
+ updateSettingValue(
+ setting.id,
+ setting.numericType === "float" ? baseValue.toFixed(2) : String(Math.round(baseValue))
+ );
+ }
+ }}
+ menuLabel={`${setting.label} mode`}
+ strDefaultLabel={`${setting.label} mode`}
+ />
+ </PanelSectionRow>
+ {!isAuto ? (
+ <PanelSectionRow>
+ <SliderField
+ label={`${setting.label} value`}
+ value={effectiveValue}
+ min={setting.rangeMin ?? 0}
+ max={setting.rangeMax ?? 1}
+ step={setting.step ?? 1}
+ showValue
+ editableValue
+ onChange={(value) =>
+ updateSettingValue(
+ setting.id,
+ setting.numericType === "float" ? value.toFixed(2) : String(Math.round(value))
+ )
+ }
+ />
+ </PanelSectionRow>
+ ) : null}
+ </div>
+ );
+ }
+
+ return (
+ <PanelSectionRow key={setting.id}>
+ <TextField
+ label={setting.label}
+ description={setting.description}
+ value={currentValue}
+ onChange={(event) => updateSettingValue(setting.id, event.currentTarget.value)}
+ />
+ </PanelSectionRow>
+ );
};
+ if (!isAvailable) return null;
+
return (
- <PanelSection title="Select a Game to Patch:">
+ <PanelSection title="Steam game integration + live config">
+ <PanelSectionRow>
+ <Field
+ label="Running now"
+ description={
+ mainRunningApp
+ ? `Main running game: ${mainRunningApp.display_name}`
+ : "No running Steam game detected right now."
+ }
+ >
+ <div style={{ ...STYLES.preWrap, fontSize: "12px" }}>
+ {runningApps.length > 0 ? runningApps.map((app) => app.display_name).join("\n") : "Idle"}
+ </div>
+ </Field>
+ </PanelSectionRow>
+
+ {mainRunningApp ? (
+ <PanelSectionRow>
+ <ButtonItem
+ layout="below"
+ onClick={() =>
+ setSelectedGame({
+ appid: mainRunningApp.appid,
+ name: mainRunningApp.display_name,
+ })
+ }
+ >
+ Use current running game
+ </ButtonItem>
+ </PanelSectionRow>
+ ) : null}
+
<PanelSectionRow>
<DropdownItem
- rgOptions={games.map(game => ({
- data: game.appid,
- label: game.name
+ label="Target game"
+ rgOptions={games.map((game) => ({
+ data: String(game.appid),
+ label: game.name,
}))}
- selectedOption={selectedGame?.appid}
+ selectedOption={selectedAppId}
onChange={(option) => {
- const game = games.find(g => g.appid === option.data);
+ const game = games.find((entry) => String(entry.appid) === String(option.data));
setSelectedGame(game || null);
- setResult('');
+ setConfigResult("");
}}
- strDefaultLabel="Choose a game"
- menuLabel="Installed Games"
+ strDefaultLabel={loadingGames ? "Loading installed games..." : "Choose a game"}
+ menuLabel="Installed Steam games"
+ disabled={loadingGames || games.length === 0}
/>
</PanelSectionRow>
- {result ? (
+ <PanelSectionRow>
+ <div style={STYLES.instructionCard}>
+ Enable writes the wrapper launch option automatically. Disable clears launch options and removes staged files from the selected game's compatdata prefix. All config controls below now autosave immediately, and if the selected game is running they also update the live prefix copy automatically.
+ </div>
+ </PanelSectionRow>
+
+ {selectedGame ? (
+ <>
+ <PanelSectionRow>
+ <Field
+ label="Selected game"
+ description={selectedIsRunning ? "Detected as currently running." : "Not currently running."}
+ >
+ {selectedGame.name}
+ </Field>
+ </PanelSectionRow>
+
+ <PanelSectionRow>
+ <ButtonItem layout="below" onClick={handleEnable} disabled={enabling || disabling}>
+ {enabling ? "Enabling..." : "Enable for selected game"}
+ </ButtonItem>
+ </PanelSectionRow>
+
+ <PanelSectionRow>
+ <ButtonItem layout="below" onClick={handleDisable} disabled={enabling || disabling}>
+ {disabling ? "Cleaning..." : "Disable and clean selected game"}
+ </ButtonItem>
+ </PanelSectionRow>
+
+ <PanelSectionRow>
+ <ButtonItem layout="below" onClick={() => loadConfig(String(selectedGame.appid))} disabled={configLoading}>
+ {configLoading ? "Loading config..." : "Reload selected game config"}
+ </ButtonItem>
+ </PanelSectionRow>
+ </>
+ ) : null}
+
+ {configResult || autoSaving ? (
<PanelSectionRow>
- <div style={{
- ...STYLES.preWrap,
- ...(result.includes('Error') ? STYLES.statusNotInstalled : STYLES.statusInstalled)
- }}>
- {result.includes('Error') ? '❌' : '✅'} {result}
+ <div
+ style={{
+ ...STYLES.preWrap,
+ ...((configResult.startsWith("Error") ? STYLES.statusNotInstalled : STYLES.statusInstalled) as object),
+ }}
+ >
+ {autoSaving ? "💾 Autosaving configuration..." : null}
+ {autoSaving && configResult ? "\n" : null}
+ {configResult ? `${configResult.startsWith("Error") ? "❌" : "✅"} ${configResult}` : null}
</div>
</PanelSectionRow>
) : null}
-
- {selectedGame ? (
+
+ {selectedGame && config ? (
<>
<PanelSectionRow>
- <ButtonItem
- layout="below"
- onClick={handlePatchClick}
+ <Field
+ label="Managed paths"
+ description={config.live_available ? "Live prefix copy is present." : "Live prefix copy is not staged right now."}
>
- Enable Frame Generation
- </ButtonItem>
+ <div style={{ ...STYLES.preWrap, fontSize: "11px", wordBreak: "break-word" }}>
+ {config.paths?.managed_ini ? `Managed INI: ${config.paths.managed_ini}\n` : ""}
+ {config.paths?.live_ini ? `Live INI: ${config.paths.live_ini}` : ""}
+ </div>
+ </Field>
</PanelSectionRow>
+
<PanelSectionRow>
- <ButtonItem
- layout="below"
- onClick={handleUnpatchClick}
- >
- Disable Frame Generation
- </ButtonItem>
+ <DropdownItem
+ label="Proxy DLL"
+ description="Persisted per game and used by the wrapper on next launch. Changes autosave immediately."
+ rgOptions={["winmm", "dxgi", "version", "dbghelp", "winhttp", "wininet", "d3d12"].map((proxy) => ({
+ data: proxy,
+ label: proxy,
+ }))}
+ selectedOption={selectedProxy}
+ onChange={(option) => setSelectedProxy(String(option.data))}
+ menuLabel="Proxy DLL"
+ strDefaultLabel="Proxy DLL"
+ />
</PanelSectionRow>
+
+ <PanelSectionRow>
+ <DropdownItem
+ label="Config section"
+ description="Browse and edit every setting parsed from the bundled OptiScaler.ini template."
+ rgOptions={sectionOptions}
+ selectedOption={selectedSectionId}
+ onChange={(option) => setSelectedSectionId(String(option.data))}
+ menuLabel="Config section"
+ strDefaultLabel="Config section"
+ disabled={sectionOptions.length === 0}
+ />
+ </PanelSectionRow>
+
+ {activeSection ? (
+ <>
+ <PanelSectionRow>
+ <Field
+ label={activeSection.label}
+ description={`Showing ${activeSection.settings.length} setting${activeSection.settings.length === 1 ? "" : "s"} in this section.`}
+ >
+ {selectedIsRunning
+ ? "Changes in this section will be applied to the managed config and the live prefix copy."
+ : "Changes in this section will be saved for the next launch unless the game is already running."}
+ </Field>
+ </PanelSectionRow>
+ {activeSection.settings.map(renderSettingControl)}
+ </>
+ ) : null}
</>
) : null}
</PanelSection>
diff --git a/src/components/InstructionCard.tsx b/src/components/InstructionCard.tsx
index fdf6755..392c782 100644
--- a/src/components/InstructionCard.tsx
+++ b/src/components/InstructionCard.tsx
@@ -11,12 +11,10 @@ export function InstructionCard({ pathExists }: InstructionCardProps) {
return (
<PanelSectionRow>
<div style={STYLES.instructionCard}>
- <div style={{ fontWeight: 'bold', marginBottom: '8px', color: 'var(--decky-accent-text)' }}>
+ <div style={{ fontWeight: "bold", marginBottom: "8px", color: "var(--decky-accent-text)" }}>
{MESSAGES.instructionTitle}
</div>
- <div style={{ whiteSpace: 'pre-line' }}>
- {MESSAGES.instructionText}
- </div>
+ <div style={{ whiteSpace: "pre-line" }}>{MESSAGES.instructionText}</div>
</div>
</PanelSectionRow>
);
diff --git a/src/components/OptiScalerControls.tsx b/src/components/OptiScalerControls.tsx
index 468683c..4a33b58 100644
--- a/src/components/OptiScalerControls.tsx
+++ b/src/components/OptiScalerControls.tsx
@@ -1,4 +1,4 @@
-import { useState, useEffect } from "react";
+import { useEffect, useState } from "react";
import { PanelSection } from "@decky/ui";
import { runInstallFGMod, runUninstallFGMod } from "../api";
import { OperationResult } from "./ResultDisplay";
@@ -10,7 +10,7 @@ import { ClipboardCommands } from "./ClipboardCommands";
import { InstructionCard } from "./InstructionCard";
import { OptiScalerWiki } from "./OptiScalerWiki";
import { UninstallButton } from "./UninstallButton";
-import { ManualPatchControls } from "./CustomPathOverride";
+import { InstalledGamesSection } from "./InstalledGamesSection";
interface OptiScalerControlsProps {
pathExists: boolean | null;
@@ -22,19 +22,15 @@ export function OptiScalerControls({ pathExists, setPathExists }: OptiScalerCont
const [uninstalling, setUninstalling] = useState(false);
const [installResult, setInstallResult] = useState<OperationResult | null>(null);
const [uninstallResult, setUninstallResult] = useState<OperationResult | null>(null);
- const [manualModeEnabled, setManualModeEnabled] = useState(false);
+
useEffect(() => {
- if (installResult) {
- return createAutoCleanupTimer(() => setInstallResult(null), TIMEOUTS.resultDisplay);
- }
- return () => {}; // Ensure a cleanup function is always returned
+ if (!installResult) return () => {};
+ return createAutoCleanupTimer(() => setInstallResult(null), TIMEOUTS.resultDisplay);
}, [installResult]);
useEffect(() => {
- if (uninstallResult) {
- return createAutoCleanupTimer(() => setUninstallResult(null), TIMEOUTS.resultDisplay);
- }
- return () => {}; // Ensure a cleanup function is always returned
+ if (!uninstallResult) return () => {};
+ return createAutoCleanupTimer(() => setUninstallResult(null), TIMEOUTS.resultDisplay);
}, [uninstallResult]);
const handleInstallClick = async () => {
@@ -45,8 +41,8 @@ export function OptiScalerControls({ pathExists, setPathExists }: OptiScalerCont
if (result.status === "success") {
setPathExists(true);
}
- } catch (e) {
- console.error(e);
+ } catch (error) {
+ console.error(error);
} finally {
setInstalling(false);
}
@@ -60,8 +56,8 @@ export function OptiScalerControls({ pathExists, setPathExists }: OptiScalerCont
if (result.status === "success") {
setPathExists(false);
}
- } catch (e) {
- console.error(e);
+ } catch (error) {
+ console.error(error);
} finally {
setUninstalling(false);
}
@@ -69,33 +65,13 @@ export function OptiScalerControls({ pathExists, setPathExists }: OptiScalerCont
return (
<PanelSection>
- <InstallationStatus
- pathExists={pathExists}
- installing={installing}
- onInstallClick={handleInstallClick}
- />
-
+ <InstallationStatus pathExists={pathExists} installing={installing} onInstallClick={handleInstallClick} />
<OptiScalerHeader pathExists={pathExists} />
-
- <ManualPatchControls
- isAvailable={pathExists === true}
- onManualModeChange={setManualModeEnabled}
- />
-
- {!manualModeEnabled && (
- <>
- <ClipboardCommands pathExists={pathExists} />
-
- <InstructionCard pathExists={pathExists} />
- </>
- )}
+ <InstalledGamesSection isAvailable={pathExists === true} />
+ <ClipboardCommands pathExists={pathExists} />
+ <InstructionCard pathExists={pathExists} />
<OptiScalerWiki pathExists={pathExists} />
-
- <UninstallButton
- pathExists={pathExists}
- uninstalling={uninstalling}
- onUninstallClick={handleUninstallClick}
- />
+ <UninstallButton pathExists={pathExists} uninstalling={uninstalling} onUninstallClick={handleUninstallClick} />
</PanelSection>
);
}
diff --git a/src/components/SmartClipboardButton.tsx b/src/components/SmartClipboardButton.tsx
index d88a58a..78f76b5 100644
--- a/src/components/SmartClipboardButton.tsx
+++ b/src/components/SmartClipboardButton.tsx
@@ -1,119 +1,68 @@
-import { useState, useEffect } from "react";
-import { PanelSectionRow, ButtonItem, ConfirmModal, showModal } from "@decky/ui";
-import { FaClipboard, FaCheck } from "react-icons/fa";
+import { useEffect, useState } from "react";
+import { ButtonItem, PanelSectionRow } from "@decky/ui";
import { toaster } from "@decky/api";
+import { FaCheck, FaClipboard } from "react-icons/fa";
interface SmartClipboardButtonProps {
command?: string;
buttonText?: string;
}
-export function SmartClipboardButton({
+export function SmartClipboardButton({
command = "~/fgmod/fgmod %command%",
- buttonText = "Copy Launch Command"
+ buttonText = "Copy Launch Command",
}: SmartClipboardButtonProps) {
const [isLoading, setIsLoading] = useState(false);
const [showSuccess, setShowSuccess] = useState(false);
- // Reset success state after 3 seconds
useEffect(() => {
- if (showSuccess) {
- const timer = setTimeout(() => {
- setShowSuccess(false);
- }, 3000);
- return () => clearTimeout(timer);
- }
- return undefined;
+ if (!showSuccess) return undefined;
+ const timer = setTimeout(() => setShowSuccess(false), 3000);
+ return () => clearTimeout(timer);
}, [showSuccess]);
- const copyToClipboard = async () => {
- if (isLoading || showSuccess) return;
-
- const isPatchCommand = command.includes("fgmod %command%") && !command.includes("uninstaller");
-
- if (isPatchCommand) {
- showModal(
- <ConfirmModal
- strTitle={`Patch Game with OptiScaler?`}
- strDescription={
- "WARNING: Decky Framegen does not unpatch games when uninstalled. Be sure to unpatch the game or run the OptiScaler uninstall script inside the game files if you choose to uninstall the plugin or the game has issues."
- }
- strOKButtonText="Copy Patch Command"
- strCancelButtonText="Cancel"
- onOK={async () => {
- await performCopy();
- }}
- />
- );
- return;
- }
-
- // For non-patch commands, copy directly
- await performCopy();
- };
-
const performCopy = async () => {
if (isLoading || showSuccess) return;
-
+
setIsLoading(true);
try {
- const text = command;
-
- // Use the proven input simulation method
- const tempInput = document.createElement('input');
- tempInput.value = text;
- tempInput.style.position = 'absolute';
- tempInput.style.left = '-9999px';
+ const tempInput = document.createElement("input");
+ tempInput.value = command;
+ tempInput.style.position = "absolute";
+ tempInput.style.left = "-9999px";
document.body.appendChild(tempInput);
-
- // Focus and select the text
tempInput.focus();
tempInput.select();
-
- // Try copying using execCommand first (most reliable in gaming mode)
+
let copySuccess = false;
try {
- if (document.execCommand('copy')) {
+ if (document.execCommand("copy")) {
copySuccess = true;
}
- } catch (e) {
- // If execCommand fails, try navigator.clipboard as fallback
+ } catch (execError) {
try {
- await navigator.clipboard.writeText(text);
+ await navigator.clipboard.writeText(command);
copySuccess = true;
} catch (clipboardError) {
- console.error('Both copy methods failed:', e, clipboardError);
+ console.error("Clipboard copy failed", execError, clipboardError);
}
}
-
- // Clean up
+
document.body.removeChild(tempInput);
-
- if (copySuccess) {
- // Show success feedback in the button instead of toast
- setShowSuccess(true);
- // Verify the copy worked by reading back
- try {
- const readBack = await navigator.clipboard.readText();
- if (readBack !== text) {
- // Copy worked but verification failed - still show success
- console.log('Copy verification failed but copy likely worked');
- }
- } catch (e) {
- // Verification failed but copy likely worked
- console.log('Copy verification unavailable but copy likely worked');
- }
- } else {
+
+ if (!copySuccess) {
toaster.toast({
title: "Copy Failed",
- body: "Unable to copy to clipboard"
+ body: "Unable to copy to clipboard",
});
+ return;
}
+ setShowSuccess(true);
} catch (error) {
toaster.toast({
title: "Copy Failed",
- body: `Error: ${String(error)}`
+ body: `Error: ${String(error)}`,
});
} finally {
setIsLoading(false);
@@ -122,28 +71,16 @@ export function SmartClipboardButton({
return (
<PanelSectionRow>
- <ButtonItem
- layout="below"
- onClick={copyToClipboard}
- disabled={isLoading || showSuccess}
- >
+ <ButtonItem layout="below" onClick={performCopy} disabled={isLoading || showSuccess}>
<div style={{ display: "flex", alignItems: "center", gap: "8px" }}>
{showSuccess ? (
- <FaCheck style={{
- color: "#4CAF50" // Green color for success
- }} />
+ <FaCheck style={{ color: "#4CAF50" }} />
) : isLoading ? (
- <FaClipboard style={{
- animation: "pulse 1s ease-in-out infinite",
- opacity: 0.7
- }} />
+ <FaClipboard style={{ animation: "pulse 1s ease-in-out infinite", opacity: 0.7 }} />
) : (
<FaClipboard />
)}
- <div style={{
- color: showSuccess ? "#4CAF50" : "inherit",
- fontWeight: showSuccess ? "bold" : "normal"
- }}>
+ <div style={{ color: showSuccess ? "#4CAF50" : "inherit", fontWeight: showSuccess ? "bold" : "normal" }}>
{showSuccess ? "Copied to clipboard" : isLoading ? "Copying..." : buttonText}
</div>
</div>
diff --git a/src/components/index.ts b/src/components/index.ts
index cd599ba..18ca2b4 100644
--- a/src/components/index.ts
+++ b/src/components/index.ts
@@ -1,4 +1,3 @@
-// Component exports for cleaner imports
export { OptiScalerControls } from './OptiScalerControls';
export { InstallationStatus } from './InstallationStatus';
export { OptiScalerHeader } from './OptiScalerHeader';
@@ -8,4 +7,4 @@ export { OptiScalerWiki } from './OptiScalerWiki';
export { UninstallButton } from './UninstallButton';
export { SmartClipboardButton } from './SmartClipboardButton';
export { ResultDisplay } from './ResultDisplay';
-export { ManualPatchControls } from './CustomPathOverride';
+export { InstalledGamesSection } from './InstalledGamesSection';