Tray: devices window, bytes/packets toggle, copy & edit affordances
Replaces the in-tile collapsing peer list with a "Show devices" button that opens a separate, normal-sized window per network, and fills in the rest of the feedback. Main window: - A global show: pkts/bytes toggle; all rates and sparklines follow it. - Sparklines now reserve their space always (fixed height, "no data yet" placeholder) so the layout no longer jumps when data arrives, and each one overlays its peak (top-left) and current value (bottom-right) with units. - Device id has a copy button; the hostname is editable in place (✎ → edit → ✔/Enter sends SetHostname); network name, range and address copy on click. - The Leave button is a neutral red. Per-tile "Show devices" opens the detail. Devices window (a separate egui viewport per network): - Network summary: id (copy), active/broadcast, range, this device's address, candidates, relay fwd/via/recv, dial/handshake failures. - A larger network traffic sparkline. - Connected peers in a table: hostname when known (else short key), protocol, address, handshake age formatted (s/m/h/d), tx/rx packets, tx/rx bytes, and current rate with an inline sparkline. Names and addresses copy on click. - Offline members listed below with address and failed-dial count. Agent: a SetHostname command (over the existing ipc) backs the in-place rename. Traffic sampler now tracks both packet and byte rates; the toggle selects which. Deferred: a "copy secret" button on the tile — the secret is deliberately not exported to the GUI (secrets never leave the agent), so it needs a small local secret-export ipc, which is the next step. Builds and is clippy-clean (-D warnings) on macOS; the UI has not been run in this headless session. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
1 parent
0a344c1b4f
commit
8f5ce21ce9
7 files changed
+602
-193
No files matched your search
@@ -1,26 +1,26 @@
|
||||
//! The eframe application: wires the tray, the window and the agent worker.
|
||||
//! The eframe application: wires the tray, the main window, the per-network
|
||||
//! devices windows, and the agent worker.
|
||||
|
||||
use std::time::Duration;
|
||||
|
||||
use eframe::egui;
|
||||
|
||||
use crate::agent::{AgentClient, resolve_socket};
|
||||
use crate::devices;
|
||||
use crate::stats::Traffic;
|
||||
use crate::tray::{Action, Tray};
|
||||
use crate::ui::{self, JoinForm};
|
||||
use crate::ui::{self, UiState};
|
||||
|
||||
/// The tray application state.
|
||||
pub(crate) struct App {
|
||||
agent: AgentClient,
|
||||
tray: Tray,
|
||||
join: JoinForm,
|
||||
state: UiState,
|
||||
/// Traffic rates derived from successive snapshots.
|
||||
traffic: Traffic,
|
||||
/// The snapshot generation last folded into `traffic`, so each refresh is
|
||||
/// sampled exactly once rather than on every repaint.
|
||||
/// The snapshot generation last folded into `traffic`.
|
||||
sampled: u64,
|
||||
/// Set when the user chose Quit, so the next close actually exits instead
|
||||
/// of hiding to the tray.
|
||||
/// Set when the user chose Quit, so the next close exits rather than hides.
|
||||
quitting: bool,
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ impl App {
|
||||
Ok(Self {
|
||||
agent,
|
||||
tray,
|
||||
join: JoinForm::default(),
|
||||
state: UiState::default(),
|
||||
traffic: Traffic::default(),
|
||||
sampled: 0,
|
||||
quitting: false,
|
||||
@@ -59,24 +59,56 @@ impl eframe::App for App {
|
||||
}
|
||||
}
|
||||
|
||||
// Closing the window hides it to the tray; only Quit truly exits.
|
||||
// Closing the main window hides it to the tray; only Quit truly exits.
|
||||
if ctx.input(|i| i.viewport().close_requested()) && !self.quitting {
|
||||
ctx.send_viewport_cmd(egui::ViewportCommand::CancelClose);
|
||||
ctx.send_viewport_cmd(egui::ViewportCommand::Visible(false));
|
||||
}
|
||||
|
||||
let snapshot = self.agent.snapshot();
|
||||
// Fold each fresh status into the traffic rates exactly once.
|
||||
if snapshot.generation != self.sampled
|
||||
&& let (Some(Ok(report)), Some(at)) = (&snapshot.status, snapshot.at)
|
||||
{
|
||||
self.traffic.observe(report, at);
|
||||
self.sampled = snapshot.generation;
|
||||
}
|
||||
ui::draw(ctx, &self.agent, &mut self.join, &snapshot, &self.traffic);
|
||||
|
||||
// Keep ticking so fresh status and tray actions are picked up even when
|
||||
// nothing else requests a repaint.
|
||||
ui::draw(ctx, &self.agent, &mut self.state, &snapshot, &self.traffic);
|
||||
self.show_devices_windows(ctx, &snapshot);
|
||||
|
||||
// Keep ticking so fresh status and tray actions are picked up.
|
||||
ctx.request_repaint_after(Duration::from_millis(500));
|
||||
}
|
||||
}
|
||||
|
||||
impl App {
|
||||
/// Renders one separate window per open network-devices view.
|
||||
fn show_devices_windows(&mut self, ctx: &egui::Context, snapshot: &crate::agent::Snapshot) {
|
||||
let Some(Ok(report)) = &snapshot.status else {
|
||||
return;
|
||||
};
|
||||
let unit = self.state.unit;
|
||||
let open: Vec<String> = self.state.open_devices.iter().cloned().collect();
|
||||
for id in open {
|
||||
let Some(network) = report.networks.iter().find(|n| n.network_id == id) else {
|
||||
// The network is gone (left/forgotten); close its window.
|
||||
self.state.open_devices.remove(&id);
|
||||
continue;
|
||||
};
|
||||
let viewport_id = egui::ViewportId::from_hash_of(("devices", &id));
|
||||
let builder = egui::ViewportBuilder::default()
|
||||
.with_title(devices::title(network))
|
||||
.with_inner_size([720.0, 540.0])
|
||||
.with_min_inner_size([480.0, 320.0]);
|
||||
let agent = &self.agent;
|
||||
let traffic = &self.traffic;
|
||||
let keep = ctx.show_viewport_immediate(viewport_id, builder, |vctx, _class| {
|
||||
devices::show(vctx, agent, unit, network, traffic);
|
||||
!vctx.input(|i| i.viewport().close_requested())
|
||||
});
|
||||
if !keep {
|
||||
self.state.open_devices.remove(&id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user