1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
|
import { ButtonItem, ConfirmModal, DialogButton, Focusable, PanelSection, PanelSectionRow, ToggleField, gamepadDialogClasses, showModal } from "@decky/ui";
import { useCallback, useEffect, useRef, useState } from "react";
import { FaArrowLeft } from "react-icons/fa";
import { ConfigurationData } from "../config/configSchema";
import { GameTarget } from "../hooks/useGameConfiguration";
import { GameConfigurationControls } from "./GameConfigurationControls";
import { GameConfigurationSelector } from "./GameConfigurationSelector";
import { ProfileDetails } from "./ProfileDetails";
interface ConfigurationTabProps {
config: ConfigurationData;
targets: GameTarget[];
runningGame: GameTarget | null;
showDebugTab: boolean;
onShowDebugTabChange: (value: boolean) => void;
onSelect: (appid: string) => void;
onConfigChange: (fieldName: keyof ConfigurationData, value: boolean | number | string | string[]) => Promise<void>;
onEnable: (appid: string) => Promise<boolean>;
onEnableAll: () => Promise<void>;
onRepair: (appid: string) => Promise<boolean>;
onReset: () => Promise<void>;
onResetAll: () => Promise<void>;
}
export function ConfigurationTab({
config,
targets,
runningGame,
showDebugTab,
onShowDebugTabChange,
onSelect,
onConfigChange,
onEnable,
onEnableAll,
onRepair,
onReset,
onResetAll,
}: ConfigurationTabProps) {
const [detailAppId, setDetailAppId] = useState<string | null>(null);
const [focusFpsMultiplier, setFocusFpsMultiplier] = useState(false);
const [focusDetailAction, setFocusDetailAction] = useState<"enable" | "fps" | null>(null);
const [focusConfiguredToggle, setFocusConfiguredToggle] = useState(false);
const enableRef = useRef<HTMLDivElement>(null);
const closeDetails = useCallback(() => {
setFocusFpsMultiplier(false);
setFocusDetailAction(null);
setDetailAppId(null);
}, []);
const clearFpsFocusRequest = useCallback(() => setFocusFpsMultiplier(false), []);
const clearConfiguredToggleFocusRequest = useCallback(() => setFocusConfiguredToggle(false), []);
useEffect(() => {
if (!focusDetailAction) return;
if (focusDetailAction === "fps") {
setFocusFpsMultiplier(true);
setFocusDetailAction(null);
return;
}
const frame = requestAnimationFrame(() => {
enableRef.current?.querySelector<HTMLElement>('[role="button"]')?.focus();
setFocusDetailAction(null);
});
return () => cancelAnimationFrame(frame);
}, [focusDetailAction]);
const selectedTarget = detailAppId ? targets.find((target) => target.appid === detailAppId) : null;
if (detailAppId === null) {
return (
<>
<PanelSection title="Games">
<GameConfigurationSelector
targets={targets}
runningGame={runningGame}
onSelect={(appid) => {
setFocusConfiguredToggle(false);
setFocusDetailAction(targets.find((target) => target.appid === appid)?.configured ? "fps" : "enable");
onSelect(appid);
setDetailAppId(appid);
}}
onEnableAll={onEnableAll}
onResetAll={onResetAll}
focusConfiguredToggle={focusConfiguredToggle}
onConfiguredToggleFocused={clearConfiguredToggleFocusRequest}
/>
</PanelSection>
<PanelSection title="Settings">
<PanelSectionRow>
<ToggleField
label="Show debug tab"
description="Show the raw configuration and generated files tab for troubleshooting."
checked={showDebugTab}
onChange={onShowDebugTabChange}
/>
</PanelSectionRow>
</PanelSection>
</>
);
}
const profileLabel = selectedTarget?.name || "Game profile";
const profileTransport = selectedTarget
? selectedTarget.directFlatpak
? "Non-Steam · Direct Flatpak"
: selectedTarget.nonSteam ? "Non-Steam" : "Steam"
: "Game";
const profileDescription = selectedTarget
? `${profileTransport} · App ID ${selectedTarget.appid} · ${selectedTarget.configured ? "LSFG-VK Enabled" : "LSFG-VK not enabled"}`
: "Game is no longer available";
const enableProfile = async (appid: string, quitRunningGame = false) => {
if (!(await onEnable(appid))) return;
if (quitRunningGame) SteamClient.Apps.TerminateApp(appid, false);
setFocusFpsMultiplier(true);
};
const handleProfileAction = async () => {
if (selectedTarget?.configured) {
await onReset();
setFocusConfiguredToggle(true);
closeDetails();
} else if (detailAppId) {
const isRunningUnconfigured = runningGame?.appid === detailAppId
&& runningGame.nonSteam === false
&& selectedTarget?.nonSteam === false
&& !runningGame.configured;
if (isRunningUnconfigured) {
showModal(
<ConfirmModal
strTitle="Game is running"
strDescription="Quit the game now so LSFG-VK is used on its next launch?"
strOKButtonText="Quit and enable"
strCancelButtonText="Enable without quitting"
onOK={() => void enableProfile(detailAppId, true)}
onCancel={() => void enableProfile(detailAppId)}
/>,
);
} else {
await enableProfile(detailAppId);
}
}
};
return (
<Focusable onCancelButton={closeDetails}>
<PanelSection>
<PanelSectionRow>
<div style={{ display: "flex", alignItems: "center", width: "100%" }}>
<Focusable noFocusRing style={{ flex: "none" }}>
<DialogButton
aria-label="Back to games"
onClick={closeDetails}
style={{
width: "48px",
minWidth: "48px",
height: "24px",
minHeight: "24px",
padding: 0,
display: "flex",
alignItems: "center",
justifyContent: "center",
}}
>
<FaArrowLeft />
</DialogButton>
</Focusable>
<div
className={gamepadDialogClasses.FieldLabel}
style={{ flex: 1, minWidth: 0, marginLeft: "8px", overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" }}
>
{profileLabel}
</div>
</div>
</PanelSectionRow>
</PanelSection>
<PanelSection>
{!selectedTarget?.configured && selectedTarget && (
<PanelSectionRow>
<Focusable ref={enableRef} noFocusRing>
<ButtonItem layout="below" onClick={handleProfileAction}>Enable for next launch</ButtonItem>
</Focusable>
</PanelSectionRow>
)}
</PanelSection>
{selectedTarget?.configured && (
<GameConfigurationControls
config={config}
onConfigChange={onConfigChange}
autoFocusFpsMultiplier={focusFpsMultiplier}
onFpsMultiplierFocused={clearFpsFocusRequest}
showWorkarounds
workaroundTarget={selectedTarget || undefined}
onRepairWorkaround={selectedTarget ? () => onRepair(selectedTarget.appid) : undefined}
/>
)}
{selectedTarget?.configured && (
<PanelSectionRow>
<ButtonItem layout="below" onClick={handleProfileAction}>Remove profile</ButtonItem>
</PanelSectionRow>
)}
<ProfileDetails description={profileDescription} />
</Focusable>
);
}
|