Update
This commit is contained in:
+35
-5
@@ -11,9 +11,11 @@ from PyQt6.QtGui import QFont, QCloseEvent, QColor
|
||||
from app.core.config import Config
|
||||
from app.core import wireguard as wg_core
|
||||
from app.core import log as conn_log
|
||||
from app.core import history as hist
|
||||
from app.ui.mfa_dialog import MFADialog
|
||||
from app.ui.admin_window import AdminWindow
|
||||
from app.ui.bw_graph import BandwidthGraph
|
||||
from app.ui.history_dialog import HistoryDialog
|
||||
from app.ui import icons
|
||||
|
||||
_DARK = "#1c2833"
|
||||
@@ -44,6 +46,7 @@ class MainWindow(QMainWindow):
|
||||
self._prev_rx: int | None = None
|
||||
self._prev_tx: int | None = None
|
||||
self._auto_reconnect_active = False
|
||||
self._session_id: int | None = None
|
||||
|
||||
self.setWindowTitle("WGSecure")
|
||||
self.setFixedSize(430, 680)
|
||||
@@ -80,6 +83,9 @@ class MainWindow(QMainWindow):
|
||||
self._reload_log()
|
||||
self._reload_profiles()
|
||||
|
||||
if self._cfg.get("ui", "auto_connect_on_startup") and self._cfg.configured:
|
||||
QTimer.singleShot(500, self._on_connect)
|
||||
|
||||
# ------------------------------------------------------------------ #
|
||||
# Construction UI
|
||||
# ------------------------------------------------------------------ #
|
||||
@@ -246,7 +252,10 @@ class MainWindow(QMainWindow):
|
||||
self._btn_connect.clicked.connect(self._on_connect)
|
||||
bl.addWidget(self._btn_connect)
|
||||
|
||||
btn_admin = QPushButton("⚙️ Panneau Administrateur")
|
||||
secondary_row = QHBoxLayout()
|
||||
secondary_row.setSpacing(6)
|
||||
|
||||
btn_admin = QPushButton("⚙️ Administrateur")
|
||||
btn_admin.setFixedHeight(30)
|
||||
btn_admin.setStyleSheet(
|
||||
"QPushButton { background: #2e4057; color: white; border-radius: 6px;"
|
||||
@@ -254,7 +263,19 @@ class MainWindow(QMainWindow):
|
||||
"QPushButton:hover { background: #3d5166; }"
|
||||
)
|
||||
btn_admin.clicked.connect(self._open_admin)
|
||||
bl.addWidget(btn_admin)
|
||||
secondary_row.addWidget(btn_admin)
|
||||
|
||||
btn_history = QPushButton("📊 Historique")
|
||||
btn_history.setFixedHeight(30)
|
||||
btn_history.setStyleSheet(
|
||||
"QPushButton { background: #2e4057; color: white; border-radius: 6px;"
|
||||
" font-size: 11px; border: none; }"
|
||||
"QPushButton:hover { background: #3d5166; }"
|
||||
)
|
||||
btn_history.clicked.connect(self._open_history)
|
||||
secondary_row.addWidget(btn_history)
|
||||
|
||||
bl.addLayout(secondary_row)
|
||||
root.addWidget(btn_area)
|
||||
|
||||
# ── Helpers UI ───────────────────────────────────────────────────────
|
||||
@@ -508,6 +529,11 @@ class MainWindow(QMainWindow):
|
||||
if connected:
|
||||
ok, msg = wg_core.disconnect(self._cfg)
|
||||
if ok:
|
||||
if self._session_id is not None:
|
||||
rx = self._prev_rx or 0
|
||||
tx = self._prev_tx or 0
|
||||
hist.end_session(self._session_id, rx, tx)
|
||||
self._session_id = None
|
||||
self._add_log("Tunnel WireGuard désactivé", "warning")
|
||||
else:
|
||||
self._add_log(f"Erreur déconnexion : {msg}", "error")
|
||||
@@ -543,9 +569,10 @@ class MainWindow(QMainWindow):
|
||||
|
||||
if ok:
|
||||
self._connected_since = QDateTime.currentDateTime()
|
||||
self._add_log(
|
||||
f"Connexion établie → {self._cfg.wg.get('server_endpoint','')}", "success"
|
||||
)
|
||||
endpoint = self._cfg.wg.get("server_endpoint", "")
|
||||
profile = self._cfg.active_profile
|
||||
self._session_id = hist.start_session(endpoint, profile)
|
||||
self._add_log(f"Connexion établie → {endpoint}", "success")
|
||||
QTimer.singleShot(5000, self._update_ping)
|
||||
else:
|
||||
self._add_log(f"Erreur : {msg}", "error")
|
||||
@@ -553,6 +580,9 @@ class MainWindow(QMainWindow):
|
||||
|
||||
self._refresh_status()
|
||||
|
||||
def _open_history(self):
|
||||
HistoryDialog(self).exec()
|
||||
|
||||
def _open_admin(self):
|
||||
if self._cfg.has_admin_password():
|
||||
pw, ok = QInputDialog.getText(
|
||||
|
||||
Reference in New Issue
Block a user