Skip to content
2 changes: 0 additions & 2 deletions headless-rust/frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { RootRoute } from "@/routes/__root";
import { IndexRoute } from "@/routes/index";
import { ViolationsRoute } from "@/routes/violations";
import { SettingsRoute } from "@/routes/settings";
import { AboutRoute } from "@/routes/about";
import { TeableRoute } from "@/routes/teable";
import { SetupRoute } from "@/routes/setup";
import { pluginRegistry } from "@/plugins";
Expand All @@ -16,7 +15,6 @@ const routeTree = RootRoute.addChildren([
IndexRoute,
ViolationsRoute,
SettingsRoute,
AboutRoute,
TeableRoute,
SetupRoute,
...pluginRegistry.getRoutes(RootRoute),
Expand Down
25 changes: 19 additions & 6 deletions headless-rust/frontend/src/components/MobileMenuSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ import {
Settings,
Sliders,
Database,
Info,
Layers,
ChevronRight,
Power,
} from "lucide-react";
import { ShutdownDialog } from "./ShutdownDialog";
import { cn } from "@/lib/utils";

interface MobileMenuSheetProps {
Expand All @@ -33,7 +34,6 @@ const CORE_NAV_LINKS = [
{ label: "Camera Setup", to: "/setup", icon: Sliders },
{ label: "System Settings", to: "/settings", icon: Settings },
{ label: "Teable Sync", to: "/teable", icon: Database },
{ label: "About & Updates", to: "/about", icon: Info },
] as const;

const MODE_META: Record<string, { label: string; badgeClass: string }> = {
Expand Down Expand Up @@ -171,10 +171,23 @@ export function MobileMenuSheet({ open, onOpenChange }: MobileMenuSheetProps) {
)}
</div>

{/* Footer with Theme Toggle */}
<div className="p-3 border-t border-border bg-muted/20 flex items-center justify-between">
<span className="text-xs text-muted-foreground font-medium">Appearance</span>
<ThemeToggle />
{/* Footer with Host Shutdown and Theme Toggle */}
<div className="p-3 border-t border-border bg-muted/20 space-y-2.5">
<div className="flex items-center justify-between">
<span className="text-xs text-muted-foreground font-medium">Appearance</span>
<ThemeToggle />
</div>
<ShutdownDialog
trigger={
<button
type="button"
className="w-full flex items-center justify-center gap-2 px-3 py-2 text-xs font-semibold text-rose-400 bg-rose-500/10 hover:bg-rose-500/20 border border-rose-500/25 rounded-lg transition-colors cursor-pointer"
>
<Power className="w-3.5 h-3.5 text-rose-500" />
<span>Shut Down Host (Pi)</span>
</button>
}
/>
</div>
</SheetContent>
</Sheet>
Expand Down
1 change: 0 additions & 1 deletion headless-rust/frontend/src/components/NavigationMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const CORE_NAV_ITEMS = [
{ label: "Settings", to: "/settings" },
{ label: "Setup", to: "/setup" },
{ label: "Teable", to: "/teable" },
{ label: "About", to: "/about" },
] as const;

const MODE_META: Record<string, { label: string; badgeClass: string }> = {
Expand Down
177 changes: 177 additions & 0 deletions headless-rust/frontend/src/components/ShutdownDialog.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
import { useState } from "react";
import { toast } from "sonner";
import { getRpc } from "@/lib/rpc";
import {
Dialog,
DialogContent,
DialogHeader,
DialogTitle,
DialogDescription,
DialogFooter,
DialogTrigger,
DialogClose,
} from "@/components/ui/dialog";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import { AlertTriangle, Power, Loader2, CheckCircle2 } from "lucide-react";

interface ShutdownDialogProps {
trigger?: React.ReactNode;
open?: boolean;
onOpenChange?: (open: boolean) => void;
}

export function ShutdownDialog({ trigger, open: controlledOpen, onOpenChange }: ShutdownDialogProps) {
const [internalOpen, setInternalOpen] = useState(false);
const isControlled = controlledOpen !== undefined;
const open = isControlled ? controlledOpen : internalOpen;

const setOpen = (next: boolean) => {
if (!next) {
// Reset state when closing
setPassword("");
setErrorMessage(null);
setCompleted(false);
}
if (isControlled) {
onOpenChange?.(next);
} else {
setInternalOpen(next);
}
};

const [password, setPassword] = useState("");
const [shuttingDown, setShuttingDown] = useState(false);
const [errorMessage, setErrorMessage] = useState<string | null>(null);
const [completed, setCompleted] = useState(false);
const [simulated, setSimulated] = useState(false);

const handleShutdown = async (e?: React.FormEvent) => {
if (e) e.preventDefault();
setShuttingDown(true);
setErrorMessage(null);
try {
const res = await getRpc().request.shutdownHost({
password: password.trim() ? password.trim() : undefined,
});
setCompleted(true);
setSimulated(Boolean(res?.simulated));
toast.success(res?.simulated ? "Shutdown simulated (mock mode)" : "Host system is shutting down...");
} catch (err: any) {
const msg = err?.message || String(err);
setErrorMessage(msg);
toast.error(`Shutdown failed: ${msg}`);
} finally {
setShuttingDown(false);
}
};

return (
<Dialog open={open} onOpenChange={setOpen}>
{trigger && <DialogTrigger asChild>{trigger}</DialogTrigger>}
<DialogContent className="sm:max-w-md">
<DialogHeader className="gap-2">
<div className="flex items-center gap-2.5 text-rose-500">
<div className="p-2 rounded-full bg-rose-500/10 border border-rose-500/20">
<Power className="w-5 h-5 text-rose-500" />
</div>
<DialogTitle className="text-base font-bold">Shut Down Raspberry Pi Host</DialogTitle>
</div>
<DialogDescription className="text-xs text-muted-foreground leading-relaxed pt-1">
This will cleanly shut down the Raspberry Pi operating system and stop all background camera services.
You will need to power cycle the hardware to turn it back on.
</DialogDescription>
</DialogHeader>

{completed ? (
<div className="py-4 space-y-3 text-center">
<div className="inline-flex p-3 rounded-full bg-emerald-500/10 text-emerald-500 border border-emerald-500/20">
<CheckCircle2 className="w-8 h-8" />
</div>
<h4 className="text-sm font-semibold text-foreground">
{simulated ? "Shutdown Simulated (Mock Mode)" : "System Powering Off"}
</h4>
<p className="text-xs text-muted-foreground max-w-xs mx-auto">
{simulated
? "Mock hardware mode is enabled. No actual machine shutdown was initiated."
: "The host Raspberry Pi has received the shutdown command and will power down shortly. You can safely disconnect power once the activity LED stops blinking."}
</p>
<DialogFooter className="pt-2 sm:justify-center">
<DialogClose asChild>
<Button variant="outline" size="sm">
Close
</Button>
</DialogClose>
</DialogFooter>
</div>
) : (
<form onSubmit={handleShutdown} className="space-y-4 pt-1">
{errorMessage && (
<div className="p-3 rounded-lg bg-rose-500/10 border border-rose-500/30 text-rose-400 text-xs flex items-start gap-2 break-words">
<AlertTriangle className="w-4 h-4 shrink-0 mt-0.5" />
<div className="flex-1">
<span className="font-semibold block">Shutdown request failed:</span>
<span className="text-[11px] opacity-90">{errorMessage}</span>
<span className="block text-[11px] text-muted-foreground mt-1">
If your Pi user requires a sudo password, please enter it below.
</span>
</div>
</div>
)}

<div className="space-y-1.5">
<Label htmlFor="sudo-password" className="text-xs font-semibold">
Sudo Password (optional)
</Label>
<Input
id="sudo-password"
type="password"
value={password}
onChange={(e) => setPassword(e.target.value)}
placeholder="Leave empty if passwordless sudo is enabled"
className="font-mono text-xs"
disabled={shuttingDown}
autoFocus
/>
<p className="text-[11px] text-muted-foreground">
Leave empty if passwordless sudo is configured on your Raspberry Pi.
</p>
</div>

<DialogFooter className="gap-2 sm:gap-0 pt-2">
<Button
type="button"
variant="outline"
size="sm"
onClick={() => setOpen(false)}
disabled={shuttingDown}
>
Cancel
</Button>
<Button
type="submit"
variant="destructive"
size="sm"
disabled={shuttingDown}
className="gap-1.5"
>
{shuttingDown ? (
<>
<Loader2 className="w-3.5 h-3.5 animate-spin" />
Shutting down...
</>
) : (
<>
<Power className="w-3.5 h-3.5" />
Yes, Shut Down Now
</>
)}
</Button>
</DialogFooter>
</form>
)}
</DialogContent>
</Dialog>
);
}
8 changes: 8 additions & 0 deletions headless-rust/frontend/src/lib/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,14 @@ class SocketIoRpcClient {
this.socket.on("operatingModeChanged", (payload: any) => {
this.handlePushEvent("operatingModeChanged", payload);
});

this.socket.on("networkStatus", (payload: any) => {
this.handlePushEvent("networkStatus", payload);
});

this.socket.on("networkStatusChanged", (payload: any) => {
this.handlePushEvent("networkStatusChanged", payload);
});
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,20 +105,20 @@ export function DisplayPreview() {
</div>

{/* Retro OLED Screen Bezel */}
<div className="flex flex-col items-center justify-center p-3 rounded-lg bg-black border-2 border-neutral-800 shadow-inner">
<div className="relative p-1.5 rounded bg-neutral-950 border border-neutral-800/80 shadow-[0_0_15px_rgba(56,189,248,0.15)]">
<div className="flex flex-col items-center justify-center p-2.5 sm:p-3 rounded-lg bg-black border-2 border-neutral-800 shadow-inner w-full">
<div className="relative p-1 sm:p-1.5 rounded bg-neutral-950 border border-neutral-800/80 shadow-[0_0_15px_rgba(56,189,248,0.15)] w-full max-w-[280px] sm:max-w-[320px] flex items-center justify-center">
<canvas
ref={canvasRef}
width={128}
height={64}
className="w-[256px] h-32 sm:w-[320px] sm:h-40 block"
className="w-full aspect-[2/1] h-auto block"
style={{ imageRendering: "pixelated" }}
/>
</div>
<div className="flex items-center justify-between w-full mt-2 px-2 text-[10px] font-mono text-neutral-500">
<span>SSD1306 • I²C</span>
<span className="text-cyan-400/80">Active Screen: {preview?.activeScreen || "SpeedCamera"}</span>
<span>128x64</span>
<div className="flex flex-wrap items-center justify-between gap-1 w-full mt-2 px-1 text-[10px] font-mono text-neutral-500">
<span className="shrink-0">SSD1306 • I²C</span>
<span className="text-cyan-400/80 font-medium truncate">Active: {preview?.activeScreen || "SpeedCamera"}</span>
<span className="shrink-0">128x64</span>
</div>
</div>
</div>
Expand Down
Loading