Skip to content

Commit

Permalink
Merge pull request #6 from fufexan/icons
Browse files Browse the repository at this point in the history
Add icons, improve notifications
  • Loading branch information
NotAShelf authored Jul 12, 2024
2 parents b380a78 + e9f5274 commit 304f19d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
18 changes: 12 additions & 6 deletions src/tailscale/peer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,29 @@ pub fn check_peer_ip(peer_ip: &str) {
}
}

pub fn copy_peer_ip(peer_ip: &str, notif_title: &str) -> Result<(), Box<dyn std::error::Error>> {
pub fn copy_peer_ip(
peer_ip: &str,
notif_body: &str,
host: bool,
) -> Result<(), Box<dyn std::error::Error>> {
check_peer_ip(peer_ip);

copy_to_clipboard(peer_ip)?;

// Get IP from clipboard to verify
let clip_ip = get_from_clipboard()?;

// Create summary for host/peer
let summary = format!("Copied {} IP address", if host { "host" } else { "peer" });

// log success
info!("Copied IP address {} to the clipboard", clip_ip);
info!("{} {} to the clipboard", summary, clip_ip);

// send a notification through dbus
let body = format!("Copied IP address {} to the clipboard", clip_ip);
Notification::new()
.summary(notif_title)
.body(&body)
.icon("info")
.summary(&summary)
.body(&notif_body)
.icon("tailscale")
.show()?;

Ok(())
Expand Down
24 changes: 15 additions & 9 deletions src/tray/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,23 +129,26 @@ impl Tray for SysTray {
fn menu(&self) -> Vec<MenuItem<Self>> {
let my_ip = self.ctx.ip.clone();

let message = format!(
"This device: {} ({})",
self.ctx.status.this_machine.display_name, self.ctx.ip
);

let mut my_sub = Vec::new();
let mut serv_sub = Vec::new();
for (_, peer) in self.ctx.status.peers.iter() {
let ip = peer.ips[0].clone();
let name = &peer.display_name;
let title = name.to_string();
let sub = match name {
PeerKind::DNSName(_) => &mut serv_sub,
PeerKind::HostName(_) => &mut my_sub,
};

let peer_ip = ip.to_owned();
let peer_title = title.to_owned();
let peer_title = format!("{} ({})", name, ip);
let menu = MenuItem::Standard(StandardItem {
label: format!("{}\t({})", title, ip),
label: format!("{}\t({})", name, ip),
activate: Box::new(move |_: &mut Self| {
if let Err(e) = copy_peer_ip(&peer_ip, &peer_title) {
if let Err(e) = copy_peer_ip(&ip, &peer_title, false) {
eprintln!("failed to copy peer ip: {}", e);
}
}),
Expand All @@ -156,7 +159,7 @@ impl Tray for SysTray {
vec![
StandardItem {
label: "Connect".into(),
icon_name: "network-transmit-receive".into(),
icon_name: "network-transmit-receive-symbolic".into(),
enabled: !self.enabled(),
visible: true,
activate: Box::new(|this: &mut Self| {
Expand All @@ -169,7 +172,7 @@ impl Tray for SysTray {
.into(),
StandardItem {
label: "Disconnect".into(),
icon_name: "network-offline".into(),
icon_name: "network-offline-symbolic".into(),
enabled: self.enabled(),
visible: true,
activate: Box::new(|this: &mut Self| {
Expand All @@ -186,8 +189,9 @@ impl Tray for SysTray {
"This device: {} ({})",
self.ctx.status.this_machine.display_name, self.ctx.ip
),
icon_name: "computer-symbolic".into(),
activate: Box::new(move |_| {
if let Err(e) = copy_peer_ip(&my_ip, "Peer IP copied to clipboard!") {
if let Err(e) = copy_peer_ip(&my_ip, message.as_str(), true) {
eprintln!("failed to copy ip for this device: {}", e);
}
}),
Expand All @@ -196,6 +200,7 @@ impl Tray for SysTray {
.into(),
SubMenu {
label: "Network Devices".into(),
icon_name: "network-wired-symbolic".into(),
submenu: vec![
SubMenu {
label: "My Devices".into(),
Expand All @@ -214,7 +219,8 @@ impl Tray for SysTray {
}
.into(),
StandardItem {
label: "Admin Console…".into(),
label: "Admin Console".into(),
icon_name: "applications-system-symbolic".into(),
activate: Box::new(|_| {
let admin_url = std::env::var("TAILRAY_ADMIN_URL").unwrap_or_else(|_| {
"https://login.tailscale.com/admin/machines".to_string()
Expand Down

0 comments on commit 304f19d

Please sign in to comment.