From 40f5af2120a93c92df342b0a71deb6dc7fad28a9 Mon Sep 17 00:00:00 2001 From: luckfox-eng29 Date: Fri, 15 May 2026 18:45:23 +0800 Subject: [PATCH] feat(usb): add UsbStatusPanel component and integrate it into BottomBarPC and MobileDesktop Signed-off-by: luckfox-eng29 --- .../usb_status/UsbStatusPanel.tsx | 79 +++++++++++++++++++ .../core/bar_bottom/BottomBarMobile.tsx | 12 +-- ui/src/layout/core/bar_bottom/BottomBarPC.tsx | 11 ++- ui/src/layout/core/desktop/DesktopMobile.tsx | 10 ++- 4 files changed, 101 insertions(+), 11 deletions(-) create mode 100644 ui/src/layout/components_bottom/usb_status/UsbStatusPanel.tsx diff --git a/ui/src/layout/components_bottom/usb_status/UsbStatusPanel.tsx b/ui/src/layout/components_bottom/usb_status/UsbStatusPanel.tsx new file mode 100644 index 0000000..edbfec5 --- /dev/null +++ b/ui/src/layout/components_bottom/usb_status/UsbStatusPanel.tsx @@ -0,0 +1,79 @@ +import React, { useCallback } from "react"; +import { useReactAt } from "i18n-auto-extractor/react"; +import { useJsonRpc } from "@/hooks/useJsonRpc"; +import notifications from "@/notifications"; +import { dark_bg2_style, dark_bd_style, dark_line_style, dark_bg_style_fun } from "@/layout/theme_color"; +import { useThemeSettings } from "@routes/login_page/useLocalAuth"; +import { isMobile } from "react-device-detect"; + +const UsbStatusPanel: React.FC = () => { + const { $at } = useReactAt(); + const { isDark } = useThemeSettings(); + const [send] = useJsonRpc(); + + const handleReinitializeUsbGadget = useCallback(() => { + send("reinitializeUsbGadget", {}, resp => { + if ("error" in resp) { + notifications.error( + `Failed to reinitialize USB gadget: ${resp.error.data || "Unknown error"}`, + ); + return; + } + notifications.success("USB Gadget reinitialized successfully"); + }); + }, [send]); + + if (isMobile) { + return ( +
+
+
+ + {$at("Reinitialize USB Gadget")} + +
+
+
+ ); + } + + return ( +
+
+
{ + e.currentTarget.style.backgroundColor = isDark ? 'rgba(255, 255, 255, 0.08)' : 'rgba(0, 0, 0, 0.04)'; + }} + onMouseLeave={(e) => { + e.currentTarget.style.backgroundColor = 'transparent'; + }} + > + {$at("Reinitialize USB Gadget")} +
+
+
+ ); +}; + +export default UsbStatusPanel; diff --git a/ui/src/layout/core/bar_bottom/BottomBarMobile.tsx b/ui/src/layout/core/bar_bottom/BottomBarMobile.tsx index 10f8aac..a2f60e4 100644 --- a/ui/src/layout/core/bar_bottom/BottomBarMobile.tsx +++ b/ui/src/layout/core/bar_bottom/BottomBarMobile.tsx @@ -176,11 +176,13 @@ export default function BottomBarMobile() { text={$at("HDMI")} isActive={!!peerConnectionState} /> - : } - text={$at("USB")} - isActive={usbState === "configured"} - /> +
toggleSidebarView("UsbStatusPanel")}> + : } + text={$at("USB")} + isActive={usbState === "configured"} + /> +
- : } - text={$at("USB")} - isActive={usbState === "configured"} + : } + buttonText={$at("USB")} + style={{ color: usbState === "configured" ? "rgba(0, 205, 27, 1)" : "inherit" }} + panelContent={} + align="left" /> ()} className={"px-[20px]"} /> + ()} + /> send("wheelReport", { wheelY: 1 })} + onClick={() => { send("wheelReport", { wheelY: 1 }); }} > ▲ @@ -712,7 +718,7 @@ export default function MobileDesktop({ isFullscreen }: { isFullscreen?: number "mt-1 flex h-8 w-8 items-center justify-center rounded-full text-white text-xs active:scale-90 transition-transform duration-100", isDark ? "bg-gray-500/70" : "bg-black/30", )} - onClick={() => send("wheelReport", { wheelY: -1 })} + onClick={() => { send("wheelReport", { wheelY: -1 }); }} > ▼