提交应用EQ时判断EQ是否启用和删除不生效的问题
This commit is contained in:
@@ -171,6 +171,7 @@ export interface PeqFilter {
|
|||||||
export interface PeqState {
|
export interface PeqState {
|
||||||
filters: PeqFilter[];
|
filters: PeqFilter[];
|
||||||
peqSelect?: number;
|
peqSelect?: number;
|
||||||
|
peqEnable?: number; // 0: off, 1: on
|
||||||
peq?: Array<{
|
peq?: Array<{
|
||||||
name: string;
|
name: string;
|
||||||
filters?: PeqFilter[] | string;
|
filters?: PeqFilter[] | string;
|
||||||
|
|||||||
+136
-42
@@ -8,6 +8,16 @@
|
|||||||
============================================================ */
|
============================================================ */
|
||||||
import BottomNav from "@/components/BottomNav";
|
import BottomNav from "@/components/BottomNav";
|
||||||
import ConnectionPlaceholder from "@/components/ConnectionPlaceholder";
|
import ConnectionPlaceholder from "@/components/ConnectionPlaceholder";
|
||||||
|
import {
|
||||||
|
AlertDialog,
|
||||||
|
AlertDialogAction,
|
||||||
|
AlertDialogCancel,
|
||||||
|
AlertDialogContent,
|
||||||
|
AlertDialogDescription,
|
||||||
|
AlertDialogFooter,
|
||||||
|
AlertDialogHeader,
|
||||||
|
AlertDialogTitle,
|
||||||
|
} from "@/components/ui/alert-dialog";
|
||||||
import { useDevice } from "@/contexts/DeviceContext";
|
import { useDevice } from "@/contexts/DeviceContext";
|
||||||
import {
|
import {
|
||||||
AI_SPLIT_RESTORE_PATH_KEY,
|
AI_SPLIT_RESTORE_PATH_KEY,
|
||||||
@@ -30,7 +40,6 @@ import {
|
|||||||
} from "@/lib/aiApi";
|
} from "@/lib/aiApi";
|
||||||
|
|
||||||
import { buildPeqSvgCurveData, getFilterType, PeqBandForResponse } from "@/lib/peqAudio";
|
import { buildPeqSvgCurveData, getFilterType, PeqBandForResponse } from "@/lib/peqAudio";
|
||||||
import { buildPeqPresetBody } from "@/lib/luxsinApi";
|
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
import {
|
import {
|
||||||
ArrowUp,
|
ArrowUp,
|
||||||
@@ -206,12 +215,18 @@ export default function AIPage({ variant = "page", onClose }: AIPageProps = {})
|
|||||||
const [routePath, setLocation] = useLocation();
|
const [routePath, setLocation] = useLocation();
|
||||||
const isLgUp = useIsLgUp();
|
const isLgUp = useIsLgUp();
|
||||||
const { setOpen: setAiPanelOpen } = useAIDrawer();
|
const { setOpen: setAiPanelOpen } = useAIDrawer();
|
||||||
const { isConnected, deviceState, api } = useDevice();
|
const { isConnected, deviceState, api, updateSetting } = useDevice();
|
||||||
const mac = deviceState?.mac ?? "";
|
const mac = deviceState?.mac ?? "";
|
||||||
const language = resolveDeviceLanguage(deviceState?.language);
|
const language = resolveDeviceLanguage(deviceState?.language);
|
||||||
const deviceName = deviceState?.device ?? "Luxsin X9";
|
const deviceName = deviceState?.device ?? "Luxsin X9";
|
||||||
|
|
||||||
const aiText = useMemo(() => resolveAILocale(language), [language]);
|
const aiText = useMemo(() => resolveAILocale(language), [language]);
|
||||||
|
const promptText = useMemo(() => resolveLocalePack(language).prompt, [language]);
|
||||||
|
const eqUi = useMemo(() => {
|
||||||
|
const pack = resolveLocalePack(language);
|
||||||
|
const peq = pack.peq as typeof localeZh.peq;
|
||||||
|
return peq.eqUi ?? (localeEn.peq as typeof localeEn.peq).eqUi;
|
||||||
|
}, [language]);
|
||||||
|
|
||||||
const restoreDesktopSplit = useCallback(() => {
|
const restoreDesktopSplit = useCallback(() => {
|
||||||
const path = readAndClearAiSplitRestorePath();
|
const path = readAndClearAiSplitRestorePath();
|
||||||
@@ -224,6 +239,8 @@ export default function AIPage({ variant = "page", onClose }: AIPageProps = {})
|
|||||||
const [input, setInput] = useState("");
|
const [input, setInput] = useState("");
|
||||||
const [sending, setSending] = useState(false);
|
const [sending, setSending] = useState(false);
|
||||||
const [historyOpen, setHistoryOpen] = useState(false);
|
const [historyOpen, setHistoryOpen] = useState(false);
|
||||||
|
const [pendingDeleteId, setPendingDeleteId] = useState<string | null>(null);
|
||||||
|
const [pendingApplyMsg, setPendingApplyMsg] = useState<OptimizeUIMessage | null>(null);
|
||||||
const [chats, setChats] = useState<ChatRead[]>([]);
|
const [chats, setChats] = useState<ChatRead[]>([]);
|
||||||
// 初次加载历史会话期间,避免先闪一下欢迎页再切到消息
|
// 初次加载历史会话期间,避免先闪一下欢迎页再切到消息
|
||||||
const [initializing, setInitializing] = useState(true);
|
const [initializing, setInitializing] = useState(true);
|
||||||
@@ -383,27 +400,22 @@ export default function AIPage({ variant = "page", onClose }: AIPageProps = {})
|
|||||||
}
|
}
|
||||||
}, [aiText, chatId, newChat]);
|
}, [aiText, chatId, newChat]);
|
||||||
|
|
||||||
// ── 历史面板里删除某条会话 ──
|
// ── 历史面板里删除某条会话(确认框用 AlertDialog,WebView 不支持 window.confirm) ──
|
||||||
const deleteChatById = useCallback(
|
const confirmDeleteChat = useCallback(async (id: string) => {
|
||||||
async (id: string) => {
|
try {
|
||||||
const ok = window.confirm(aiText.history.deleteConfirm);
|
await clearChat(id);
|
||||||
if (!ok) return;
|
setChats((prev) => prev.filter((c) => c.id !== id));
|
||||||
try {
|
if (chatId === id) {
|
||||||
await clearChat(id);
|
setChatId(null);
|
||||||
setChats((prev) => prev.filter((c) => c.id !== id));
|
setMessages([]);
|
||||||
if (chatId === id) {
|
|
||||||
setChatId(null);
|
|
||||||
setMessages([]);
|
|
||||||
}
|
|
||||||
toast.success(aiText.history.deleted);
|
|
||||||
} catch (e: any) {
|
|
||||||
toast.error(
|
|
||||||
formatText(aiText.history.deleteFailed, { message: e?.message ?? e }),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
},
|
toast.success(aiText.history.deleted);
|
||||||
[aiText, chatId],
|
} catch (e: any) {
|
||||||
);
|
toast.error(
|
||||||
|
formatText(aiText.history.deleteFailed, { message: e?.message ?? e }),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}, [aiText, chatId]);
|
||||||
|
|
||||||
// ── 发送提问 ──
|
// ── 发送提问 ──
|
||||||
const send = useCallback(
|
const send = useCallback(
|
||||||
@@ -621,8 +633,6 @@ export default function AIPage({ variant = "page", onClose }: AIPageProps = {})
|
|||||||
autoPre: selected?.autoPre,
|
autoPre: selected?.autoPre,
|
||||||
brand: selected?.brand,
|
brand: selected?.brand,
|
||||||
model: selected?.model,
|
model: selected?.model,
|
||||||
target: selected?.target,
|
|
||||||
form: selected?.form,
|
|
||||||
filters: (selectedFilters ?? peqState.filters ?? []) as OptimizePeqPayload["filters"],
|
filters: (selectedFilters ?? peqState.filters ?? []) as OptimizePeqPayload["filters"],
|
||||||
});
|
});
|
||||||
} catch {
|
} catch {
|
||||||
@@ -634,7 +644,7 @@ export default function AIPage({ variant = "page", onClose }: AIPageProps = {})
|
|||||||
if (isConnected) void refreshCurrentDevicePeq();
|
if (isConnected) void refreshCurrentDevicePeq();
|
||||||
}, [isConnected, refreshCurrentDevicePeq]);
|
}, [isConnected, refreshCurrentDevicePeq]);
|
||||||
|
|
||||||
const handleApplyToggle = useCallback(
|
const executeApplyToggle = useCallback(
|
||||||
async (msg: OptimizeUIMessage) => {
|
async (msg: OptimizeUIMessage) => {
|
||||||
if (!api) {
|
if (!api) {
|
||||||
toast.error(aiText.deviceDisconnected);
|
toast.error(aiText.deviceDisconnected);
|
||||||
@@ -642,28 +652,21 @@ export default function AIPage({ variant = "page", onClose }: AIPageProps = {})
|
|||||||
}
|
}
|
||||||
const nextApplied = !msg.applied;
|
const nextApplied = !msg.applied;
|
||||||
const targetPeq = nextApplied ? msg.afterPeq : msg.beforePeq;
|
const targetPeq = nextApplied ? msg.afterPeq : msg.beforePeq;
|
||||||
const metaSource = currentDevicePeq ?? targetPeq;
|
|
||||||
setApplyingId(msg.id);
|
setApplyingId(msg.id);
|
||||||
try {
|
try {
|
||||||
await api.upgradePeqChange({
|
await api.upgradePeqChange({
|
||||||
peqChange: buildPeqPresetBody(
|
peqChange: {
|
||||||
{
|
name: targetPeq.name ?? msg.name,
|
||||||
name: targetPeq.name ?? msg.name ?? metaSource?.name ?? "",
|
filters: (targetPeq.filters ?? []).map((f) => ({
|
||||||
brand: targetPeq.brand ?? metaSource?.brand,
|
|
||||||
model: targetPeq.model ?? metaSource?.model,
|
|
||||||
target: targetPeq.target ?? metaSource?.target,
|
|
||||||
form: targetPeq.form ?? metaSource?.form,
|
|
||||||
autoPre: targetPeq.autoPre ?? metaSource?.autoPre,
|
|
||||||
preamp: targetPeq.preamp ?? metaSource?.preamp,
|
|
||||||
canDel: targetPeq.canDel ?? metaSource?.canDel,
|
|
||||||
},
|
|
||||||
(targetPeq.filters ?? []).map((f) => ({
|
|
||||||
type: getFilterType(f.type),
|
type: getFilterType(f.type),
|
||||||
fc: (f.fc ?? f.frequency ?? 1000) as number,
|
fc: (f.fc ?? f.frequency ?? 1000) as number,
|
||||||
gain: f.gain,
|
gain: f.gain,
|
||||||
q: f.q,
|
q: f.q,
|
||||||
})),
|
})),
|
||||||
),
|
autoPre: targetPeq.autoPre,
|
||||||
|
preamp: targetPeq.preamp,
|
||||||
|
canDel: targetPeq.canDel,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
await updateMessageApplied(msg.id, nextApplied);
|
await updateMessageApplied(msg.id, nextApplied);
|
||||||
await api.refreshState();
|
await api.refreshState();
|
||||||
@@ -687,7 +690,35 @@ export default function AIPage({ variant = "page", onClose }: AIPageProps = {})
|
|||||||
setApplyingId(null);
|
setApplyingId(null);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[aiText, api, currentDevicePeq, refreshCurrentDevicePeq],
|
[aiText, api, refreshCurrentDevicePeq],
|
||||||
|
);
|
||||||
|
|
||||||
|
const handleApplyToggle = useCallback(
|
||||||
|
(msg: OptimizeUIMessage) => {
|
||||||
|
if (!api) {
|
||||||
|
toast.error(aiText.deviceDisconnected);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if ((deviceState?.peqEnable ?? 0) !== 1) {
|
||||||
|
setPendingApplyMsg(msg);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
void executeApplyToggle(msg);
|
||||||
|
},
|
||||||
|
[aiText, api, deviceState?.peqEnable, executeApplyToggle],
|
||||||
|
);
|
||||||
|
|
||||||
|
const confirmEnableAndApply = useCallback(
|
||||||
|
async (msg: OptimizeUIMessage) => {
|
||||||
|
try {
|
||||||
|
const bypassOn = (deviceState?.dsp_enable ?? 0) === 0;
|
||||||
|
await updateSetting(bypassOn ? { peqEnable: 1, dsp_enable: 1 } : { peqEnable: 1 });
|
||||||
|
await executeApplyToggle(msg);
|
||||||
|
} catch (e: any) {
|
||||||
|
toast.error(formatText(aiText.optimize.applyFailed, { message: e?.message ?? e }));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[aiText, deviceState?.dsp_enable, executeApplyToggle, updateSetting],
|
||||||
);
|
);
|
||||||
|
|
||||||
const openCompare = useCallback(
|
const openCompare = useCallback(
|
||||||
@@ -907,10 +938,72 @@ export default function AIPage({ variant = "page", onClose }: AIPageProps = {})
|
|||||||
onClose={() => setHistoryOpen(false)}
|
onClose={() => setHistoryOpen(false)}
|
||||||
onSelect={(id) => loadChat(id)}
|
onSelect={(id) => loadChat(id)}
|
||||||
onNew={newChat}
|
onNew={newChat}
|
||||||
onDelete={deleteChatById}
|
onDelete={setPendingDeleteId}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
<AlertDialog
|
||||||
|
open={pendingDeleteId !== null}
|
||||||
|
onOpenChange={(open) => {
|
||||||
|
if (!open) setPendingDeleteId(null);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<AlertDialogContent className="top-[42%] z-[70] border-white/10 bg-zinc-900 text-white sm:max-w-md">
|
||||||
|
<AlertDialogHeader>
|
||||||
|
<AlertDialogTitle className="text-white">
|
||||||
|
{aiText.history.delete}
|
||||||
|
</AlertDialogTitle>
|
||||||
|
<AlertDialogDescription className="text-white/60">
|
||||||
|
{aiText.history.deleteConfirm}
|
||||||
|
</AlertDialogDescription>
|
||||||
|
</AlertDialogHeader>
|
||||||
|
<AlertDialogFooter>
|
||||||
|
<AlertDialogCancel className="border-white/20 bg-transparent text-white hover:bg-white/10">
|
||||||
|
{promptText.cancel}
|
||||||
|
</AlertDialogCancel>
|
||||||
|
<AlertDialogAction
|
||||||
|
className="bg-red-500 text-white hover:bg-red-500/90 focus-visible:ring-red-500"
|
||||||
|
onClick={() => {
|
||||||
|
if (pendingDeleteId) void confirmDeleteChat(pendingDeleteId);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{promptText.delete}
|
||||||
|
</AlertDialogAction>
|
||||||
|
</AlertDialogFooter>
|
||||||
|
</AlertDialogContent>
|
||||||
|
</AlertDialog>
|
||||||
|
|
||||||
|
<AlertDialog
|
||||||
|
open={pendingApplyMsg !== null}
|
||||||
|
onOpenChange={(open) => {
|
||||||
|
if (!open) setPendingApplyMsg(null);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<AlertDialogContent className="top-[42%] z-[70] border-white/10 bg-zinc-900 text-white sm:max-w-md">
|
||||||
|
<AlertDialogHeader>
|
||||||
|
<AlertDialogTitle className="text-white">
|
||||||
|
{eqUi.enableConfirmTitle}
|
||||||
|
</AlertDialogTitle>
|
||||||
|
<AlertDialogDescription className="text-white/60">
|
||||||
|
{eqUi.enableConfirmDesc}
|
||||||
|
</AlertDialogDescription>
|
||||||
|
</AlertDialogHeader>
|
||||||
|
<AlertDialogFooter>
|
||||||
|
<AlertDialogCancel className="border-white/20 bg-transparent text-white hover:bg-white/10">
|
||||||
|
{eqUi.cancel}
|
||||||
|
</AlertDialogCancel>
|
||||||
|
<AlertDialogAction
|
||||||
|
className="bg-[#00FFF6] text-black hover:bg-[#00FFF6]/90 focus-visible:ring-[#00FFF6]"
|
||||||
|
onClick={() => {
|
||||||
|
if (pendingApplyMsg) void confirmEnableAndApply(pendingApplyMsg);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{eqUi.enableConfirmOk}
|
||||||
|
</AlertDialogAction>
|
||||||
|
</AlertDialogFooter>
|
||||||
|
</AlertDialogContent>
|
||||||
|
</AlertDialog>
|
||||||
|
|
||||||
{/* ── 对比对话框 ── */}
|
{/* ── 对比对话框 ── */}
|
||||||
{compareMsg && (
|
{compareMsg && (
|
||||||
<CompareDialog
|
<CompareDialog
|
||||||
@@ -1157,11 +1250,12 @@ function HistoryPanel({
|
|||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
<button
|
<button
|
||||||
|
type="button"
|
||||||
onClick={(e) => {
|
onClick={(e) => {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
onDelete(c.id);
|
onDelete(c.id);
|
||||||
}}
|
}}
|
||||||
className="ml-2 w-8 h-8 rounded-full flex items-center justify-center text-white/40 hover:text-red-400 active:text-red-500 transition-colors"
|
className="ml-2 w-8 h-8 shrink-0 rounded-full flex items-center justify-center text-white/40 hover:text-red-400 active:text-red-500 transition-colors touch-manipulation"
|
||||||
style={{ background: "rgba(44,44,46,0.6)" }}
|
style={{ background: "rgba(44,44,46,0.6)" }}
|
||||||
aria-label={aiText.history.delete}
|
aria-label={aiText.history.delete}
|
||||||
>
|
>
|
||||||
|
|||||||
Reference in New Issue
Block a user