Refactor build and start scripts in package.json; add plugin to exclude debug files from production build in vite.config.ts; remove ConnectScreen component and replace with ConnectionPlaceholder in multiple pages; update DeviceContext to auto-connect using device IP from URL; enhance locale files with new device IP labels.
This commit is contained in:
@@ -9,6 +9,7 @@ import {
|
||||
PeqFilter,
|
||||
PeqState,
|
||||
} from "@/lib/luxsinApi";
|
||||
import { getDeviceIpFromUrl, resolveInitialDeviceIp } from "@/lib/deviceIp";
|
||||
|
||||
interface DeviceContextType {
|
||||
ip: string;
|
||||
@@ -39,7 +40,7 @@ interface DeviceContextType {
|
||||
const DeviceContext = createContext<DeviceContextType | null>(null);
|
||||
|
||||
export function DeviceProvider({ children }: { children: React.ReactNode }) {
|
||||
const [ip, setIp] = useState(() => localStorage.getItem("luxsin_ip") || "192.168.2.30");
|
||||
const [ip, setIp] = useState(resolveInitialDeviceIp);
|
||||
const [isConnected, setIsConnected] = useState(false);
|
||||
const [isConnecting, setIsConnecting] = useState(false);
|
||||
const [isDemoMode, setDemoMode] = useState(false);
|
||||
@@ -51,6 +52,7 @@ export function DeviceProvider({ children }: { children: React.ReactNode }) {
|
||||
const [api, setApi] = useState<LuxsinAPI | null>(null);
|
||||
const lastMsgCountRef = useRef<number>(-1);
|
||||
const pollIntervalRef = useRef<ReturnType<typeof setInterval> | null>(null);
|
||||
const autoConnectStartedRef = useRef(false);
|
||||
|
||||
const saveIp = useCallback((newIp: string) => {
|
||||
setIp(newIp);
|
||||
@@ -202,6 +204,17 @@ export function DeviceProvider({ children }: { children: React.ReactNode }) {
|
||||
if (!isDemoMode && api) api.setBalance(v).catch(console.error);
|
||||
}, [api, isDemoMode]);
|
||||
|
||||
// 启动时根据 ?ip= 或已存 IP 自动连接(默认进入首页,无需连接页)
|
||||
useEffect(() => {
|
||||
if (autoConnectStartedRef.current) return;
|
||||
autoConnectStartedRef.current = true;
|
||||
|
||||
const urlIp = getDeviceIpFromUrl();
|
||||
const targetIp = urlIp ?? ip;
|
||||
if (urlIp) saveIp(urlIp);
|
||||
void connect(false, targetIp);
|
||||
}, [connect, ip, saveIp]);
|
||||
|
||||
// Polling for changes
|
||||
useEffect(() => {
|
||||
if (!isConnected || isDemoMode || !api) return;
|
||||
|
||||
Reference in New Issue
Block a user