Skip to content

Commit

Permalink
Merge pull request #2 from NotAShelf/tray
Browse files Browse the repository at this point in the history
refactor(tray): move to its own module
  • Loading branch information
NotAShelf authored Mar 18, 2024
2 parents bf37cac + 01e4beb commit 8d7d8dc
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/tailscale/status.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
39 changes: 22 additions & 17 deletions src/tray.rs → src/tray/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Icon> {
ResvgRenderer::load_icon(self.enabled())
}

fn title(&self) -> String {
"Tailscale Tray".into()
"Tailray".into()
}

fn tool_tip(&self) -> ToolTip {
Expand All @@ -93,27 +105,19 @@ 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),
description: Default::default(),
}
}

fn icon_name(&self) -> String {
if self.enabled() {
"tailscale-online".into()
} else {
"tailscale-offline".into()
}
}

fn icon_pixmap(&self) -> Vec<Icon> {
// TODO: fix setting icon
ResvgRenderer::load_icon(self.enabled())
}

fn menu(&self) -> Vec<MenuItem<Self>> {
// 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();
Expand All @@ -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 {
Expand Down Expand Up @@ -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()
}
}
1 change: 1 addition & 0 deletions src/tray/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod menu;

0 comments on commit 8d7d8dc

Please sign in to comment.