diff --git a/src/main.rs b/src/main.rs index 94feeaf..7a13bac 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,24 +4,17 @@ mod svg; mod tailscale; mod tray; -use crate::tray::menu::SysTray; +use crate::tray::utils::start_tray_service; use std::thread::park; fn main() { // initialize logger env_logger::init(); - // start the tray service - let handle = ksni::spawn(SysTray { - ctx: tailscale::status::get_current_status(), - }) - .unwrap(); + // start tray service + start_tray_service(); // keep the main thread alive - // NOTE: The documentation for park reads: - // "A call to park does not guarantee that the thread will - // remain parked forever, and callers should be prepared for this possibility." - // hence the loop loop { park(); } diff --git a/src/tray/menu.rs b/src/tray/menu.rs index 9c460c4..02280a6 100644 --- a/src/tray/menu.rs +++ b/src/tray/menu.rs @@ -30,12 +30,6 @@ pub struct SysTray { } impl SysTray { - pub fn new() -> Self { - SysTray { - ctx: get_current_status(), - } - } - fn enabled(&self) -> bool { self.ctx.status.tailscale_up } @@ -112,6 +106,10 @@ impl Tray for SysTray { ResvgRenderer::load_icon(self.enabled()) } + fn id(&self) -> String { + env!("CARGO_PKG_NAME").into() + } + fn title(&self) -> String { "Tailray".into() } @@ -215,7 +213,7 @@ impl Tray for SysTray { .into(), MenuItem::Separator, StandardItem { - label: "Exit".into(), + label: "Exit Tailray".into(), icon_name: "application-exit".into(), activate: Box::new(|_| std::process::exit(0)), ..Default::default() @@ -232,8 +230,4 @@ impl Tray for SysTray { info!("Watcher offline, shutting down the system Tray."); false } - - fn id(&self) -> String { - "tailray".to_string() - } } diff --git a/src/tray/mod.rs b/src/tray/mod.rs index b9a0e3e..f0837a9 100644 --- a/src/tray/mod.rs +++ b/src/tray/mod.rs @@ -1 +1,2 @@ pub mod menu; +pub mod utils; diff --git a/src/tray/utils.rs b/src/tray/utils.rs new file mode 100644 index 0000000..505bfd6 --- /dev/null +++ b/src/tray/utils.rs @@ -0,0 +1,12 @@ +use crate::tailscale; +use crate::tray::menu::SysTray; + +pub fn start_tray_service() { + // start the tray service + let _handle = ksni::spawn(SysTray { + ctx: tailscale::status::get_current_status(), + }) + .unwrap_or_else(|e| { + panic!("Failed to start the tray service: {}", e); + }); +}