import React, { useEffect, useState } from "react"; import { Shield, ShieldAlert, RefreshCw, Wifi } from "lucide-react"; interface Props { children: React.ReactNode; } const VpnGuard: React.FC = ({ children }) => { const VPN_API = "http://10.0.0.2:3000"; const [checking, setChecking] = useState(true); const [vpnConnected, setVpnConnected] = useState(true); const [isRetrying, setIsRetrying] = useState(false); const checkVPN = async () => { try { setChecking(true); const res = await window.electron?.checkRegion(); console.log("VpnGuard", res); setVpnConnected(res?.success === true); } catch (error) { console.error("VPN check failed:", error); setVpnConnected(false); } finally { setChecking(false); setIsRetrying(false); } }; useEffect(() => { checkVPN(); }, []); const connectVPN = async () => { setChecking(true); try { const res = await window.electron.connectVPN(); console.log("connectVPN result → ", res); // Only proceed if VPN actually connected if (res === "Windows VPN connected silently") { const vpnRes = await window.electron.updateBaseURL(VPN_API); console.log("vpnRes", vpnRes); if (vpnRes) { // Run VPN check again AFTER URL changes await checkVPN(); } else { console.warn("Base URL updated but health check failed"); } } } catch (error) { console.log(error); } finally { setChecking(false); } }; // Checking state if (checking && !isRetrying) { return (

Verifying Connection

Checking VPN status...

); } // VPN not connected state if (!vpnConnected) { return (
{/* Icon with animation */}
{/* Title */}

VPN Required

{/* Description */}

Please connect to your company VPN to access this application.

{/* Retry button */} {/* Help text */}

Need help? Contact IT support at{" "} support@company.com

); } return <>{children}; }; export default VpnGuard;