diff --git a/src/main.rs b/src/main.rs index 9fd7657..dac06b8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,7 +11,7 @@ fn main() { env_logger::init(); // start the tray service - TrayService::new(crate::tray::SysTray::new()).spawn(); + TrayService::new(crate::tray::menu::SysTray::new()).spawn(); // keep the main thread alive loop { diff --git a/src/tailscale/status.rs b/src/tailscale/status.rs index 8437ac6..b3e867a 100644 --- a/src/tailscale/status.rs +++ b/src/tailscale/status.rs @@ -1,6 +1,6 @@ use crate::tailscale::dns; use crate::tailscale::utils::{Machine, User}; -use crate::tray::Context; +use crate::tray::menu::Context; use serde::{Deserialize, Serialize}; use std::{collections::HashMap, process::Command}; use which::which; diff --git a/src/tray.rs b/src/tray/menu.rs similarity index 93% rename from src/tray.rs rename to src/tray/menu.rs index 7a30b74..457a34f 100644 --- a/src/tray.rs +++ b/src/tray/menu.rs @@ -81,8 +81,20 @@ impl SysTray { } impl Tray for SysTray { + fn icon_name(&self) -> String { + if self.enabled() { + "tailscale-online".into() + } else { + "tailscale-offline".into() + } + } + + fn icon_pixmap(&self) -> Vec { + ResvgRenderer::load_icon(self.enabled()) + } + fn title(&self) -> String { - "Tailscale Tray".into() + "Tailray".into() } fn tool_tip(&self) -> ToolTip { @@ -93,6 +105,9 @@ impl Tray for SysTray { }; ToolTip { + // FIXME: the icon is still not showing up + // ags returns: + // "Error: can't assign "tailscale-online" as icon, it is not a file nor a named icon" icon_name: Default::default(), icon_pixmap: Default::default(), title: format!("Tailscale: {}", state), @@ -100,20 +115,9 @@ impl Tray for SysTray { } } - fn icon_name(&self) -> String { - if self.enabled() { - "tailscale-online".into() - } else { - "tailscale-offline".into() - } - } - - fn icon_pixmap(&self) -> Vec { - // TODO: fix setting icon - ResvgRenderer::load_icon(self.enabled()) - } - fn menu(&self) -> Vec> { + // TODO: build pkexec_exists into pkexec_path by failing early + // if pkexec cannot be found let pkexec_path = get_pkexec_path(); let pkexec_exist: bool = pkexec_found(&pkexec_path); let my_ip = self.ctx.ip.clone(); @@ -128,6 +132,7 @@ impl Tray for SysTray { PeerKind::DNSName(_) => &mut serv_sub, PeerKind::HostName(_) => &mut my_sub, }; + let peer_ip = ip.to_owned(); let peer_title = title.to_owned(); let menu = MenuItem::Standard(StandardItem { @@ -205,15 +210,15 @@ impl Tray for SysTray { } fn watcher_online(&self) { - info!("Wathcer online."); + info!("Watcher online."); } fn watcher_offine(&self) -> bool { - info!("Wathcer offline, shutdown the tray."); + info!("Watcher offline, shutting down the system Tray."); false } fn id(&self) -> String { - "mytray".to_string() + "tailray".to_string() } } diff --git a/src/tray/mod.rs b/src/tray/mod.rs new file mode 100644 index 0000000..b9a0e3e --- /dev/null +++ b/src/tray/mod.rs @@ -0,0 +1 @@ +pub mod menu;