1866 lines
77 KiB
JavaScript
1866 lines
77 KiB
JavaScript
import React, { useEffect, useMemo, useRef, useState } from "react";
|
||
import {
|
||
ShieldCheck,
|
||
ShieldAlert,
|
||
Shield,
|
||
Power,
|
||
Zap,
|
||
Globe,
|
||
Gamepad2,
|
||
GraduationCap,
|
||
DoorOpen,
|
||
Gauge,
|
||
Activity,
|
||
Terminal,
|
||
Settings,
|
||
Info,
|
||
RefreshCw,
|
||
Copy,
|
||
Check,
|
||
ChevronDown,
|
||
RotateCcw,
|
||
Wifi,
|
||
Smartphone,
|
||
Lock,
|
||
Cpu,
|
||
Trash2,
|
||
AlertTriangle,
|
||
CheckCircle2,
|
||
XCircle,
|
||
X,
|
||
Languages,
|
||
Sparkles,
|
||
Server,
|
||
} from "lucide-react";
|
||
import { QRCodeSVG } from "qrcode.react";
|
||
import { TEXT } from "./i18n";
|
||
import {
|
||
invokeTauri,
|
||
sanitizeText,
|
||
isTauriRuntime,
|
||
buildSpoofDpiArgs,
|
||
SPOOFDPI_VERSION,
|
||
} from "./utils/tauriBridge";
|
||
import { listen } from "@tauri-apps/api/event";
|
||
import { check as checkTauriUpdate } from "@tauri-apps/plugin-updater";
|
||
import UpdatePanel from "./components/UpdatePanel";
|
||
|
||
const EMPTY_STATUS = {
|
||
isConnected: false,
|
||
desiredConnected: false,
|
||
connecting: false,
|
||
engineAlive: false,
|
||
proxyRouted: false,
|
||
discordVerified: false,
|
||
webVerified: false,
|
||
latencyMs: 0,
|
||
lastError: null,
|
||
};
|
||
|
||
const engineConfigFrom = (cfg) => ({
|
||
connectionMode: cfg.connectionMode,
|
||
bypassMode: cfg.bypassMode,
|
||
chunkSize: cfg.chunkSize,
|
||
dohProvider: cfg.dohProvider,
|
||
quicBlock: Boolean(cfg.quicBlock),
|
||
lanSharing: cfg.lanSharing,
|
||
proxyPort: cfg.proxyPort,
|
||
pacPort: cfg.pacPort,
|
||
});
|
||
|
||
function Toggle({ checked, onChange, label, desc, disabled = false }) {
|
||
return (
|
||
<div className="flex items-start justify-between gap-5 py-3.5">
|
||
<div className="min-w-0">
|
||
<div className="text-sm font-medium text-slate-100">{label}</div>
|
||
<div className="text-xs text-slate-400 mt-0.5 leading-relaxed">{desc}</div>
|
||
</div>
|
||
<button
|
||
type="button"
|
||
role="switch"
|
||
aria-checked={checked}
|
||
aria-label={label}
|
||
onClick={() => !disabled && onChange(!checked)}
|
||
className={`w-12 h-6 rounded-full p-0.5 shrink-0 transition-colors ${
|
||
checked ? "bg-blue-600" : "bg-slate-700"
|
||
} ${disabled ? "opacity-50 cursor-not-allowed" : ""}`}
|
||
>
|
||
<span
|
||
className={`block w-5 h-5 rounded-full bg-white shadow transition-transform ${
|
||
checked ? "translate-x-6" : "translate-x-0"
|
||
}`}
|
||
/>
|
||
</button>
|
||
</div>
|
||
);
|
||
}
|
||
|
||
function Pill({ tone = "slate", children }) {
|
||
const tones = {
|
||
slate: "bg-slate-800 text-slate-300 border-slate-700",
|
||
green: "bg-emerald-500/15 text-emerald-300 border-emerald-500/30",
|
||
amber: "bg-amber-500/15 text-amber-300 border-amber-500/30",
|
||
red: "bg-rose-500/15 text-rose-300 border-rose-500/30",
|
||
blue: "bg-blue-500/15 text-blue-300 border-blue-500/30",
|
||
};
|
||
return (
|
||
<span
|
||
className={`inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full border text-[11px] font-semibold ${tones[tone]}`}
|
||
>
|
||
{children}
|
||
</span>
|
||
);
|
||
}
|
||
|
||
export default function App() {
|
||
const [lang, setLang] = useState("tr");
|
||
const t = TEXT[lang];
|
||
|
||
const [view, setView] = useState("home");
|
||
const [runtimeReady] = useState(() => isTauriRuntime());
|
||
const [config, setConfig] = useState(null);
|
||
const [bootError, setBootError] = useState(null);
|
||
const configRef = useRef(null);
|
||
const saveQueue = useRef(Promise.resolve());
|
||
const [status, setStatus] = useState(EMPTY_STATUS);
|
||
const [busy, setBusy] = useState(null);
|
||
const [lastError, setLastError] = useState(null);
|
||
const [engineFound, setEngineFound] = useState(true);
|
||
const [engineVersion, setEngineVersion] = useState(`SpoofDPI ${SPOOFDPI_VERSION}`);
|
||
const [localIp, setLocalIp] = useState("127.0.0.1");
|
||
const [isAdmin, setIsAdmin] = useState(false);
|
||
const [appVersion, setAppVersion] = useState("1.7.1");
|
||
const [updateInfo, setUpdateInfo] = useState(null);
|
||
const [updateBusy, setUpdateBusy] = useState(false);
|
||
const [updateError, setUpdateError] = useState(null);
|
||
const [autostartEffective, setAutostartEffective] = useState(false);
|
||
const [autostartWarning, setAutostartWarning] = useState(null);
|
||
|
||
const [logs, setLogs] = useState([]);
|
||
const [logsOpen, setLogsOpen] = useState(false);
|
||
const [benchmarks, setBenchmarks] = useState([]);
|
||
const [benchmarking, setBenchmarking] = useState(false);
|
||
const [diagnostics, setDiagnostics] = useState(null);
|
||
const [diagRunning, setDiagRunning] = useState(false);
|
||
const [copied, setCopied] = useState(null);
|
||
const [ports, setPorts] = useState({ proxyPort: 18080, pacPort: 18081 });
|
||
const [lanWarn, setLanWarn] = useState(false);
|
||
const [autostartNote, setAutostartNote] = useState(false);
|
||
const [eduroam, setEduroam] = useState(null);
|
||
const [captive, setCaptive] = useState(null);
|
||
const [autoBypass, setAutoBypass] = useState(null);
|
||
const [vpn, setVpn] = useState(null);
|
||
const [vpnBusy, setVpnBusy] = useState(null);
|
||
const [vpnError, setVpnError] = useState(null);
|
||
const [vpnProgress, setVpnProgress] = useState(null);
|
||
const [dnsCheck, setDnsCheck] = useState(null);
|
||
const [dnsChecking, setDnsChecking] = useState(false);
|
||
const dohAutoRan = useRef(false);
|
||
const [uiActive, setUiActive] = useState(
|
||
() => typeof document === "undefined" || document.visibilityState !== "hidden"
|
||
);
|
||
|
||
const logEndRef = useRef(null);
|
||
const prevConnected = useRef(false);
|
||
|
||
const pushLog = (level, message) => {
|
||
const now = new Date();
|
||
setLogs((prev) => [
|
||
...prev.slice(-149),
|
||
{
|
||
id: `${Date.now()}-${Math.random()}`,
|
||
time: now.toTimeString().split(" ")[0],
|
||
level,
|
||
text: sanitizeText(String(message ?? "")),
|
||
},
|
||
]);
|
||
};
|
||
|
||
// Load the initial snapshot once.
|
||
useEffect(() => {
|
||
if (!runtimeReady) {
|
||
setLastError(t.errors.tauri);
|
||
return;
|
||
}
|
||
let cancelled = false;
|
||
(async () => {
|
||
try {
|
||
const s = await invokeTauri("get_initial_state");
|
||
if (cancelled) return;
|
||
setConfig(s.config);
|
||
configRef.current = s.config;
|
||
setBootError(null);
|
||
setPorts({ proxyPort: s.config.proxyPort, pacPort: s.config.pacPort });
|
||
setEngineFound(s.engineFound);
|
||
setEngineVersion(s.engineVersion);
|
||
setLocalIp(s.localIp);
|
||
setIsAdmin(s.isAdmin);
|
||
setAppVersion(s.appVersion);
|
||
setAutostartEffective(s.autostartEffective);
|
||
setAutostartWarning(s.autostartError);
|
||
setStatus({
|
||
...EMPTY_STATUS,
|
||
isConnected: s.isConnected,
|
||
desiredConnected: s.desiredConnected,
|
||
connecting: s.connecting,
|
||
lastError: s.lastError,
|
||
});
|
||
prevConnected.current = s.isConnected;
|
||
|
||
pushLog("INFO", `LD FDPI ${s.appVersion} — ${s.engineVersion}`);
|
||
if (s.sentinelRecovered) {
|
||
pushLog("WARN", "Sentinel: önceki oturumdan kalan proxy ayarları geri yüklendi.");
|
||
}
|
||
if (!s.engineFound) pushLog("ERROR", t.errors.engine);
|
||
if (s.autostartError) pushLog("WARN", `Otomatik başlatma: ${s.autostartError}`);
|
||
if (s.isConnected) pushLog("SUCCESS", t.log.connected);
|
||
else if (s.desiredConnected) pushLog("INFO", t.log.auto);
|
||
} catch (error) {
|
||
if (!cancelled) {
|
||
setBootError(String(error));
|
||
setLastError(String(error));
|
||
pushLog("ERROR", String(error));
|
||
}
|
||
}
|
||
})();
|
||
return () => {
|
||
cancelled = true;
|
||
};
|
||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||
}, [runtimeReady]);
|
||
|
||
// Pause the status timer while the window is hidden in the tray or unfocused.
|
||
// The Rust supervisor keeps the tunnel alive independently.
|
||
useEffect(() => {
|
||
const update = () =>
|
||
setUiActive(
|
||
document.visibilityState !== "hidden" &&
|
||
(typeof document.hasFocus !== "function" || document.hasFocus())
|
||
);
|
||
update();
|
||
document.addEventListener("visibilitychange", update);
|
||
window.addEventListener("focus", update);
|
||
window.addEventListener("blur", update);
|
||
return () => {
|
||
document.removeEventListener("visibilitychange", update);
|
||
window.removeEventListener("focus", update);
|
||
window.removeEventListener("blur", update);
|
||
};
|
||
}, []);
|
||
|
||
// Cheap status polling; the Rust supervisor does the heavy health checks.
|
||
useEffect(() => {
|
||
if (!runtimeReady || !uiActive) return undefined;
|
||
let cancelled = false;
|
||
|
||
const tick = async () => {
|
||
try {
|
||
const s = await invokeTauri("get_status");
|
||
if (cancelled) return;
|
||
setStatus((prev) => ({ ...prev, ...s }));
|
||
if (s.isConnected && !prevConnected.current) pushLog("SUCCESS", t.log.connected);
|
||
if (!s.isConnected && prevConnected.current) pushLog("INFO", t.log.disconnected);
|
||
prevConnected.current = s.isConnected;
|
||
if (s.lastError) setLastError(s.lastError);
|
||
} catch {
|
||
/* Rust is busy or reloading; next tick will retry */
|
||
}
|
||
};
|
||
|
||
tick();
|
||
const timer = setInterval(tick, 2500);
|
||
return () => {
|
||
cancelled = true;
|
||
clearInterval(timer);
|
||
};
|
||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||
}, [runtimeReady, lang, uiActive]);
|
||
|
||
// First launch: if DNS is still on "auto", benchmark before the user connects
|
||
// and persist the fastest resolver. Settings can override it afterwards.
|
||
useEffect(() => {
|
||
if (!runtimeReady || !config || config.dohProvider !== "auto" || dohAutoRan.current) {
|
||
return undefined;
|
||
}
|
||
dohAutoRan.current = true;
|
||
let cancelled = false;
|
||
(async () => {
|
||
try {
|
||
const results = await invokeTauri("benchmark_doh_resolvers");
|
||
if (cancelled || !Array.isArray(results)) return;
|
||
setBenchmarks(results);
|
||
const best = results.find((item) => item.reachable);
|
||
if (best) {
|
||
await saveConfig({ dohProvider: best.id });
|
||
if (!cancelled) {
|
||
pushLog("INFO", `DNS otomatik seçildi: ${best.name} (${best.latencyMs} ms).`);
|
||
}
|
||
}
|
||
} catch {
|
||
/* Network may be captive; leave "auto" and retry next launch. */
|
||
}
|
||
})();
|
||
return () => {
|
||
cancelled = true;
|
||
};
|
||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||
}, [runtimeReady, config?.dohProvider]);
|
||
|
||
// VPN progress comes from the Rust zero-touch setup pipeline.
|
||
useEffect(() => {
|
||
let unlisten = null;
|
||
let cancelled = false;
|
||
listen("vpn-progress", (event) => {
|
||
if (!cancelled) setVpnProgress(String(event.payload || ""));
|
||
})
|
||
.then((fn) => {
|
||
if (cancelled) fn();
|
||
else unlisten = fn;
|
||
})
|
||
.catch(() => {});
|
||
return () => {
|
||
cancelled = true;
|
||
if (unlisten) unlisten();
|
||
};
|
||
}, []);
|
||
|
||
// VPN status is polled globally so DPI and VPN stay mutually exclusive.
|
||
useEffect(() => {
|
||
if (!runtimeReady) return undefined;
|
||
let cancelled = false;
|
||
const load = async () => {
|
||
try {
|
||
const snapshot = await invokeTauri("get_vpn_status");
|
||
if (!cancelled) setVpn(snapshot);
|
||
} catch {
|
||
/* client not installed or service unavailable */
|
||
}
|
||
};
|
||
load();
|
||
const timer = setInterval(load, 5000);
|
||
return () => {
|
||
cancelled = true;
|
||
clearInterval(timer);
|
||
};
|
||
}, [runtimeReady]);
|
||
|
||
// Eduroam SSID/MTU snapshot (only while the mode is selected and the UI is active).
|
||
useEffect(() => {
|
||
if (!runtimeReady || !uiActive || config?.connectionMode !== "eduroam") {
|
||
return undefined;
|
||
}
|
||
let cancelled = false;
|
||
const load = async () => {
|
||
try {
|
||
const snapshot = await invokeTauri("get_eduroam_status");
|
||
if (!cancelled) setEduroam(snapshot);
|
||
} catch {
|
||
/* Wi-Fi service may be off; UI keeps the last value */
|
||
}
|
||
};
|
||
load();
|
||
const timer = setInterval(load, 15000);
|
||
return () => {
|
||
cancelled = true;
|
||
clearInterval(timer);
|
||
};
|
||
}, [runtimeReady, uiActive, config?.connectionMode]);
|
||
|
||
useEffect(() => {
|
||
if (!runtimeReady) return undefined;
|
||
let cancelled = false;
|
||
checkTauriUpdate()
|
||
.then((update) => {
|
||
if (!cancelled && update) {
|
||
setUpdateInfo({
|
||
latest_version: update.version,
|
||
notes: update.body || "",
|
||
page_url: "https://ttmadethat.shop/ld-fdpi",
|
||
});
|
||
}
|
||
})
|
||
.catch(() => {});
|
||
return () => {
|
||
cancelled = true;
|
||
};
|
||
}, [runtimeReady]);
|
||
|
||
const handleInstallUpdate = async () => {
|
||
if (updateBusy) return;
|
||
setUpdateBusy(true);
|
||
setUpdateError(null);
|
||
try {
|
||
await invokeTauri("prepare_for_update");
|
||
const update = await checkTauriUpdate();
|
||
if (!update) {
|
||
setUpdateError(
|
||
lang === "tr"
|
||
? "Güncelleme bulunamadı. Sayfayı yenileyip tekrar deneyin."
|
||
: "No update found. Refresh and try again."
|
||
);
|
||
return;
|
||
}
|
||
await update.downloadAndInstall();
|
||
await invokeTauri("restart_app");
|
||
} catch (error) {
|
||
setUpdateError(
|
||
lang === "tr"
|
||
? "Güncelleme indirilemedi/doğrulanamadı. Lütfen tekrar deneyin."
|
||
: "Update could not be downloaded/verified. Please try again."
|
||
);
|
||
pushLog("ERROR", `Güncelleme: ${String(error)}`);
|
||
} finally {
|
||
setUpdateBusy(false);
|
||
}
|
||
};
|
||
|
||
useEffect(() => {
|
||
if (logsOpen && logEndRef.current) {
|
||
logEndRef.current.scrollIntoView({ behavior: "smooth", block: "end" });
|
||
}
|
||
}, [logs, logsOpen]);
|
||
|
||
const saveConfig = (patch, restartIfConnected = false) => {
|
||
const run = async () => {
|
||
const previous = configRef.current;
|
||
if (!previous) return { config: null, warning: "Ayarlar henüz yüklenmedi." };
|
||
const next = { ...previous, ...patch };
|
||
configRef.current = next;
|
||
setConfig(next);
|
||
if (patch.proxyPort || patch.pacPort) {
|
||
setPorts({
|
||
proxyPort: next.proxyPort,
|
||
pacPort: next.pacPort,
|
||
});
|
||
}
|
||
|
||
let res;
|
||
try {
|
||
res = await invokeTauri("save_config", { config: next });
|
||
configRef.current = res.config;
|
||
setConfig(res.config);
|
||
setAutostartEffective(res.autostartEffective);
|
||
setAutostartWarning(res.warning || null);
|
||
if (res.warning) pushLog("WARN", res.warning);
|
||
} catch (error) {
|
||
configRef.current = previous;
|
||
setConfig(previous);
|
||
setLastError(String(error));
|
||
pushLog("ERROR", String(error));
|
||
return { config: previous, autostartEffective, warning: String(error) };
|
||
}
|
||
|
||
// Persist succeeded; a restart failure must not roll the saved config back.
|
||
if (restartIfConnected && status.isConnected) {
|
||
try {
|
||
const restarted = await invokeTauri("soft_restart_engine", {
|
||
config: engineConfigFrom(res.config),
|
||
});
|
||
pushLog("SUCCESS", restarted.message || t.log.restart);
|
||
} catch (error) {
|
||
setLastError(String(error));
|
||
pushLog("ERROR", String(error));
|
||
}
|
||
}
|
||
return res;
|
||
};
|
||
|
||
const queued = saveQueue.current.then(run, run);
|
||
saveQueue.current = queued.catch(() => {});
|
||
return queued;
|
||
};
|
||
|
||
const handleConnect = async () => {
|
||
if (!config) return;
|
||
if (vpn?.connected) {
|
||
const message = "VPN açıkken DPI bağlantısı başlatılamaz. Önce VPN sekmesinden bağlantıyı kesin.";
|
||
setLastError(message);
|
||
pushLog("ERROR", message);
|
||
return;
|
||
}
|
||
setBusy("connect");
|
||
setLastError(null);
|
||
pushLog("INFO", t.log.connecting);
|
||
try {
|
||
let active = config;
|
||
if (config.autoOptimize !== false) {
|
||
pushLog("INFO", "Otomatik test: DNS ve bypass modları sınanıyor...");
|
||
try {
|
||
const [dohResults, bypassResult] = await Promise.all([
|
||
invokeTauri("benchmark_doh_resolvers"),
|
||
invokeTauri("auto_select_bypass"),
|
||
]);
|
||
if (Array.isArray(dohResults)) {
|
||
setBenchmarks(dohResults);
|
||
const bestDoh = dohResults.find((item) => item.reachable);
|
||
if (bestDoh) {
|
||
active = { ...active, dohProvider: bestDoh.id };
|
||
pushLog("INFO", `Otomatik DNS: ${bestDoh.name} (${bestDoh.latencyMs} ms).`);
|
||
}
|
||
}
|
||
if (bypassResult?.success) {
|
||
setAutoBypass(bypassResult);
|
||
active = { ...active, bypassMode: bypassResult.mode };
|
||
pushLog("INFO", `Otomatik bypass: ${bypassResult.name} (${bypassResult.latencyMs} ms).`);
|
||
}
|
||
if (active.dohProvider !== config.dohProvider || active.bypassMode !== config.bypassMode) {
|
||
await saveConfig({
|
||
dohProvider: active.dohProvider,
|
||
bypassMode: active.bypassMode,
|
||
});
|
||
}
|
||
} catch (error) {
|
||
pushLog("WARN", `Otomatik test atlandı: ${String(error)}`);
|
||
}
|
||
}
|
||
|
||
const res = await invokeTauri("start_connection", {
|
||
config: engineConfigFrom(active),
|
||
});
|
||
setStatus((prev) => ({
|
||
...prev,
|
||
isConnected: true,
|
||
desiredConnected: true,
|
||
connecting: false,
|
||
discordVerified: Boolean(res.discordVerified),
|
||
webVerified: Boolean(res.webVerified),
|
||
latencyMs: res.latencyMs || 0,
|
||
}));
|
||
pushLog("SUCCESS", res.message);
|
||
if (res.dohProvider) {
|
||
pushLog(
|
||
"INFO",
|
||
`DoH: ${res.dohProvider}${res.dohLatencyMs ? ` (${res.dohLatencyMs} ms)` : ""}`
|
||
);
|
||
}
|
||
if (res.warning) pushLog("WARN", res.warning);
|
||
prevConnected.current = true;
|
||
if (config.connectionMode === "eduroam") {
|
||
invokeTauri("get_eduroam_status").then(setEduroam).catch(() => {});
|
||
}
|
||
} catch (error) {
|
||
setLastError(String(error));
|
||
pushLog("ERROR", String(error));
|
||
setStatus((prev) => ({
|
||
...prev,
|
||
isConnected: false,
|
||
desiredConnected: false,
|
||
connecting: false,
|
||
}));
|
||
} finally {
|
||
setBusy(null);
|
||
}
|
||
};
|
||
|
||
const handleDisconnect = async () => {
|
||
setBusy("disconnect");
|
||
try {
|
||
const res = await invokeTauri("stop_connection");
|
||
setStatus((prev) => ({
|
||
...prev,
|
||
isConnected: false,
|
||
desiredConnected: false,
|
||
connecting: false,
|
||
discordVerified: false,
|
||
webVerified: false,
|
||
latencyMs: 0,
|
||
}));
|
||
prevConnected.current = false;
|
||
pushLog(res.externalProxyDetected ? "WARN" : "SUCCESS", res.message);
|
||
setLastError(null);
|
||
if (config?.connectionMode === "eduroam") {
|
||
invokeTauri("get_eduroam_status").then(setEduroam).catch(() => {});
|
||
}
|
||
} catch (error) {
|
||
setLastError(String(error));
|
||
pushLog("ERROR", String(error));
|
||
} finally {
|
||
setBusy(null);
|
||
}
|
||
};
|
||
|
||
const handleToggle = () => {
|
||
if (status.isConnected) handleDisconnect();
|
||
else handleConnect();
|
||
};
|
||
|
||
const handleLan = async (enabled) => {
|
||
if (!config) return;
|
||
setBusy("lan");
|
||
try {
|
||
const res = await invokeTauri("toggle_lan_sharing", {
|
||
enabled,
|
||
proxyPort: config.proxyPort,
|
||
pacPort: config.pacPort,
|
||
});
|
||
setConfig((prev) => ({ ...prev, lanSharing: enabled }));
|
||
setLanWarn(enabled && !res.firewallRuleUpdated);
|
||
pushLog(enabled ? "SUCCESS" : "INFO", res.message);
|
||
setLastError(null);
|
||
} catch (error) {
|
||
setLastError(String(error));
|
||
pushLog("ERROR", String(error));
|
||
} finally {
|
||
setBusy(null);
|
||
}
|
||
};
|
||
|
||
const handleFastestDoh = async () => {
|
||
setBenchmarking(true);
|
||
try {
|
||
const results = await invokeTauri("benchmark_doh_resolvers");
|
||
if (Array.isArray(results)) setBenchmarks(results);
|
||
const best = results?.find((r) => r.reachable);
|
||
if (!best) {
|
||
pushLog("WARN", "Hiçbir DoH uç noktasına ulaşılamadı.");
|
||
return;
|
||
}
|
||
await saveConfig({ dohProvider: best.id }, true);
|
||
pushLog("SUCCESS", `${t.log.fastest}: ${best.name} (${best.latencyMs} ms)`);
|
||
} catch (error) {
|
||
setLastError(String(error));
|
||
pushLog("ERROR", String(error));
|
||
} finally {
|
||
setBenchmarking(false);
|
||
}
|
||
};
|
||
|
||
const handleDiagnostics = async () => {
|
||
setDiagRunning(true);
|
||
try {
|
||
const items = await invokeTauri("run_diagnostics");
|
||
setDiagnostics(Array.isArray(items) ? items : []);
|
||
const ok = (items || []).filter((i) => i.passed).length;
|
||
pushLog("INFO", `Tanılama: ${ok}/${(items || []).length} kontrol başarılı.`);
|
||
} catch (error) {
|
||
setLastError(String(error));
|
||
pushLog("ERROR", String(error));
|
||
} finally {
|
||
setDiagRunning(false);
|
||
}
|
||
};
|
||
|
||
const refreshEduroam = async () => {
|
||
try {
|
||
const snapshot = await invokeTauri("get_eduroam_status");
|
||
setEduroam(snapshot);
|
||
return snapshot;
|
||
} catch {
|
||
return null;
|
||
}
|
||
};
|
||
|
||
const handleEduroamConnect = async () => {
|
||
setBusy("eduroam");
|
||
try {
|
||
const message = await invokeTauri("connect_eduroam_wifi");
|
||
pushLog("SUCCESS", message);
|
||
setLastError(null);
|
||
await refreshEduroam();
|
||
} catch (error) {
|
||
setLastError(String(error));
|
||
pushLog("ERROR", String(error));
|
||
} finally {
|
||
setBusy(null);
|
||
}
|
||
};
|
||
|
||
const handleGameToggle = async (enabled) => {
|
||
if (config?.connectionMode === "eduroam") return;
|
||
setBusy("mode");
|
||
try {
|
||
await saveConfig({ connectionMode: enabled ? "game" : "normal" }, true);
|
||
} finally {
|
||
setBusy(null);
|
||
}
|
||
};
|
||
|
||
const handleEduroamToggle = async (enabled) => {
|
||
setBusy("mode");
|
||
try {
|
||
if (enabled) {
|
||
await saveConfig(
|
||
{
|
||
connectionMode: "eduroam",
|
||
bypassMode: 1,
|
||
chunkSize: 4,
|
||
dohProvider: config?.dohProvider || "auto",
|
||
},
|
||
true
|
||
);
|
||
await refreshEduroam();
|
||
} else {
|
||
await saveConfig({ connectionMode: "normal" }, true);
|
||
setEduroam(null);
|
||
}
|
||
} finally {
|
||
setBusy(null);
|
||
}
|
||
};
|
||
|
||
const handleWifiSettings = async () => {
|
||
try {
|
||
await invokeTauri("open_wifi_settings");
|
||
} catch (error) {
|
||
setLastError(String(error));
|
||
pushLog("ERROR", String(error));
|
||
}
|
||
};
|
||
|
||
const handleEduroamDiagnostics = async () => {
|
||
setDiagRunning(true);
|
||
try {
|
||
const items = await invokeTauri("run_eduroam_diagnostics");
|
||
setDiagnostics(Array.isArray(items) ? items : []);
|
||
const ok = (items || []).filter((i) => i.passed).length;
|
||
pushLog("INFO", `Eduroam ağ testi: ${ok}/${(items || []).length} kontrol başarılı.`);
|
||
} catch (error) {
|
||
setLastError(String(error));
|
||
pushLog("ERROR", String(error));
|
||
} finally {
|
||
setDiagRunning(false);
|
||
}
|
||
};
|
||
|
||
const handleCaptiveConnect = async () => {
|
||
setBusy("captive");
|
||
setCaptive(null);
|
||
try {
|
||
const result = await invokeTauri("connect_without_login");
|
||
setCaptive(result);
|
||
const level = result.state === "online" ? "SUCCESS" : result.state === "portal" ? "WARN" : "ERROR";
|
||
pushLog(level, result.detail);
|
||
if (result.portalUrl) pushLog("INFO", `Portal: ${result.portalUrl}`);
|
||
setLastError(result.state === "blocked" || result.state === "eduroam" ? result.detail : null);
|
||
} catch (error) {
|
||
setLastError(String(error));
|
||
pushLog("ERROR", String(error));
|
||
} finally {
|
||
setBusy(null);
|
||
}
|
||
};
|
||
|
||
const handleAutoBypass = async () => {
|
||
setBusy("autoBypass");
|
||
setAutoBypass(null);
|
||
try {
|
||
const result = await invokeTauri("auto_select_bypass");
|
||
setAutoBypass(result);
|
||
if (result?.success) {
|
||
await saveConfig({ bypassMode: result.mode }, true);
|
||
pushLog("SUCCESS", `Otomatik bypass: ${result.name} (${result.latencyMs} ms).`);
|
||
} else {
|
||
pushLog("WARN", t.power.autoFail);
|
||
}
|
||
} catch (error) {
|
||
setLastError(String(error));
|
||
pushLog("ERROR", String(error));
|
||
} finally {
|
||
setBusy(null);
|
||
}
|
||
};
|
||
|
||
const handleVpnToggle = async () => {
|
||
if (!vpn?.connected && connected) {
|
||
const message = "DPI bağlantısı açıkken VPN başlatılamaz. Önce DPI bağlantısını kesin.";
|
||
setVpnError(message);
|
||
pushLog("ERROR", message);
|
||
return;
|
||
}
|
||
setVpnBusy(vpn?.connected ? "disconnect" : "connect");
|
||
setVpnError(null);
|
||
setVpnProgress(null);
|
||
try {
|
||
const snapshot = await invokeTauri(vpn?.connected ? "disconnect_vpn" : "connect_vpn");
|
||
setVpn(snapshot);
|
||
pushLog(snapshot.connected ? "SUCCESS" : "INFO", snapshot.detail);
|
||
} catch (error) {
|
||
setVpnError(String(error));
|
||
pushLog("ERROR", String(error));
|
||
} finally {
|
||
setVpnBusy(null);
|
||
setVpnProgress(null);
|
||
}
|
||
};
|
||
|
||
const handleDnsCheck = async () => {
|
||
setDnsChecking(true);
|
||
try {
|
||
const result = await invokeTauri("run_dns_check");
|
||
setDnsCheck(result);
|
||
pushLog(result.leakRisk ? "WARN" : "INFO", result.detail);
|
||
} catch (error) {
|
||
pushLog("ERROR", String(error));
|
||
} finally {
|
||
setDnsChecking(false);
|
||
}
|
||
};
|
||
|
||
const handleEmergencyRestore = async () => {
|
||
try {
|
||
const res = await invokeTauri("emergency_sentinel_restore");
|
||
setStatus((prev) => ({ ...prev, isConnected: false, desiredConnected: false }));
|
||
prevConnected.current = false;
|
||
pushLog(res.restored ? "SUCCESS" : "WARN", res.message);
|
||
setLastError(null);
|
||
} catch (error) {
|
||
setLastError(String(error));
|
||
pushLog("ERROR", String(error));
|
||
}
|
||
};
|
||
|
||
const savePorts = async () => {
|
||
const proxyPort = Math.max(1024, Math.min(65535, Number(ports.proxyPort) || 18080));
|
||
const pacPort = Math.max(1024, Math.min(65535, Number(ports.pacPort) || 18081));
|
||
if (proxyPort === pacPort) {
|
||
setLastError(lang === "tr" ? "Proxy ve PAC portu aynı olamaz." : "Proxy and PAC ports must differ.");
|
||
return;
|
||
}
|
||
await saveConfig({ proxyPort, pacPort }, false);
|
||
setPorts({ proxyPort, pacPort });
|
||
pushLog("INFO", t.log.configSaved);
|
||
};
|
||
|
||
const copyText = async (key, text) => {
|
||
try {
|
||
await navigator.clipboard.writeText(text);
|
||
} catch {
|
||
const area = document.createElement("textarea");
|
||
area.value = text;
|
||
document.body.appendChild(area);
|
||
area.select();
|
||
try {
|
||
document.execCommand("copy");
|
||
} finally {
|
||
document.body.removeChild(area);
|
||
}
|
||
}
|
||
setCopied(key);
|
||
setTimeout(() => setCopied(null), 1600);
|
||
};
|
||
|
||
const pacUrl = `http://${localIp}:${config?.pacPort ?? 18081}/proxy.pac`;
|
||
const manualProxy = `${localIp}:${config?.proxyPort ?? 18080}`;
|
||
|
||
const cliPreview = useMemo(
|
||
() => (config ? `spoofdpi.exe ${buildSpoofDpiArgs(config).join(" ")}` : ""),
|
||
[config]
|
||
);
|
||
|
||
const connected = status.isConnected;
|
||
const vpnConnected = Boolean(vpn?.connected);
|
||
const connecting = status.connecting || busy === "connect";
|
||
const autoWaiting = !connected && !connecting && status.desiredConnected;
|
||
|
||
const statusTitle = vpnConnected
|
||
? t.status.vpnConnected
|
||
: connected
|
||
? t.status.fdpiConnected
|
||
: connecting
|
||
? t.status.connecting
|
||
: autoWaiting
|
||
? t.status.autoConnecting
|
||
: t.status.disconnected;
|
||
|
||
const statusTone = vpnConnected || connected ? "green" : connecting || autoWaiting ? "amber" : "slate";
|
||
|
||
if (!config) {
|
||
return (
|
||
<div className="h-screen w-screen bg-fluent-bg text-slate-200 flex flex-col items-center justify-center gap-4">
|
||
<img
|
||
src="/logo.png"
|
||
alt="LD FDPI"
|
||
className="w-16 h-16 rounded-2xl shadow-lg shadow-blue-500/20"
|
||
/>
|
||
<div className="text-sm text-slate-400">
|
||
{runtimeReady ? "LD FDPI başlatılıyor..." : t.errors.tauri}
|
||
</div>
|
||
{bootError && (
|
||
<div className="max-w-[320px] text-center text-[11px] text-rose-300 space-y-2">
|
||
<p>{bootError}</p>
|
||
<button
|
||
onClick={() => window.location.reload()}
|
||
className="px-3 py-1.5 rounded-lg bg-slate-800 border border-slate-700 text-slate-200"
|
||
>
|
||
Yeniden Dene
|
||
</button>
|
||
</div>
|
||
)}
|
||
</div>
|
||
);
|
||
}
|
||
|
||
return (
|
||
<div className="flex h-screen w-screen flex-col bg-fluent-bg text-slate-100 overflow-hidden select-none">
|
||
{/* Main */}
|
||
<main className="flex-1 min-h-0 flex flex-col">
|
||
<header className="flex items-center justify-between gap-3 px-4 py-2.5 border-b border-fluent-border bg-fluent-surface/30 backdrop-blur-xl">
|
||
<div className="flex items-center gap-2 min-w-0">
|
||
<img src="/logo.png" alt="LD FDPI" className="w-8 h-8 rounded-lg shadow-lg shadow-cyan-500/20" />
|
||
<div className="min-w-0">
|
||
<h1 className="text-sm font-bold truncate">{t.nav[view]}</h1>
|
||
<p className="text-[10px] text-slate-400 truncate">
|
||
{vpnConnected
|
||
? vpn?.endpoint || "AmneziaWG"
|
||
: connected
|
||
? `${localIp}:${config.proxyPort}`
|
||
: "LD FDPI"}
|
||
</p>
|
||
</div>
|
||
</div>
|
||
<div className="flex items-center gap-2 shrink-0">
|
||
<span className="px-2 py-1 rounded-lg border border-slate-700/70 bg-slate-900/60 text-[10px] font-mono font-semibold text-slate-300">
|
||
v{appVersion}
|
||
</span>
|
||
{updateInfo && (
|
||
<button
|
||
onClick={handleInstallUpdate}
|
||
disabled={updateBusy}
|
||
title={updateInfo.notes || "Signed update"}
|
||
className="px-2.5 py-1 rounded-lg border border-cyan-400/40 bg-cyan-500/15 text-[10px] font-semibold text-cyan-100 hover:bg-cyan-500/25 disabled:opacity-50"
|
||
>
|
||
{updateBusy
|
||
? lang === "tr" ? "Güncelleniyor..." : "Updating..."
|
||
: `${lang === "tr" ? "Yeni Sürüm" : "New"} v${updateInfo.latest_version} · ${lang === "tr" ? "Güncelle" : "Update"}`}
|
||
</button>
|
||
)}
|
||
<div className="max-w-[130px]">
|
||
<Pill tone={statusTone}>
|
||
<span className="w-1.5 h-1.5 rounded-full bg-current shrink-0" />
|
||
<span className="truncate">{statusTitle}</span>
|
||
</Pill>
|
||
</div>
|
||
</div>
|
||
</header>
|
||
|
||
<div className="flex-1 overflow-y-auto p-4 space-y-4">
|
||
{!runtimeReady && (
|
||
<div className="rounded-xl border border-rose-500/40 bg-rose-500/10 p-3 text-xs text-rose-200">
|
||
{t.errors.tauri}
|
||
</div>
|
||
)}
|
||
{runtimeReady && !engineFound && (
|
||
<div className="rounded-xl border border-amber-500/40 bg-amber-500/10 p-3 text-xs text-amber-200">
|
||
{t.errors.engine}
|
||
</div>
|
||
)}
|
||
{lastError && (
|
||
<div className="rounded-xl border border-rose-500/40 bg-rose-500/10 p-3 text-xs text-rose-200 flex items-start justify-between gap-3">
|
||
<div className="whitespace-pre-wrap">{lastError}</div>
|
||
<button onClick={() => setLastError(null)} className="text-rose-300/80 hover:text-rose-200 shrink-0">
|
||
<X className="w-4 h-4" />
|
||
</button>
|
||
</div>
|
||
)}
|
||
{updateInfo && (
|
||
<div className="rounded-xl border border-cyan-400/40 bg-cyan-500/10 p-3 text-xs text-cyan-100 flex items-center justify-between gap-3">
|
||
<div>
|
||
<div className="font-semibold">
|
||
{lang === "tr"
|
||
? `Yeni sürüm (v${updateInfo.latest_version}) mevcut`
|
||
: `New version (v${updateInfo.latest_version}) available`}
|
||
</div>
|
||
<div className="text-cyan-200/70 mt-0.5">
|
||
{updateInfo.notes || (lang === "tr" ? "İmzalı güncelleme hazır." : "Signed update ready.")}
|
||
</div>
|
||
{updateError && <div className="text-rose-200 mt-1">{updateError}</div>}
|
||
</div>
|
||
<div className="flex shrink-0 gap-2">
|
||
<button
|
||
onClick={() => invokeTauri("open_download_page")}
|
||
className="px-3 py-1.5 rounded-lg bg-slate-900/60 border border-slate-600/60 text-slate-200 font-semibold hover:bg-slate-800"
|
||
>
|
||
{lang === "tr" ? "Sayfa" : "Page"}
|
||
</button>
|
||
<button
|
||
onClick={handleInstallUpdate}
|
||
disabled={updateBusy}
|
||
className="px-3 py-1.5 rounded-lg bg-cyan-500/20 border border-cyan-400/40 text-cyan-100 font-semibold hover:bg-cyan-500/30 disabled:opacity-50"
|
||
>
|
||
{updateBusy
|
||
? lang === "tr" ? "Güncelleniyor..." : "Updating..."
|
||
: lang === "tr" ? "Güncelle" : "Update"}
|
||
</button>
|
||
</div>
|
||
</div>
|
||
)}
|
||
|
||
{view === "home" && (
|
||
<div className="max-w-[430px] mx-auto w-full flex flex-col items-center gap-5 py-2">
|
||
<div className="text-center">
|
||
<div className="text-[10px] uppercase tracking-[0.3em] text-slate-500">LD FDPI</div>
|
||
<div className="text-xs text-slate-400 mt-1">
|
||
{config?.connectionMode === "eduroam"
|
||
? t.mode.eduroam
|
||
: config?.connectionMode === "game"
|
||
? t.mode.game
|
||
: t.mode.normal}
|
||
</div>
|
||
</div>
|
||
|
||
<div className="relative w-64 h-64 flex items-center justify-center my-1">
|
||
{connected && (
|
||
<span className="absolute h-52 w-52 rounded-full bg-emerald-500/15 animate-pulse-ring" />
|
||
)}
|
||
<button
|
||
onClick={handleToggle}
|
||
disabled={connecting || busy === "disconnect" || busy === "lan" || vpn?.connected}
|
||
className={`relative w-56 h-56 rounded-full border-2 flex flex-col items-center justify-center transition-all shadow-2xl disabled:opacity-60 ${
|
||
connected
|
||
? "border-emerald-400/70 bg-emerald-500/10 text-emerald-300 shadow-emerald-900/30"
|
||
: connecting || autoWaiting
|
||
? "border-amber-400/60 bg-amber-500/10 text-amber-300 shadow-amber-900/20"
|
||
: "border-cyan-300/40 bg-cyan-500/5 text-cyan-200 shadow-cyan-950/40 hover:border-cyan-200/70"
|
||
}`}
|
||
>
|
||
<span className="absolute inset-4 rounded-full border border-current/20" />
|
||
{connected ? (
|
||
<ShieldCheck className="w-12 h-12" />
|
||
) : connecting || autoWaiting ? (
|
||
<RefreshCw className="w-11 h-11 animate-spin" />
|
||
) : (
|
||
<Power className="w-12 h-12" />
|
||
)}
|
||
<span className={`relative mt-3 font-bold ${connected ? "text-[11px]" : "text-xl"}`}>
|
||
{connected
|
||
? t.actions.disconnect
|
||
: connecting
|
||
? t.status.connecting
|
||
: t.actions.connect}
|
||
</span>
|
||
</button>
|
||
</div>
|
||
<p className="text-[10px] text-slate-500 -mt-3 text-center max-w-[280px]">
|
||
{connected ? "Korunuyor" : t.hero.disconnectedSub}
|
||
</p>
|
||
|
||
<h2 className="text-2xl font-bold">{statusTitle}</h2>
|
||
<div className="flex flex-wrap items-center justify-center gap-2 -mt-2 min-h-[26px]">
|
||
{connected && status.latencyMs > 0 && (
|
||
<Pill tone="blue">
|
||
<Activity className="w-3 h-3" /> {status.latencyMs} ms
|
||
</Pill>
|
||
)}
|
||
{connected && status.discordVerified && <Pill tone="green">discord.com TLS</Pill>}
|
||
{connected && status.webVerified && <Pill tone="green">web TLS</Pill>}
|
||
{connected && <Pill tone="slate">{config.dohProvider?.toUpperCase() || "AUTO"} DoH</Pill>}
|
||
</div>
|
||
|
||
<section className="w-full mica-card rounded-2xl p-4">
|
||
<Toggle
|
||
checked={config?.connectionMode === "game"}
|
||
onChange={handleGameToggle}
|
||
disabled={config?.connectionMode === "eduroam" || busy === "mode" || vpn?.connected}
|
||
label={t.mode.game}
|
||
desc={t.mode.gameDesc}
|
||
/>
|
||
{vpn?.connected && (
|
||
<p className="text-[10px] text-amber-300/90 leading-relaxed pt-1">
|
||
VPN açık. DPI bağlantısı ve DPI ayarları kullanılamaz; önce VPN'i kesin.
|
||
</p>
|
||
)}
|
||
{config?.connectionMode === "eduroam" && (
|
||
<p className="text-[10px] text-amber-300/80 leading-relaxed">{t.mode.eduroamNote}</p>
|
||
)}
|
||
</section>
|
||
|
||
<div className="text-[10px] text-slate-500 text-center">
|
||
{config?.dohProvider?.toUpperCase()} DoH · {t.power.title}:{" "}
|
||
{config?.bypassMode === 0
|
||
? t.power.turbo
|
||
: config?.bypassMode === 2
|
||
? t.power.strong
|
||
: t.power.balanced}
|
||
</div>
|
||
</div>
|
||
)}
|
||
|
||
{view === "vpn" && (
|
||
<div className="max-w-[430px] mx-auto w-full flex flex-col items-center gap-4 py-2">
|
||
<div className="text-center">
|
||
<div className="text-[10px] uppercase tracking-[0.3em] text-slate-500">LD FDPI</div>
|
||
<div className="text-xs text-slate-400 mt-1">AmneziaWG · {vpn?.endpoint || "sunucu"}</div>
|
||
</div>
|
||
|
||
<div className="relative w-64 h-64 flex items-center justify-center my-1">
|
||
{vpn?.connected && (
|
||
<span className="absolute h-52 w-52 rounded-full bg-emerald-500/15 animate-pulse-ring" />
|
||
)}
|
||
<button
|
||
onClick={handleVpnToggle}
|
||
disabled={Boolean(vpnBusy) || connected}
|
||
className={`relative w-56 h-56 rounded-full border-2 flex flex-col items-center justify-center transition-all shadow-2xl disabled:opacity-60 ${
|
||
vpn?.connected
|
||
? "border-emerald-400/70 bg-emerald-500/10 text-emerald-300 shadow-emerald-900/30"
|
||
: "border-cyan-300/40 bg-cyan-500/5 text-cyan-200 shadow-cyan-950/40 hover:border-cyan-200/70"
|
||
}`}
|
||
>
|
||
<span className="absolute inset-4 rounded-full border border-current/20" />
|
||
<Shield className="w-12 h-12" />
|
||
<span className={`relative mt-3 font-bold ${vpn?.connected ? "text-[11px]" : "text-xl"}`}>
|
||
{vpnBusy === "connect"
|
||
? "HAZIRLANIYOR"
|
||
: vpnBusy
|
||
? t.captive.trying
|
||
: vpn?.connected
|
||
? t.vpn.disconnect
|
||
: t.vpn.connect}
|
||
</span>
|
||
</button>
|
||
</div>
|
||
|
||
<h2 className="text-2xl font-bold">
|
||
{vpn?.connected ? t.vpn.connected : t.vpn.disconnected}
|
||
</h2>
|
||
<p className="text-[11px] text-slate-400 text-center max-w-[300px]">
|
||
{connected
|
||
? "DPI bağlantısı açık. VPN kullanmak için önce DPI bağlantısını kesin."
|
||
: vpnError || vpnProgress || vpn?.detail || "BAĞLAN'a bas; gerisini uygulama halleder."}
|
||
</p>
|
||
|
||
<section className="w-full mica-card rounded-2xl p-4 space-y-2">
|
||
<div className="text-[10px] text-slate-500 uppercase tracking-wider">{t.vpn.server}</div>
|
||
<div className="text-sm font-mono text-slate-100 break-all">
|
||
{vpn?.endpoint || "116.202.14.171:42771"}
|
||
</div>
|
||
<div className="flex justify-between text-[11px] text-slate-400">
|
||
<span>{vpn?.address || "10.8.1.5/32"}</span>
|
||
<span>{vpn?.connected ? t.vpn.connected : t.vpn.disconnected}</span>
|
||
</div>
|
||
</section>
|
||
|
||
<button
|
||
onClick={handleDnsCheck}
|
||
disabled={dnsChecking}
|
||
className="w-full flex items-center justify-center gap-2 py-2 rounded-xl bg-slate-900/60 hover:bg-slate-800 border border-slate-700 text-[11px] font-semibold text-slate-300 disabled:opacity-60"
|
||
>
|
||
<Activity className={`w-3.5 h-3.5 ${dnsChecking ? "animate-spin" : ""}`} />
|
||
{dnsChecking ? "..." : "DNS Sızıntı Testi"}
|
||
</button>
|
||
{dnsCheck && (
|
||
<div className="w-full rounded-xl bg-slate-900/60 border border-slate-800 p-3 space-y-1 text-[10px] text-slate-400">
|
||
<div>DNS: {dnsCheck.servers?.join(", ") || "—"}</div>
|
||
<div>Çıkış IP: {dnsCheck.egressIp || "—"}</div>
|
||
<div className={dnsCheck.leakRisk ? "text-amber-300" : "text-emerald-300"}>
|
||
{dnsCheck.detail}
|
||
</div>
|
||
</div>
|
||
)}
|
||
|
||
<p className="text-[10px] text-slate-500 leading-relaxed px-1">{t.vpn.note}</p>
|
||
</div>
|
||
)}
|
||
|
||
{view === "settings" && (
|
||
<>
|
||
<div className="flex flex-col gap-3">
|
||
{vpn?.connected && (
|
||
<div className="rounded-xl border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-[11px] text-amber-200">
|
||
VPN açık. DPI ayarları kilitli; değiştirmek için önce VPN sekmesinden bağlantıyı kesin.
|
||
</div>
|
||
)}
|
||
<UpdatePanel appVersion={appVersion} lang={lang} />
|
||
<div className="order-1 px-1 text-[10px] font-semibold uppercase tracking-wider text-slate-500">
|
||
{lang === "tr" ? "Genel" : "General"}
|
||
</div>
|
||
<section className="order-3 mica-card rounded-2xl p-5">
|
||
<div className="flex items-center gap-2 text-sm font-semibold text-slate-200 mb-1">
|
||
<Power className="w-4 h-4 text-blue-400" />
|
||
{t.settings.startup}
|
||
</div>
|
||
<div className="divide-y divide-slate-800/70">
|
||
<Toggle
|
||
checked={Boolean(config.autoStart)}
|
||
onChange={async (value) => {
|
||
await saveConfig({ autoStart: value });
|
||
setAutostartNote(true);
|
||
pushLog(value ? "INFO" : "INFO", `${t.settings.autoStart}: ${value ? "ON" : "OFF"}`);
|
||
}}
|
||
label={t.settings.autoStart}
|
||
desc={t.settings.autoStartDesc}
|
||
/>
|
||
<Toggle
|
||
checked={Boolean(config.autoConnect)}
|
||
onChange={(value) => saveConfig({ autoConnect: value })}
|
||
label={t.settings.autoConnect}
|
||
desc={t.settings.autoConnectDesc}
|
||
/>
|
||
<Toggle
|
||
checked={Boolean(config.minimizeToTray)}
|
||
onChange={(value) => saveConfig({ minimizeToTray: value })}
|
||
label={t.settings.minimize}
|
||
desc={t.settings.minimizeDesc}
|
||
/>
|
||
</div>
|
||
{autostartWarning && (
|
||
<div className="mt-2 rounded-lg border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-[11px] text-amber-200">
|
||
{t.errors.autostart} {autostartWarning}
|
||
</div>
|
||
)}
|
||
{!isAdmin && (
|
||
<div className="mt-2 rounded-lg border border-slate-700 bg-slate-900/60 px-3 py-2 text-[11px] text-slate-400">
|
||
{t.settings.adminNote}
|
||
</div>
|
||
)}
|
||
{autostartNote && autostartEffective && (
|
||
<div className="mt-2 text-[11px] text-emerald-400">
|
||
{lang === "tr" ? "Görev Zamanlayıcı görevi aktif." : "Task Scheduler entry is active."}
|
||
</div>
|
||
)}
|
||
</section>
|
||
|
||
<section className="order-4 mica-card rounded-2xl p-5">
|
||
<div className="flex items-center justify-between">
|
||
<div className="flex items-center gap-2 text-sm font-semibold text-slate-200">
|
||
<Smartphone className="w-4 h-4 text-emerald-400" />
|
||
{t.settings.lan}
|
||
</div>
|
||
<Pill tone={config.lanSharing ? "green" : "slate"}>
|
||
{config.lanSharing ? t.settings.lanEnabled : t.settings.lanDisabled}
|
||
</Pill>
|
||
</div>
|
||
<div className="mt-1">
|
||
<Toggle
|
||
checked={Boolean(config.lanSharing)}
|
||
onChange={handleLan}
|
||
disabled={busy === "lan"}
|
||
label={t.settings.lan}
|
||
desc={t.settings.lanDesc}
|
||
/>
|
||
</div>
|
||
|
||
{config.lanSharing && (
|
||
<div className="grid grid-cols-1 lg:grid-cols-3 gap-3 mt-3">
|
||
<div className="rounded-xl bg-slate-900/60 border border-slate-800 p-3">
|
||
<div className="text-[11px] text-slate-400">{t.settings.manual}</div>
|
||
<div className="flex items-center justify-between gap-2 mt-1">
|
||
<code className="text-xs font-mono text-blue-300 truncate">{manualProxy}</code>
|
||
<button
|
||
onClick={() => copyText("manual", manualProxy)}
|
||
className="text-slate-400 hover:text-white"
|
||
>
|
||
{copied === "manual" ? (
|
||
<Check className="w-3.5 h-3.5 text-emerald-400" />
|
||
) : (
|
||
<Copy className="w-3.5 h-3.5" />
|
||
)}
|
||
</button>
|
||
</div>
|
||
</div>
|
||
<div className="rounded-xl bg-slate-900/60 border border-slate-800 p-3">
|
||
<div className="text-[11px] text-slate-400">{t.settings.pacUrl}</div>
|
||
<div className="flex items-center justify-between gap-2 mt-1">
|
||
<code className="text-xs font-mono text-cyan-300 truncate">{pacUrl}</code>
|
||
<button
|
||
onClick={() => copyText("pac", pacUrl)}
|
||
className="text-slate-400 hover:text-white"
|
||
>
|
||
{copied === "pac" ? (
|
||
<Check className="w-3.5 h-3.5 text-emerald-400" />
|
||
) : (
|
||
<Copy className="w-3.5 h-3.5" />
|
||
)}
|
||
</button>
|
||
</div>
|
||
</div>
|
||
<div className="rounded-xl bg-white p-2 flex items-center justify-center">
|
||
<QRCodeSVG value={pacUrl} size={86} level="M" />
|
||
</div>
|
||
</div>
|
||
)}
|
||
{lanWarn && (
|
||
<div className="mt-2 rounded-lg border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-[11px] text-amber-200">
|
||
{t.settings.firewallWarn}
|
||
</div>
|
||
)}
|
||
</section>
|
||
|
||
<section className="order-2 mica-card rounded-2xl p-5 flex items-center justify-between">
|
||
<div className="flex items-center gap-2 text-sm font-semibold text-slate-200">
|
||
<Languages className="w-4 h-4 text-cyan-400" />
|
||
{t.settings.language}
|
||
</div>
|
||
<div className="flex gap-2">
|
||
{["tr", "en"].map((code) => (
|
||
<button
|
||
key={code}
|
||
onClick={() => setLang(code)}
|
||
className={`px-4 py-1.5 rounded-lg text-xs font-semibold border ${
|
||
lang === code
|
||
? "bg-blue-600/20 border-blue-500/60 text-blue-200"
|
||
: "bg-slate-900/60 border-slate-800 text-slate-400"
|
||
}`}
|
||
>
|
||
{code.toUpperCase()}
|
||
</button>
|
||
))}
|
||
</div>
|
||
</section>
|
||
<div className="order-5 px-1 text-[10px] font-semibold uppercase tracking-wider text-slate-500">
|
||
{lang === "tr" ? "DPI / Bağlantı" : "DPI / Connection"}
|
||
</div>
|
||
<section className="order-6 mica-card rounded-2xl p-5">
|
||
<Toggle
|
||
checked={config.captiveAssistant !== false}
|
||
onChange={(value) => saveConfig({ captiveAssistant: value })}
|
||
label={t.captive.title}
|
||
desc={t.captive.enableDesc}
|
||
/>
|
||
</section>
|
||
{config.captiveAssistant !== false && (
|
||
<section className={`order-7 mica-card rounded-2xl p-5 space-y-3 border border-cyan-500/25 ${vpn?.connected ? "opacity-40 pointer-events-none" : ""}`}>
|
||
<div className="flex items-center gap-2 text-sm font-semibold text-slate-200">
|
||
<DoorOpen className="w-4 h-4 text-cyan-300" />
|
||
{t.captive.title}
|
||
</div>
|
||
<p className="text-[11px] text-slate-400 leading-relaxed">{t.captive.desc}</p>
|
||
<button
|
||
onClick={handleCaptiveConnect}
|
||
disabled={busy === "captive"}
|
||
className="w-full flex items-center justify-center gap-2 py-3 rounded-xl bg-cyan-500/10 hover:bg-cyan-500/20 border border-cyan-500/40 text-sm font-semibold text-cyan-200 disabled:opacity-60 transition-colors"
|
||
>
|
||
<DoorOpen className={`w-4 h-4 ${busy === "captive" ? "animate-pulse" : ""}`} />
|
||
{busy === "captive" ? t.captive.trying : t.captive.connect}
|
||
</button>
|
||
{captive && (
|
||
<div className="rounded-xl bg-slate-900/60 border border-slate-800 p-3 space-y-1.5" aria-live="polite">
|
||
<Pill
|
||
tone={
|
||
captive.state === "online"
|
||
? "green"
|
||
: captive.state === "portal"
|
||
? "amber"
|
||
: "red"
|
||
}
|
||
>
|
||
{captive.state === "online"
|
||
? t.captive.online
|
||
: captive.state === "portal"
|
||
? t.captive.portal
|
||
: captive.state === "eduroam"
|
||
? t.captive.eduroam
|
||
: t.captive.blocked}
|
||
</Pill>
|
||
<p className="text-[11px] text-slate-300 leading-relaxed">{captive.detail}</p>
|
||
{captive.portalUrl && (
|
||
<p className="text-[10px] font-mono text-cyan-300 break-all">{captive.portalUrl}</p>
|
||
)}
|
||
</div>
|
||
)}
|
||
<p className="text-[10px] text-slate-500 leading-relaxed">{t.captive.note}</p>
|
||
</section>
|
||
)}
|
||
<section className={`order-8 mica-card rounded-2xl p-5 ${vpn?.connected ? "opacity-40 pointer-events-none" : ""}`}>
|
||
<div className="flex items-center gap-2 text-sm font-semibold text-slate-200 mb-1">
|
||
<GraduationCap className="w-4 h-4 text-emerald-400" />
|
||
{t.mode.eduroam}
|
||
</div>
|
||
<Toggle
|
||
checked={config.connectionMode === "eduroam"}
|
||
onChange={handleEduroamToggle}
|
||
label={t.mode.eduroam}
|
||
desc={t.mode.eduroamDesc}
|
||
/>
|
||
<p className="text-[10px] text-slate-500 leading-relaxed">{t.mode.eduroamNote}</p>
|
||
</section>
|
||
{config.connectionMode === "eduroam" && (
|
||
<section className={`order-9 mica-card rounded-2xl p-5 space-y-3 border border-emerald-500/25 ${vpn?.connected ? "opacity-40 pointer-events-none" : ""}`}>
|
||
<div className="flex items-center gap-2">
|
||
<GraduationCap className="w-4 h-4 text-emerald-400" />
|
||
<span className="text-sm font-semibold text-slate-100">
|
||
{t.eduroam.title}
|
||
</span>
|
||
<span
|
||
className={`ml-auto text-[10px] px-2 py-0.5 rounded-full border ${
|
||
eduroam?.wifi?.isEduroam
|
||
? "bg-emerald-500/10 border-emerald-500/40 text-emerald-300"
|
||
: "bg-amber-500/10 border-amber-500/40 text-amber-300"
|
||
}`}
|
||
>
|
||
{eduroam?.wifi?.isEduroam
|
||
? t.eduroam.connected
|
||
: eduroam?.wifi?.available
|
||
? t.eduroam.notConnected
|
||
: t.eduroam.noWifi}
|
||
</span>
|
||
</div>
|
||
|
||
<div className="grid grid-cols-2 sm:grid-cols-4 gap-2 text-[10px]">
|
||
<div className="rounded-lg bg-slate-900/60 border border-slate-800 px-2 py-1.5">
|
||
<div className="text-slate-500">SSID</div>
|
||
<div className="text-slate-200 truncate">{eduroam?.wifi?.ssid || "—"}</div>
|
||
</div>
|
||
<div className="rounded-lg bg-slate-900/60 border border-slate-800 px-2 py-1.5">
|
||
<div className="text-slate-500">{t.eduroam.auth}</div>
|
||
<div className="text-slate-200 truncate">
|
||
{eduroam?.wifi?.authentication || "—"}
|
||
</div>
|
||
</div>
|
||
<div className="rounded-lg bg-slate-900/60 border border-slate-800 px-2 py-1.5">
|
||
<div className="text-slate-500">{t.eduroam.mtu}</div>
|
||
<div className="text-slate-200">
|
||
{eduroam?.mtu ?? "—"} / {eduroam?.targetMtu ?? 1400}
|
||
</div>
|
||
</div>
|
||
<div className="rounded-lg bg-slate-900/60 border border-slate-800 px-2 py-1.5">
|
||
<div className="text-slate-500">Wi-Fi</div>
|
||
<div className="text-slate-200 truncate">
|
||
{eduroam?.wifi?.interface || "—"}
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div className="flex flex-wrap gap-2">
|
||
<button
|
||
onClick={handleEduroamConnect}
|
||
disabled={busy === "eduroam"}
|
||
className="flex-1 min-w-[140px] flex items-center justify-center gap-2 py-2 rounded-xl bg-emerald-600/20 hover:bg-emerald-600/30 border border-emerald-500/40 text-xs font-semibold text-emerald-200 disabled:opacity-60"
|
||
>
|
||
<Wifi className="w-3.5 h-3.5" />
|
||
{busy === "eduroam" ? "..." : t.eduroam.connect}
|
||
</button>
|
||
<button
|
||
onClick={handleWifiSettings}
|
||
className="flex-1 min-w-[120px] flex items-center justify-center gap-2 py-2 rounded-xl bg-slate-800 hover:bg-slate-700 border border-slate-700 text-xs font-semibold text-slate-200"
|
||
>
|
||
<Settings className="w-3.5 h-3.5" />
|
||
{t.eduroam.wifiSettings}
|
||
</button>
|
||
<button
|
||
onClick={handleEduroamDiagnostics}
|
||
disabled={diagRunning}
|
||
className="flex-1 min-w-[110px] flex items-center justify-center gap-2 py-2 rounded-xl bg-slate-800 hover:bg-slate-700 border border-slate-700 text-xs font-semibold text-cyan-300 disabled:opacity-60"
|
||
>
|
||
<Activity className="w-3.5 h-3.5" />
|
||
{diagRunning ? "..." : t.eduroam.diagnostics}
|
||
</button>
|
||
</div>
|
||
|
||
<p className="text-[10px] text-slate-500 leading-relaxed">
|
||
{t.eduroam.profileHint}
|
||
</p>
|
||
<p className="text-[10px] text-amber-300/80 leading-relaxed flex gap-1.5">
|
||
<AlertTriangle className="w-3.5 h-3.5 shrink-0 mt-0.5" />
|
||
{t.eduroam.voiceWarning}
|
||
</p>
|
||
|
||
{(diagnostics || []).filter((item) => item.id?.startsWith("eduroam")).length >
|
||
0 && (
|
||
<div className="space-y-1 pt-1">
|
||
{(diagnostics || [])
|
||
.filter((item) => item.id?.startsWith("eduroam"))
|
||
.map((item) => (
|
||
<div
|
||
key={item.id}
|
||
className="flex items-start gap-2 text-[10px] leading-relaxed"
|
||
>
|
||
{item.passed ? (
|
||
<CheckCircle2 className="w-3.5 h-3.5 text-emerald-400 shrink-0 mt-0.5" />
|
||
) : (
|
||
<XCircle className="w-3.5 h-3.5 text-amber-400 shrink-0 mt-0.5" />
|
||
)}
|
||
<span className="text-slate-400">
|
||
<b className="text-slate-300">{item.name}:</b> {item.detail}
|
||
</span>
|
||
</div>
|
||
))}
|
||
</div>
|
||
)}
|
||
</section>
|
||
)}
|
||
{/* Bypass strength */}
|
||
<section className={`order-10 mica-card rounded-2xl p-5 space-y-3 ${vpn?.connected ? "opacity-40 pointer-events-none" : ""}`}>
|
||
<div className="flex items-center gap-2 text-sm font-semibold text-slate-200">
|
||
<Gauge className="w-4 h-4 text-cyan-400" />
|
||
{t.power.title}
|
||
</div>
|
||
<button
|
||
onClick={handleAutoBypass}
|
||
disabled={busy === "autoBypass"}
|
||
className="w-full text-left px-3 py-2.5 rounded-xl border border-cyan-500/40 bg-cyan-500/10 hover:bg-cyan-500/20 transition-colors disabled:opacity-60"
|
||
>
|
||
<div className="flex items-center gap-2">
|
||
<Sparkles className={`w-4 h-4 text-cyan-300 ${busy === "autoBypass" ? "animate-spin" : ""}`} />
|
||
<div className="text-sm font-semibold text-slate-100">
|
||
{busy === "autoBypass" ? t.captive.trying : t.power.auto}
|
||
</div>
|
||
</div>
|
||
<div className="text-[10px] text-slate-400 mt-0.5 pl-6">{t.power.autoDesc}</div>
|
||
</button>
|
||
{autoBypass && (
|
||
<div className="rounded-xl bg-slate-900/60 border border-slate-800 p-3 space-y-1" aria-live="polite">
|
||
<Pill tone={autoBypass.success ? "green" : "amber"}>
|
||
{autoBypass.success
|
||
? `${t.power.autoSelected}: ${autoBypass.name} · ${autoBypass.latencyMs} ms`
|
||
: t.power.autoFail}
|
||
</Pill>
|
||
{autoBypass.tested?.length > 0 && (
|
||
<p className="text-[10px] text-slate-500 leading-relaxed">
|
||
{autoBypass.tested
|
||
.map((item) => `${item.name}: ${item.reachable ? `${item.latencyMs} ms` : "—"}`)
|
||
.join(" · ")}
|
||
</p>
|
||
)}
|
||
</div>
|
||
)}
|
||
<div className="border-t border-slate-800 pt-1">
|
||
<Toggle
|
||
checked={config.autoOptimize !== false}
|
||
onChange={(value) => saveConfig({ autoOptimize: value })}
|
||
label={t.power.autoOptimize}
|
||
desc={t.power.autoOptimizeDesc}
|
||
/>
|
||
<Toggle
|
||
checked={Boolean(config.quicBlock)}
|
||
onChange={(value) => saveConfig({ quicBlock: value }, true)}
|
||
label={t.power.quicBlock}
|
||
desc={t.power.quicBlockDesc}
|
||
/>
|
||
</div>
|
||
<div className="space-y-2">
|
||
{[
|
||
{ mode: 0, label: t.power.turbo, desc: t.power.turboDesc },
|
||
{ mode: 1, label: t.power.balanced, desc: t.power.balancedDesc },
|
||
{ mode: 2, label: t.power.strong, desc: t.power.strongDesc },
|
||
].map(({ mode, label, desc }) => {
|
||
const active = config.bypassMode === mode;
|
||
return (
|
||
<button
|
||
key={mode}
|
||
onClick={() => saveConfig({ bypassMode: mode }, true)}
|
||
className={`w-full text-left px-3 py-2.5 rounded-xl border transition-all flex items-center justify-between gap-2 ${
|
||
active
|
||
? "bg-cyan-500/10 border-cyan-500/50"
|
||
: "bg-slate-900/50 border-slate-800 hover:border-slate-700"
|
||
}`}
|
||
>
|
||
<div>
|
||
<div className="text-sm font-semibold text-slate-100">{label}</div>
|
||
<div className="text-[10px] text-slate-400 mt-0.5">{desc}</div>
|
||
</div>
|
||
<span
|
||
className={`w-2 h-2 rounded-full shrink-0 ${
|
||
active ? "bg-cyan-400" : "bg-slate-600"
|
||
}`}
|
||
/>
|
||
</button>
|
||
);
|
||
})}
|
||
</div>
|
||
{config.bypassMode === 1 && (
|
||
<div className="flex items-center gap-2 pt-1">
|
||
{[4, 8, 16].map((size) => (
|
||
<button
|
||
key={size}
|
||
onClick={() => saveConfig({ chunkSize: size }, true)}
|
||
className={`flex-1 py-1.5 rounded-lg text-[11px] font-mono border transition ${
|
||
config.chunkSize === size
|
||
? "bg-blue-600/20 border-blue-500/60 text-blue-200"
|
||
: "bg-slate-900/60 border-slate-800 text-slate-400 hover:text-slate-200"
|
||
}`}
|
||
>
|
||
{size} B
|
||
</button>
|
||
))}
|
||
</div>
|
||
)}
|
||
</section>
|
||
|
||
{/* DNS */}
|
||
<div className="order-11 px-1 text-[10px] font-semibold uppercase tracking-wider text-slate-500">
|
||
DNS
|
||
</div>
|
||
<section className={`order-12 mica-card rounded-2xl p-5 space-y-3 ${vpn?.connected ? "opacity-40 pointer-events-none" : ""}`}>
|
||
<div className="flex items-center gap-2 text-sm font-semibold text-slate-200">
|
||
<Wifi className="w-4 h-4 text-emerald-400" />
|
||
{t.dns.title}
|
||
</div>
|
||
<p className="text-[11px] text-slate-400">{t.dns.subtitle}</p>
|
||
<select
|
||
value={config.dohProvider}
|
||
onChange={(e) => saveConfig({ dohProvider: e.target.value }, true)}
|
||
className="w-full rounded-xl bg-slate-900 border border-slate-700 px-3 py-2.5 text-sm text-slate-100 focus:outline-none focus:border-blue-500"
|
||
>
|
||
<option value="auto">{t.dns.auto}</option>
|
||
<option value="cloudflare">Cloudflare · 1.1.1.1</option>
|
||
<option value="google">Google · 8.8.8.8</option>
|
||
<option value="adguard">AdGuard · 94.140.14.14</option>
|
||
</select>
|
||
<button
|
||
onClick={handleFastestDoh}
|
||
disabled={benchmarking}
|
||
className="w-full flex items-center justify-center gap-2 py-2 rounded-xl bg-slate-800 hover:bg-slate-700 border border-slate-700 text-xs font-semibold text-cyan-300 disabled:opacity-60"
|
||
>
|
||
<Sparkles className={`w-3.5 h-3.5 ${benchmarking ? "animate-spin" : ""}`} />
|
||
{benchmarking ? "..." : t.actions.fastest}
|
||
</button>
|
||
{benchmarks?.length > 0 && (
|
||
<div className="rounded-xl bg-slate-900/60 border border-slate-800 p-2.5 space-y-1.5">
|
||
<div className="text-[10px] text-cyan-300 font-semibold">
|
||
{t.dns.autoPicked}: {benchmarks[0].name}
|
||
{benchmarks[0].reachable ? ` · ${benchmarks[0].latencyMs} ms` : ""}
|
||
</div>
|
||
<div className="grid grid-cols-3 gap-1 text-[10px] font-mono text-slate-400">
|
||
{benchmarks.slice(0, 3).map((item) => (
|
||
<div key={item.id} className="truncate">
|
||
{item.id}: {item.reachable ? `${item.latencyMs} ms` : "—"}
|
||
</div>
|
||
))}
|
||
</div>
|
||
</div>
|
||
)}
|
||
<div className="text-[10px] text-slate-500 font-mono truncate">
|
||
{config.dohProvider === "auto"
|
||
? t.dns.autoHint
|
||
: config.dohProvider === "cloudflare"
|
||
? "https://1.1.1.1/dns-query"
|
||
: config.dohProvider === "google"
|
||
? "https://8.8.8.8/dns-query"
|
||
: "https://94.140.14.14/dns-query"}
|
||
</div>
|
||
</section>
|
||
|
||
{/* Advanced (collapsed) */}
|
||
<div className="order-[13] px-1 text-[10px] font-semibold uppercase tracking-wider text-slate-500">
|
||
{lang === "tr" ? "Gelişmiş" : "Advanced"}
|
||
</div>
|
||
<details className={`order-[14] mica-card rounded-2xl overflow-hidden group ${vpn?.connected ? "opacity-40 pointer-events-none" : ""}`}>
|
||
<summary className="cursor-pointer list-none px-5 py-3.5 flex items-center justify-between text-sm font-semibold text-slate-300">
|
||
<span className="flex items-center gap-2">
|
||
<Settings className="w-4 h-4 text-slate-400" />
|
||
{t.advanced.title}
|
||
</span>
|
||
<ChevronDown className="w-4 h-4 text-slate-400 transition-transform group-open:rotate-180" />
|
||
</summary>
|
||
<div className="border-t border-fluent-border px-5 py-4 space-y-5">
|
||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||
<div>
|
||
<div className="text-xs font-semibold text-slate-300 mb-2">{t.advanced.ports}</div>
|
||
<div className="flex items-end gap-2">
|
||
<label className="flex-1 text-[11px] text-slate-400">
|
||
{t.advanced.proxyPort}
|
||
<input
|
||
type="number"
|
||
value={ports.proxyPort}
|
||
onChange={(e) => setPorts((p) => ({ ...p, proxyPort: e.target.value }))}
|
||
className="mt-1 w-full rounded-lg bg-slate-900 border border-slate-700 px-2.5 py-1.5 text-xs font-mono text-slate-100"
|
||
/>
|
||
</label>
|
||
<label className="flex-1 text-[11px] text-slate-400">
|
||
{t.advanced.pacPort}
|
||
<input
|
||
type="number"
|
||
value={ports.pacPort}
|
||
onChange={(e) => setPorts((p) => ({ ...p, pacPort: e.target.value }))}
|
||
className="mt-1 w-full rounded-lg bg-slate-900 border border-slate-700 px-2.5 py-1.5 text-xs font-mono text-slate-100"
|
||
/>
|
||
</label>
|
||
<button
|
||
onClick={savePorts}
|
||
className="px-3 py-1.5 rounded-lg bg-blue-600 hover:bg-blue-500 text-xs font-semibold"
|
||
>
|
||
{t.actions.save}
|
||
</button>
|
||
</div>
|
||
<div className="text-[10px] text-slate-500 mt-1.5">{t.advanced.portsHint}</div>
|
||
</div>
|
||
|
||
<div>
|
||
<div className="text-xs font-semibold text-slate-300 mb-2">{t.advanced.cli}</div>
|
||
<code className="block text-[10px] font-mono text-slate-400 bg-slate-950/70 border border-slate-800 rounded-lg p-2 break-all leading-relaxed">
|
||
{cliPreview}
|
||
</code>
|
||
</div>
|
||
</div>
|
||
|
||
<div className="flex flex-wrap items-center gap-2">
|
||
<button
|
||
onClick={handleDiagnostics}
|
||
disabled={diagRunning}
|
||
className="flex items-center gap-2 px-3 py-2 rounded-xl bg-slate-800 hover:bg-slate-700 border border-slate-700 text-xs font-semibold text-slate-200 disabled:opacity-60"
|
||
>
|
||
<Activity className={`w-3.5 h-3.5 text-cyan-400 ${diagRunning ? "animate-spin" : ""}`} />
|
||
{t.advanced.diagnostics}
|
||
</button>
|
||
<button
|
||
onClick={handleEmergencyRestore}
|
||
className="flex items-center gap-2 px-3 py-2 rounded-xl bg-amber-500/10 hover:bg-amber-500/20 border border-amber-500/30 text-xs font-semibold text-amber-300"
|
||
>
|
||
<RotateCcw className="w-3.5 h-3.5" />
|
||
{t.actions.restore}
|
||
</button>
|
||
<button
|
||
onClick={handleConnect}
|
||
className="flex items-center gap-2 px-3 py-2 rounded-xl bg-slate-800 hover:bg-slate-700 border border-slate-700 text-xs font-semibold text-slate-200"
|
||
>
|
||
<Activity className="w-3.5 h-3.5 text-emerald-400" />
|
||
{t.actions.test}
|
||
</button>
|
||
</div>
|
||
|
||
<div className="text-[10px] text-slate-500 leading-relaxed">
|
||
{t.advanced.diagnosticsDesc} {t.advanced.emergencyDesc}
|
||
</div>
|
||
|
||
{diagnostics && (
|
||
<div className="grid grid-cols-1 md:grid-cols-2 gap-1.5">
|
||
{diagnostics.map((item) => (
|
||
<div
|
||
key={item.id}
|
||
className="flex items-start gap-2 px-2.5 py-2 rounded-lg bg-slate-900/60 border border-slate-800"
|
||
>
|
||
{item.passed ? (
|
||
<CheckCircle2 className="w-3.5 h-3.5 text-emerald-400 mt-0.5 shrink-0" />
|
||
) : (
|
||
<XCircle className="w-3.5 h-3.5 text-rose-400 mt-0.5 shrink-0" />
|
||
)}
|
||
<div className="min-w-0">
|
||
<div className="text-[11px] font-medium text-slate-200">{item.name}</div>
|
||
<div className="text-[10px] text-slate-500 font-mono break-all">{item.detail}</div>
|
||
</div>
|
||
</div>
|
||
))}
|
||
</div>
|
||
)}
|
||
</div>
|
||
</details>
|
||
</div>
|
||
</>
|
||
)}
|
||
|
||
{view === "about" && (
|
||
<section className="mica-card rounded-2xl p-6 space-y-4 max-w-2xl">
|
||
<div className="flex items-center gap-3">
|
||
<img
|
||
src="/logo.png"
|
||
alt="LD FDPI"
|
||
className="w-12 h-12 rounded-2xl"
|
||
/>
|
||
<div>
|
||
<h2 className="text-lg font-bold">{t.about.title}</h2>
|
||
<p className="text-[11px] text-slate-400">{t.about.desc}</p>
|
||
</div>
|
||
</div>
|
||
<div className="grid grid-cols-2 gap-3 text-xs">
|
||
<div className="rounded-xl bg-slate-900/60 border border-slate-800 p-3">
|
||
<div className="text-slate-400">{t.about.engine}</div>
|
||
<div className="font-mono text-slate-200 mt-0.5">{engineVersion}</div>
|
||
</div>
|
||
<div className="rounded-xl bg-slate-900/60 border border-slate-800 p-3">
|
||
<div className="text-slate-400">{t.about.version}</div>
|
||
<div className="font-mono text-slate-200 mt-0.5">v{appVersion}</div>
|
||
</div>
|
||
<div className="rounded-xl bg-slate-900/60 border border-slate-800 p-3">
|
||
<div className="text-slate-400">{t.about.admin}</div>
|
||
<div className="text-slate-200 mt-0.5">
|
||
{isAdmin ? t.about.adminYes : t.about.adminNo}
|
||
</div>
|
||
</div>
|
||
<div className="rounded-xl bg-slate-900/60 border border-slate-800 p-3">
|
||
<div className="text-slate-400">Auto-start</div>
|
||
<div className="text-slate-200 mt-0.5">
|
||
{autostartEffective ? "Task Scheduler · Highest" : "—"}
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<p className="text-[11px] text-slate-400 leading-relaxed">{t.about.privacy}</p>
|
||
<p className="text-[10px] text-slate-500 font-mono break-all">
|
||
%LOCALAPPDATA%\LD-FDPI\config.json
|
||
</p>
|
||
</section>
|
||
)}
|
||
</div>
|
||
|
||
{/* Bottom navigation */}
|
||
<nav className="shrink-0 border-t border-fluent-border bg-fluent-surface/90 backdrop-blur-xl px-2 py-1.5">
|
||
<div className="grid grid-cols-5 gap-1">
|
||
{[
|
||
{ id: "home", label: t.nav.home, icon: Zap },
|
||
{ id: "vpn", label: t.nav.vpn, icon: Shield },
|
||
{ id: "settings", label: t.nav.settings, icon: Settings },
|
||
{ id: "about", label: t.nav.about, icon: Info },
|
||
].map(({ id, label, icon: Icon }) => {
|
||
const active = view === id && !logsOpen;
|
||
return (
|
||
<button
|
||
key={id}
|
||
onClick={() => {
|
||
setView(id);
|
||
setLogsOpen(false);
|
||
}}
|
||
className={`flex flex-col items-center gap-0.5 py-1.5 rounded-xl text-[10px] transition-colors ${
|
||
active ? "text-cyan-300 bg-cyan-500/10" : "text-slate-400 hover:text-slate-200"
|
||
}`}
|
||
>
|
||
<Icon className="w-5 h-5" />
|
||
{label}
|
||
</button>
|
||
);
|
||
})}
|
||
<button
|
||
onClick={() => setLogsOpen((value) => !value)}
|
||
className={`flex flex-col items-center gap-0.5 py-1.5 rounded-xl text-[10px] transition-colors ${
|
||
logsOpen ? "text-cyan-300 bg-cyan-500/10" : "text-slate-400 hover:text-slate-200"
|
||
}`}
|
||
>
|
||
<Terminal className="w-5 h-5" />
|
||
{t.actions.logs}
|
||
</button>
|
||
</div>
|
||
</nav>
|
||
|
||
{/* Logs drawer */}
|
||
{logsOpen && (
|
||
<div className="fixed left-0 right-0 bottom-0 h-[46vh] bg-fluent-surface/95 backdrop-blur-xl border-t border-fluent-border shadow-2xl z-40 flex flex-col">
|
||
<div className="flex items-center justify-between px-4 py-2.5 border-b border-slate-800">
|
||
<div className="flex items-center gap-2 text-xs font-semibold text-slate-200">
|
||
<Terminal className="w-4 h-4 text-blue-400" />
|
||
{t.logs.title}
|
||
<span className="text-[10px] text-slate-500">
|
||
{logs.length} {t.logs.count}
|
||
</span>
|
||
</div>
|
||
<div className="flex items-center gap-1.5">
|
||
<button
|
||
onClick={() => setLogs([])}
|
||
className="flex items-center gap-1 px-2 py-1 rounded-lg bg-slate-800 hover:bg-slate-700 text-[11px] text-slate-300"
|
||
>
|
||
<Trash2 className="w-3 h-3" /> {t.actions.clear}
|
||
</button>
|
||
<button
|
||
onClick={() => setLogsOpen(false)}
|
||
className="p-1.5 rounded-lg bg-slate-800 hover:bg-slate-700 text-slate-300"
|
||
>
|
||
<X className="w-3.5 h-3.5" />
|
||
</button>
|
||
</div>
|
||
</div>
|
||
<div className="flex-1 overflow-y-auto px-4 py-2 font-mono text-[11px] space-y-1">
|
||
{logs.length === 0 && <div className="text-slate-500 py-4">{t.logs.empty}</div>}
|
||
{logs.map((item) => (
|
||
<div key={item.id} className="leading-relaxed">
|
||
<span className="text-slate-600">[{item.time}]</span>{" "}
|
||
<span
|
||
className={
|
||
item.level === "SUCCESS"
|
||
? "text-emerald-400"
|
||
: item.level === "WARN"
|
||
? "text-amber-400"
|
||
: item.level === "ERROR"
|
||
? "text-rose-400"
|
||
: "text-blue-300"
|
||
}
|
||
>
|
||
[{item.level}]
|
||
</span>{" "}
|
||
<span className="text-slate-300">{item.text}</span>
|
||
</div>
|
||
))}
|
||
<div ref={logEndRef} />
|
||
</div>
|
||
</div>
|
||
)}
|
||
</main>
|
||
</div>
|
||
);
|
||
}
|