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,12 +1,12 @@
|
||||
//! Tray application for managing a running tsunagi agent.
|
||||
//!
|
||||
//! A small window (networks, their peers and addresses, join/leave, per-network
|
||||
//! active and broadcast switches) plus a tray menu (Open, Quit). It is a thin
|
||||
//! client over the agent's local control socket — the same interface the CLI
|
||||
//! uses — and owns its own runtime, logger and event loop, like the CLI binary.
|
||||
//! A tray icon and menu (Open, Quit) that opens a small window (networks, their
|
||||
//! peers and addresses, join/leave, per-network active and broadcast switches).
|
||||
//! There is no window until Open, and closing it leaves the icon. The window
|
||||
//! is a thin client over the agent's local control socket — the same interface
|
||||
//! the CLI uses.
|
||||
|
||||
// The window is created hidden-to-tray on close rather than exiting; the binary
|
||||
// itself may exit on Quit. Nothing here is a library.
|
||||
// Nothing here is a library.
|
||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||
|
||||
mod agent;
|
||||
@@ -21,38 +21,42 @@ use eframe::egui;
|
||||
|
||||
use crate::app::App;
|
||||
|
||||
/// The argument that makes this binary the window rather than the tray.
|
||||
const WINDOW_ARG: &str = "--window";
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let filter = tracing_subscriber::EnvFilter::try_from_default_env()
|
||||
.unwrap_or_else(|_| tracing_subscriber::EnvFilter::new("warn"));
|
||||
let _ = tracing_subscriber::fmt().with_env_filter(filter).try_init();
|
||||
|
||||
// Two processes from one binary. The tray is what stays; the window is
|
||||
// started by it and ends when it is closed. A window that merely hides is
|
||||
// not something every platform can do — Wayland has no such thing — and a
|
||||
// hidden one that stays is worse than none.
|
||||
if std::env::args().any(|arg| arg == WINDOW_ARG) {
|
||||
window()
|
||||
} else {
|
||||
tray::run()
|
||||
}
|
||||
}
|
||||
|
||||
/// Runs the window until it is closed.
|
||||
fn window() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let runtime = tokio::runtime::Builder::new_multi_thread()
|
||||
.enable_all()
|
||||
.build()?;
|
||||
let handle = runtime.handle().clone();
|
||||
|
||||
#[cfg_attr(not(target_os = "macos"), expect(unused_mut))]
|
||||
let mut options = eframe::NativeOptions {
|
||||
let options = eframe::NativeOptions {
|
||||
// A fixed, small window; the whole layout targets this size.
|
||||
viewport: egui::ViewportBuilder::default()
|
||||
.with_title("tsunagi")
|
||||
.with_app_id("tsunagi")
|
||||
.with_inner_size([360.0, 600.0])
|
||||
.with_resizable(false)
|
||||
// Start hidden: the app lives in the tray and the window opens from
|
||||
// the menu.
|
||||
.with_visible(false),
|
||||
.with_resizable(false),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
// macOS: live in the menu bar with no Dock icon (tray-only).
|
||||
#[cfg(target_os = "macos")]
|
||||
{
|
||||
options.event_loop_builder = Some(Box::new(|builder| {
|
||||
use winit::platform::macos::{ActivationPolicy, EventLoopBuilderExtMacOS};
|
||||
builder.with_activation_policy(ActivationPolicy::Accessory);
|
||||
}));
|
||||
}
|
||||
|
||||
eframe::run_native(
|
||||
"tsunagi",
|
||||
options,
|
||||
@@ -63,7 +67,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
}),
|
||||
)?;
|
||||
|
||||
// The window loop has ended (Quit); let the runtime wind down.
|
||||
// The window loop has ended; let the runtime wind down.
|
||||
drop(runtime);
|
||||
Ok(())
|
||||
}
|
||||
Reference in new issue
Block a user