import { useEffect, useRef, useState } from "react"; import { Battery, BellRing, Smartphone, Wifi, WifiOff } from "lucide-react"; import { Device } from "@capacitor/device"; import { isMobile } from "@/lib/platform"; import { useNativeFeatures } from "@/hooks/use-native-features"; import { useHaptics } from "@/hooks/use-haptics"; export function MobileNativeBridge() { const native = useNativeFeatures(); const haptics = useHaptics(); const prevNetwork = useRef(native.networkStatus.connected); const [batteryLevel, setBatteryLevel] = useState(null); // Request notifications + prime native layer useEffect(() => { if (!isMobile()) return; native.requestNotificationPermission(); const loadBattery = async () => { try { const info = await Device.getBatteryInfo(); if (typeof info.batteryLevel === "number") { setBatteryLevel(Math.round(info.batteryLevel * 100)); } } catch (err) { console.log("[MobileNativeBridge] battery info unavailable", err); } }; loadBattery(); // eslint-disable-next-line react-hooks/exhaustive-deps }, []); // Network change feedback useEffect(() => { if (!isMobile()) return; const current = native.networkStatus.connected; if (prevNetwork.current !== current) { const label = current ? "Online" : "Offline"; native.showToast(`Network: ${label}`); haptics.notification(current ? "success" : "warning"); prevNetwork.current = current; } }, [native.networkStatus.connected, native, haptics]); if (!isMobile()) return null; const batteryText = batteryLevel !== null ? `${batteryLevel}%` : "--"; const handleNotify = async () => { await native.sendLocalNotification("AeThex OS", "Synced with your device"); await haptics.notification("success"); }; const handleToast = async () => { await native.showToast("AeThex is live on-device"); await haptics.impact("light"); }; return (
Device Link
{native.networkStatus.connected ? ( ) : ( )} {native.networkStatus.connected ? "Online" : "Offline"}
Battery
{batteryText}
); }