Enhance DeviceContext and LuxsinAPI to support new PEQ apply functionality; update locale files for English and Chinese to include new UI strings for applying and saving PEQ settings. Refactor AudioPage and EQPage to integrate boot sound management and improve state handling.

This commit is contained in:
yangy
2026-05-18 13:42:29 +08:00
parent b5c0606972
commit ba5f5d074a
8 changed files with 463 additions and 59 deletions
+19 -13
View File
@@ -22,6 +22,7 @@ const KEY_TO_SETTING: Record<string, string> = {
language: "language",
analogGain: "analogGain",
soundStep: "soundStep",
bootSound: "bootSound",
filterCharacteristic: "pcm",
mutePolar: "hdmimutepolar",
IISMode: "hdmiType",
@@ -63,7 +64,7 @@ export function navigateToSelect(title: string, options: string[], selected: num
}
export default function SelectPage() {
const [, setLocation] = useLocation();
const [location, setLocation] = useLocation();
const { updateSetting } = useDevice();
const [state, setState] = useState<{
title: string;
@@ -71,14 +72,15 @@ export default function SelectPage() {
selected: number;
back: string;
key: string;
} | null>(selectPageState);
} | null>(() => selectPageState);
const [saving, setSaving] = useState(false);
// Clear state when component unmounts
// Re-read global state whenever we enter /select (avoids stale key/options after remount)
useEffect(() => {
return () => {
selectPageState = null;
};
}, []);
if (location === "/select" && selectPageState) {
setState({ ...selectPageState });
}
}, [location]);
if (!state) {
return null;
@@ -86,16 +88,20 @@ export default function SelectPage() {
const { title, options, selected: selectedIdx, back, key } = state;
const handleSelect = (idx: number) => {
// Keep selection result for pages that handle non-api local updates (e.g. EQ filter type)
const handleSelect = async (idx: number) => {
if (saving) return;
selectPageResult = { key, selected: idx };
// Apply setting if key maps to an API field
const apiField = KEY_TO_SETTING[key];
if (apiField) {
updateSetting({ [apiField]: idx } as Parameters<typeof updateSetting>[0]);
setSaving(true);
try {
await updateSetting({ [apiField]: idx });
} finally {
setSaving(false);
}
}
// Navigate back
selectPageState = null;
setLocation(back);
};
@@ -121,7 +127,7 @@ export default function SelectPage() {
<button
key={idx}
className="ios-list-row w-full text-left active:bg-white/5 transition-colors"
onClick={() => handleSelect(idx)}>
onClick={() => void handleSelect(idx)}>
<span className={`flex-1 text-[16px] ${isSelected ? "text-white font-medium" : "text-white/75"}`}>
{opt}
</span>