Tray: separate tray and window processes; device list without self
Release / tsunagi-linux-aarch64 (push) Successful in 2m44s
Release / tsunagi-linux-x86_64 (push) Successful in 4m37s
Release / tsunagi-macos-aarch64 (push) Canceled after 0s
Release / tsunagi-windows-x86_64 (push) Canceled after 0s
Release / Publish release (push) Canceled after 0s
Release / tsunagi-linux-aarch64 (push) Successful in 2m44s
Release / tsunagi-linux-x86_64 (push) Successful in 4m37s
Release / tsunagi-macos-aarch64 (push) Canceled after 0s
Release / tsunagi-windows-x86_64 (push) Canceled after 0s
Release / Publish release (push) Canceled after 0s
The tray process holds only the icon and starts the same binary with --window on Open; the window ends when closed, which works on Wayland where a window cannot be hidden. The devices table now names devices as hostname (id5), leaves out this device and counts the others. Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
1 parent
69310108f4
commit
f4dcdec662
6 files changed
+247
-172
No files matched your search
@@ -1,5 +1,9 @@
|
||||
//! The eframe application: wires the tray, the main window, the per-network
|
||||
//! The eframe application behind the window: the main view, the per-network
|
||||
//! devices windows, and the agent worker.
|
||||
//!
|
||||
//! It runs in its own process, started by the tray when the user chooses Open
|
||||
//! and gone when the window is closed. The tray, which has to outlive the
|
||||
//! window, lives in the other process; see [`crate::tray`].
|
||||
|
||||
use std::time::Duration;
|
||||
|
||||
@@ -8,24 +12,20 @@ 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, UiState};
|
||||
|
||||
/// The tray application state.
|
||||
/// The window's state.
|
||||
pub(crate) struct App {
|
||||
agent: AgentClient,
|
||||
tray: Tray,
|
||||
state: UiState,
|
||||
/// Traffic rates derived from successive snapshots.
|
||||
traffic: Traffic,
|
||||
/// The snapshot generation last folded into `traffic`.
|
||||
sampled: u64,
|
||||
/// Set when the user chose Quit, so the next close exits rather than hides.
|
||||
quitting: bool,
|
||||
}
|
||||
|
||||
impl App {
|
||||
/// Builds the app: resolves the socket, starts the worker, creates the tray.
|
||||
/// Builds the app: resolves the socket and starts the worker.
|
||||
pub(crate) fn new(
|
||||
cc: &eframe::CreationContext<'_>,
|
||||
runtime: tokio::runtime::Handle,
|
||||
@@ -37,40 +37,18 @@ impl App {
|
||||
egui_phosphor::add_to_fonts(&mut fonts, egui_phosphor::Variant::Regular);
|
||||
ctx.set_fonts(fonts);
|
||||
|
||||
let agent = AgentClient::spawn(&runtime, ctx.clone(), resolve_socket());
|
||||
let tray = Tray::new(ctx)?;
|
||||
let agent = AgentClient::spawn(&runtime, ctx, resolve_socket());
|
||||
Ok(Self {
|
||||
agent,
|
||||
tray,
|
||||
state: UiState::default(),
|
||||
traffic: Traffic::default(),
|
||||
sampled: 0,
|
||||
quitting: false,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl eframe::App for App {
|
||||
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
||||
for action in self.tray.poll() {
|
||||
match action {
|
||||
Action::Open => {
|
||||
ctx.send_viewport_cmd(egui::ViewportCommand::Visible(true));
|
||||
ctx.send_viewport_cmd(egui::ViewportCommand::Focus);
|
||||
}
|
||||
Action::Quit => {
|
||||
self.quitting = true;
|
||||
ctx.send_viewport_cmd(egui::ViewportCommand::Close);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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();
|
||||
if snapshot.generation != self.sampled
|
||||
&& let (Some(Ok(report)), Some(at)) = (&snapshot.status, snapshot.at)
|
||||
@@ -88,7 +66,7 @@ impl eframe::App for App {
|
||||
ctx.copy_text(secret);
|
||||
}
|
||||
|
||||
// Keep ticking so fresh status and tray actions are picked up.
|
||||
// Keep ticking so fresh status is picked up.
|
||||
ctx.request_repaint_after(Duration::from_millis(500));
|
||||
}
|
||||
}
|
||||
@@ -117,7 +95,7 @@ impl App {
|
||||
// main window's stay in step.
|
||||
let unit = &mut self.state.unit;
|
||||
let keep = ctx.show_viewport_immediate(viewport_id, builder, |vctx, _class| {
|
||||
devices::show(vctx, agent, unit, network, traffic);
|
||||
devices::show(vctx, agent, unit, network, &report.endpoint_id, traffic);
|
||||
!vctx.input(|i| i.viewport().close_requested())
|
||||
});
|
||||
if !keep {
|
||||
|
||||
Reference in new issue
Block a user