新增了耳机音量保护和模拟输入的各项设置

This commit is contained in:
eafonyang
2026-10-22 18:40:18 +08:00
parent c5cdbb4a64
commit 81f5635dd6
15 changed files with 650 additions and 38 deletions
+8 -3
View File
@@ -1,6 +1,7 @@
import React, { createContext, useCallback, useContext, useEffect, useRef, useState } from "react";
import {
DeviceState,
getHomeVolumeMax,
LuxsinAPI,
MOCK_DEVICE_STATE,
MOCK_PEQ_STATE,
@@ -262,12 +263,16 @@ export function DeviceProvider({ children }: { children: React.ReactNode }) {
}, [api, isDemoMode, applyPeqFiltersToState]);
// Optimistic setters
const maxVolume = getHomeVolumeMax(deviceState);
const setVolume = useCallback((v: number) => {
setDeviceState(prev => prev ? { ...prev, volume: v } : prev);
if (!Number.isFinite(v)) return;
// 指令和乐观状态使用同一上限,防止任何首页入口发送超限音量。
const volume = Math.max(0, Math.min(maxVolume, Math.round(v)));
setDeviceState(prev => prev ? { ...prev, volume } : prev);
if (!isDemoMode && api) {
api.setVolume(v).catch(console.error);
api.setVolume(volume).catch(console.error);
}
}, [api, isDemoMode]);
}, [api, isDemoMode, maxVolume]);
const setInput = useCallback((v: number) => {
setDeviceState(prev => prev ? { ...prev, input: v } : prev);