312 lines
9.4 KiB
JavaScript
312 lines
9.4 KiB
JavaScript
import { useCallback, useEffect, useMemo, useState } from "react";
|
||
import { invoke } from "@tauri-apps/api/core";
|
||
import {
|
||
AlertTriangle,
|
||
CheckCircle2,
|
||
FolderOpen,
|
||
Loader2,
|
||
Play,
|
||
Power,
|
||
RefreshCw,
|
||
Settings,
|
||
Square,
|
||
} from "lucide-react";
|
||
|
||
const EMPTY = {
|
||
connected: false,
|
||
helper: "unknown",
|
||
desktop: "unknown",
|
||
spoofdpiAvailable: false,
|
||
config: {
|
||
proxyPort: 18080,
|
||
quicBlock: false,
|
||
spoofdpiPath: "",
|
||
autoStart: false,
|
||
},
|
||
appVersion: "1.0.0",
|
||
lastError: null,
|
||
};
|
||
|
||
async function call(command, args) {
|
||
if (!window.__TAURI_INTERNALS__) {
|
||
throw new Error("Tauri çalışma zamanı bulunamadı.");
|
||
}
|
||
return invoke(command, args);
|
||
}
|
||
|
||
export default function App() {
|
||
const [state, setState] = useState(EMPTY);
|
||
const [updateInfo, setUpdateInfo] = useState(null);
|
||
const [busy, setBusy] = useState("");
|
||
const [error, setError] = useState(null);
|
||
const [draft, setDraft] = useState(EMPTY.config);
|
||
const [notice, setNotice] = useState(null);
|
||
|
||
const refresh = useCallback(async () => {
|
||
try {
|
||
const next = await call("get_state");
|
||
setState(next);
|
||
setDraft(next.config);
|
||
setError(null);
|
||
} catch (e) {
|
||
setError(String(e));
|
||
}
|
||
}, []);
|
||
|
||
useEffect(() => {
|
||
refresh();
|
||
const timer = window.setInterval(refresh, 4000);
|
||
return () => window.clearInterval(timer);
|
||
}, [refresh]);
|
||
|
||
const connected = Boolean(state.connected);
|
||
const helperOk = state.helper === "ready";
|
||
const canStart = state.spoofdpiAvailable && !connected && busy !== "start";
|
||
|
||
const handleUpdate = async () => {
|
||
setBusy("update");
|
||
setError(null);
|
||
try {
|
||
const info = await call("check_linux_update");
|
||
setUpdateInfo(info);
|
||
setNotice(info.available ? `Yeni sürüm: ${info.version}` : "Güncel sürümdesiniz.");
|
||
} catch (e) {
|
||
setError(String(e));
|
||
} finally {
|
||
setBusy("");
|
||
}
|
||
};
|
||
|
||
const handleConnect = async () => {
|
||
setBusy(connected ? "stop" : "start");
|
||
setError(null);
|
||
setNotice(null);
|
||
try {
|
||
await call(connected ? "stop_fdpi" : "start_fdpi");
|
||
setNotice(connected ? "FDPI durduruldu." : "FDPI başlatıldı.");
|
||
await refresh();
|
||
} catch (e) {
|
||
setError(String(e));
|
||
await refresh();
|
||
} finally {
|
||
setBusy("");
|
||
}
|
||
};
|
||
|
||
const handleSave = async () => {
|
||
setBusy("save");
|
||
setError(null);
|
||
try {
|
||
const next = await call("save_config", { config: draft });
|
||
setState((prev) => ({ ...prev, config: next }));
|
||
setDraft(next);
|
||
setNotice("Ayarlar kaydedildi.");
|
||
} catch (e) {
|
||
setError(String(e));
|
||
} finally {
|
||
setBusy("");
|
||
}
|
||
};
|
||
|
||
const openFolder = async () => {
|
||
try {
|
||
await call("open_data_folder");
|
||
} catch (e) {
|
||
setError(String(e));
|
||
}
|
||
};
|
||
|
||
const status = useMemo(() => {
|
||
if (connected) return { label: "FDPI bağlı", tone: "ok" };
|
||
if (busy === "start") return { label: "Başlatılıyor", tone: "warn" };
|
||
return { label: "Bağlı değil", tone: "idle" };
|
||
}, [connected, busy]);
|
||
|
||
return (
|
||
<div className="app">
|
||
<header className="topbar">
|
||
<div className="brand">
|
||
<div className="logo">LD</div>
|
||
<div>
|
||
<strong>LD FDPI Linux</strong>
|
||
<small>Phase 1 · FDPI MVP</small>
|
||
</div>
|
||
</div>
|
||
<div className="top-actions">
|
||
<span className="version">v{state.appVersion}</span>
|
||
<span className={`pill ${status.tone}`}>{status.label}</span>
|
||
</div>
|
||
</header>
|
||
|
||
<main className="content">
|
||
{error && (
|
||
<div className="alert error">
|
||
<AlertTriangle size={16} />
|
||
<span>{error}</span>
|
||
<button onClick={() => setError(null)} aria-label="Kapat">×</button>
|
||
</div>
|
||
)}
|
||
{notice && (
|
||
<div className="alert ok">
|
||
<CheckCircle2 size={16} />
|
||
<span>{notice}</span>
|
||
<button onClick={() => setNotice(null)} aria-label="Kapat">×</button>
|
||
</div>
|
||
)}
|
||
|
||
<section className="hero">
|
||
<div>
|
||
<div className="eyebrow">WINDOWS PARITY · PHASE 1</div>
|
||
<h1>DPI engelini<br /><span>Linux'ta aş.</span></h1>
|
||
<p>
|
||
SpoofDPI tabanlı yerel proxy. Sistem proxy'si GNOME üzerinden
|
||
uygulanır ve QUIC uyumluluğu systemd helper tarafından yönetilir.
|
||
</p>
|
||
</div>
|
||
<div className={`pulse-card ${connected ? "is-on" : ""}`}>
|
||
<div className="pulse-orb"><Power size={28} /></div>
|
||
<div>
|
||
<strong>{connected ? "Koruma aktif" : "Hazır"}</strong>
|
||
<small>{connected ? `127.0.0.1:${state.config.proxyPort}` : "Bağlantı bekleniyor"}</small>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
|
||
<section className="card connect-card">
|
||
<div className="card-head">
|
||
<div>
|
||
<div className="kicker">FDPI</div>
|
||
<h2>SpoofDPI yerel proxy</h2>
|
||
</div>
|
||
<span className={`pill ${helperOk ? "ok" : "warn"}`}>
|
||
helper: {state.helper}
|
||
</span>
|
||
</div>
|
||
|
||
<div className="facts">
|
||
<div><span>Desktop</span><b>{state.desktop}</b></div>
|
||
<div><span>SpoofDPI</span><b>{state.spoofdpiAvailable ? "bulundu" : "yok"}</b></div>
|
||
<div><span>Proxy portu</span><b>{state.config.proxyPort}</b></div>
|
||
<div><span>Helper</span><b>{state.helper}</b></div>
|
||
</div>
|
||
|
||
<button
|
||
className={`primary ${connected ? "danger" : ""}`}
|
||
onClick={handleConnect}
|
||
disabled={busy === "start" || busy === "stop" || (!connected && !canStart)}
|
||
>
|
||
{busy === "start" || busy === "stop" ? (
|
||
<Loader2 size={18} className="spin" />
|
||
) : connected ? (
|
||
<Square size={18} />
|
||
) : (
|
||
<Play size={18} />
|
||
)}
|
||
{connected ? "Bağlantıyı Kes" : "BAĞLAN"}
|
||
</button>
|
||
|
||
{!state.spoofdpiAvailable && (
|
||
<p className="hint warn-text">
|
||
SpoofDPI bulunamadı. <code>/usr/lib/ld-fdpi/spoofdpi</code> yolu
|
||
veya Ayarlar'daki <code>spoofdpiPath</code> gerekli.
|
||
</p>
|
||
)}
|
||
{state.desktop !== "gnome" && (
|
||
<p className="hint warn-text">
|
||
Bu MVP yalnızca GNOME sistem proxy'sini destekler. KDE Faz 2'de.
|
||
</p>
|
||
)}
|
||
</section>
|
||
|
||
|
||
<section className="card">
|
||
<div className="card-head">
|
||
<div>
|
||
<div className="kicker">Ayarlar</div>
|
||
<h2>Bağlantı tercihleri</h2>
|
||
</div>
|
||
<Settings size={20} />
|
||
</div>
|
||
|
||
<div className="form">
|
||
<label>
|
||
Proxy portu
|
||
<input
|
||
type="number"
|
||
min="1024"
|
||
max="65535"
|
||
value={draft.proxyPort}
|
||
onChange={(e) => setDraft({ ...draft, proxyPort: Number(e.target.value) })}
|
||
/>
|
||
</label>
|
||
<label>
|
||
SpoofDPI yolu
|
||
<input
|
||
value={draft.spoofdpiPath}
|
||
placeholder="/usr/lib/ld-fdpi/spoofdpi"
|
||
onChange={(e) => setDraft({ ...draft, spoofdpiPath: e.target.value })}
|
||
/>
|
||
</label>
|
||
<label className="switch-row">
|
||
<span>
|
||
QUIC uyumluluk modu
|
||
<small>Faz 2 · cgroup/nftables</small>
|
||
</span>
|
||
<input
|
||
type="checkbox"
|
||
checked={Boolean(draft.quicBlock)}
|
||
disabled
|
||
readOnly
|
||
/>
|
||
</label>
|
||
<label className="switch-row">
|
||
<span>
|
||
Otomatik başlat
|
||
<small>Faz 5 · systemd user unit</small>
|
||
</span>
|
||
<input
|
||
type="checkbox"
|
||
checked={Boolean(draft.autoStart)}
|
||
disabled
|
||
readOnly
|
||
/>
|
||
</label>
|
||
</div>
|
||
|
||
<div className="actions">
|
||
<button className="primary" onClick={handleSave} disabled={busy === "save"}>
|
||
{busy === "save" ? <Loader2 size={16} className="spin" /> : <RefreshCw size={16} />}
|
||
Kaydet
|
||
</button>
|
||
<button className="secondary" onClick={openFolder}>
|
||
<FolderOpen size={16} />
|
||
Ayar klasörü
|
||
</button>
|
||
<button className="secondary" onClick={handleUpdate} disabled={busy === "update"}>
|
||
{busy === "update" ? <Loader2 size={16} className="spin" /> : <RefreshCw size={16} />}
|
||
Güncelleme kontrol et
|
||
</button>
|
||
</div>
|
||
{updateInfo && (
|
||
<p className="hint">
|
||
Sürüm: {updateInfo.version} ·{" "}
|
||
{updateInfo.available ? (
|
||
<a href={updateInfo.url} target="_blank" rel="noopener" style={{ color: "#8fe3f5" }}>
|
||
güncellemeyi indir
|
||
</a>
|
||
) : (
|
||
"güncel"
|
||
)}
|
||
{updateInfo.notes ? ` · ${updateInfo.notes}` : ""}
|
||
</p>
|
||
)}
|
||
</section>
|
||
|
||
<footer>
|
||
<span>LD FDPI Linux · Phase 0/1</span>
|
||
<span>Windows v1.7.3 hattı etkilenmez</span>
|
||
</footer>
|
||
</main>
|
||
</div>
|
||
);
|
||
}
|