2026-10-02 15:37:08 +01:00
|
|
|
//! The main window: a compact overview. Per-network detail (the full peer
|
|
|
|
|
//! table with inline plots) lives in a separate devices window (see
|
|
|
|
|
//! [`crate::devices`]), opened from each tile.
|
2026-10-02 14:48:52 +01:00
|
|
|
//!
|
2026-10-02 15:37:08 +01:00
|
|
|
//! Pure rendering: state comes from the snapshot and the traffic sampler, a
|
2026-11-24 17:28:23 +02:00
|
|
|
//! change to a switch or button sends a [`tsunagi_ui::client::Command`] to the worker, and local UI
|
2026-10-02 15:37:08 +01:00
|
|
|
//! state (the join form, the unit toggle, which devices windows are open, an
|
|
|
|
|
//! in-progress hostname edit) lives in [`UiState`].
|
2026-10-02 15:08:29 +01:00
|
|
|
|
2026-11-24 17:28:23 +02:00
|
|
|
pub(crate) use tsunagi_ui::home::UiState;
|
|
|
|
|
use tsunagi_ui::home::{draw_header, draw_join, draw_network};
|
2026-10-02 14:48:52 +01:00
|
|
|
|
|
|
|
|
use eframe::egui;
|
2026-10-02 16:00:23 +01:00
|
|
|
use egui_phosphor::regular as icon;
|
2026-10-02 14:48:52 +01:00
|
|
|
|
2026-11-24 17:28:23 +02:00
|
|
|
use crate::agent::{AgentClient, Snapshot};
|
2026-10-02 19:23:06 +01:00
|
|
|
use crate::devices;
|
2026-10-02 15:37:08 +01:00
|
|
|
use crate::stats::{Traffic, Unit};
|
2026-10-02 15:08:29 +01:00
|
|
|
|
|
|
|
|
const OK: egui::Color32 = egui::Color32::from_rgb(0x3c, 0xb0, 0x4a);
|
|
|
|
|
const BAD: egui::Color32 = egui::Color32::from_rgb(0xd0, 0x4a, 0x3c);
|
2026-10-02 15:37:08 +01:00
|
|
|
|
|
|
|
|
/// Draws the main window.
|
2026-10-02 14:48:52 +01:00
|
|
|
pub(crate) fn draw(
|
|
|
|
|
ctx: &egui::Context,
|
|
|
|
|
agent: &AgentClient,
|
2026-10-02 15:37:08 +01:00
|
|
|
state: &mut UiState,
|
2026-10-02 14:48:52 +01:00
|
|
|
snapshot: &Snapshot,
|
2026-10-02 15:08:29 +01:00
|
|
|
traffic: &Traffic,
|
2026-10-02 14:48:52 +01:00
|
|
|
) {
|
2026-10-02 15:08:29 +01:00
|
|
|
egui::TopBottomPanel::top("top").show(ctx, |ui| {
|
|
|
|
|
ui.add_space(4.0);
|
2026-10-02 14:48:52 +01:00
|
|
|
ui.horizontal(|ui| {
|
|
|
|
|
ui.heading("tsunagi");
|
2026-10-02 20:16:01 +01:00
|
|
|
ui.label(
|
|
|
|
|
egui::RichText::new(env!("CARGO_PKG_VERSION"))
|
|
|
|
|
.small()
|
|
|
|
|
.weak(),
|
|
|
|
|
);
|
2026-10-02 14:48:52 +01:00
|
|
|
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
2026-11-25 15:38:10 +02:00
|
|
|
if tsunagi_ui::widgets::icon_button(ui, icon::INFO, "About Tsunagi").clicked() {
|
2026-10-02 20:16:01 +01:00
|
|
|
state.about_open = true;
|
2026-10-02 14:48:52 +01:00
|
|
|
}
|
|
|
|
|
if snapshot.busy {
|
|
|
|
|
ui.add(egui::Spinner::new());
|
|
|
|
|
}
|
2026-10-02 15:37:08 +01:00
|
|
|
ui.separator();
|
|
|
|
|
ui.selectable_value(&mut state.unit, Unit::Bytes, "bytes");
|
|
|
|
|
ui.selectable_value(&mut state.unit, Unit::Packets, "pkts");
|
|
|
|
|
ui.label("show:");
|
2026-10-02 14:48:52 +01:00
|
|
|
});
|
|
|
|
|
});
|
2026-10-02 15:08:29 +01:00
|
|
|
ui.add_space(4.0);
|
|
|
|
|
});
|
2026-10-02 14:48:52 +01:00
|
|
|
|
2026-10-02 15:08:29 +01:00
|
|
|
egui::TopBottomPanel::bottom("bottom").show(ctx, |ui| {
|
|
|
|
|
if let Some(action) = &snapshot.last_action {
|
|
|
|
|
ui.add_space(4.0);
|
|
|
|
|
match action {
|
|
|
|
|
Ok(message) => ui.colored_label(OK, message),
|
|
|
|
|
Err(error) => ui.colored_label(BAD, error),
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
ui.add_space(4.0);
|
2026-10-02 15:37:08 +01:00
|
|
|
draw_join(ui, agent, &mut state.join);
|
2026-10-02 15:08:29 +01:00
|
|
|
ui.add_space(4.0);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
egui::CentralPanel::default().show(ctx, |ui| match &snapshot.status {
|
|
|
|
|
None => {
|
|
|
|
|
ui.add_space(8.0);
|
|
|
|
|
ui.label("Connecting to the agent…");
|
|
|
|
|
}
|
|
|
|
|
Some(Err(error)) => draw_unreachable(ui, agent, error),
|
|
|
|
|
Some(Ok(report)) => {
|
2026-10-02 15:37:08 +01:00
|
|
|
draw_header(ui, agent, state, report);
|
2026-10-02 15:08:29 +01:00
|
|
|
ui.separator();
|
|
|
|
|
egui::ScrollArea::vertical()
|
|
|
|
|
.auto_shrink([false, false])
|
|
|
|
|
.show(ui, |ui| {
|
2026-10-02 14:48:52 +01:00
|
|
|
if report.networks.is_empty() {
|
2026-10-02 15:08:29 +01:00
|
|
|
ui.add_space(6.0);
|
|
|
|
|
ui.weak("No networks yet — join one below.");
|
2026-10-02 14:48:52 +01:00
|
|
|
}
|
|
|
|
|
for network in &report.networks {
|
2026-11-24 17:28:23 +02:00
|
|
|
draw_network(ui, agent, state, traffic, network, report, true);
|
2026-10-02 14:48:52 +01:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
2026-10-03 02:09:14 +01:00
|
|
|
|
|
|
|
|
devices::confirm_exit(ctx, agent, &mut state.exit_confirm, None);
|
2026-10-02 14:48:52 +01:00
|
|
|
}
|
|
|
|
|
|
2026-10-02 15:37:08 +01:00
|
|
|
/// The "agent cannot be reached" state.
|
2026-10-02 14:48:52 +01:00
|
|
|
fn draw_unreachable(ui: &mut egui::Ui, agent: &AgentClient, error: &str) {
|
|
|
|
|
ui.add_space(8.0);
|
2026-10-02 15:08:29 +01:00
|
|
|
ui.colored_label(BAD, "The agent is not reachable.");
|
2026-10-02 14:48:52 +01:00
|
|
|
ui.add_space(6.0);
|
2026-10-02 15:37:08 +01:00
|
|
|
ui.horizontal(|ui| {
|
|
|
|
|
ui.weak("socket");
|
|
|
|
|
ui.monospace(agent.socket().display().to_string());
|
|
|
|
|
});
|
2026-10-02 15:08:29 +01:00
|
|
|
ui.add_space(4.0);
|
|
|
|
|
ui.weak(error);
|
|
|
|
|
ui.add_space(6.0);
|
|
|
|
|
ui.weak(
|
2026-10-02 14:48:52 +01:00
|
|
|
"Start the agent, or check that this user may open its control socket \
|
|
|
|
|
(its group, mode 0660).",
|
|
|
|
|
);
|
|
|
|
|
}
|