desktop app windows

This commit is contained in:
2026-03-20 13:33:52 +07:00
parent 366168c7ad
commit 12e7fdf422
9 changed files with 200 additions and 74 deletions
+30
View File
@@ -4,6 +4,8 @@ import { cn } from "@/lib/utils";
import { useTranslation } from "react-i18next";
import { TunnelConfig, startVpn, stopVpn } from "vpn-plugin";
import { useVpnStore } from "@/store/useVpnStore";
import { useEffect } from "react";
import { listen } from "@tauri-apps/api/event";
export function VpnControl() {
const { status, setStatus } = useVpnStore();
@@ -28,6 +30,34 @@ export function VpnControl() {
}
};
// Слушаем события напрямую в компоненте
useEffect(() => {
let unlisten: (() => void) | null = null;
async function setupListener() {
// Слушаем глобальное событие 'status-change', которое шлет Rust через app.emit
unlisten = await listen<{ status: string }>("status-change", (event) => {
console.log("--- [GUI] Direct Event Received:", event.payload);
const newStatus = event.payload.status as
| "idle"
| "connecting"
| "connected";
// Обновляем глобальный стор
if (newStatus) {
setStatus(newStatus);
}
});
}
setupListener();
// Очистка при размонтировании
return () => {
if (unlisten) unlisten();
};
}, [setStatus]);
const { t } = useTranslation();
const isActive = status !== "idle";