From b8aa9fcc9d05f3634f13c0f88bac3c3a67b0f942 Mon Sep 17 00:00:00 2001 From: Reactor Scram Date: Thu, 11 Jan 2024 12:16:06 -0600 Subject: [PATCH] feat(windows): When the tunnel is ready, show a notification (#3166) This is handy since the systray icon is hidden by default: ![image](https://github.com/firezone/firezone/assets/13400041/7c434538-8baf-46ca-92db-1fea97e84f41) --------- Signed-off-by: Reactor Scram Co-authored-by: Jamil --- rust/Cargo.lock | 56 +++++++++++++++++-- rust/windows-client/src-tauri/Cargo.toml | 2 +- .../src-tauri/src/client/gui.rs | 14 ++++- 3 files changed, 64 insertions(+), 8 deletions(-) diff --git a/rust/Cargo.lock b/rust/Cargo.lock index eaada709a..02fdec8a3 100755 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -2620,9 +2620,9 @@ dependencies = [ [[package]] name = "h2" -version = "0.3.22" +version = "0.3.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d6250322ef6e60f93f9a2162799302cd6f68f79f6e5d85c8c16f14d1d958178" +checksum = "b553656127a00601c8ae5590fcfdc118e4083a7924b6cf4ffc1ea4b99dc429d7" dependencies = [ "bytes", "fnv", @@ -3407,6 +3407,19 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4" +[[package]] +name = "mac-notification-sys" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51fca4d74ff9dbaac16a01b924bc3693fa2bba0862c2c633abc73f9a8ea21f64" +dependencies = [ + "cc", + "dirs-next", + "objc-foundation", + "objc_id", + "time", +] + [[package]] name = "malloc_buf" version = "0.0.6" @@ -3693,6 +3706,19 @@ dependencies = [ "minimal-lexical", ] +[[package]] +name = "notify-rust" +version = "4.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "827c5edfa80235ded4ab3fe8e9dc619b4f866ef16fe9b1c6b8a7f8692c0f2226" +dependencies = [ + "log", + "mac-notification-sys", + "serde", + "tauri-winrt-notification", + "zbus", +] + [[package]] name = "nu-ansi-term" version = "0.46.0" @@ -4376,7 +4402,7 @@ dependencies = [ "base64 0.21.6", "indexmap 2.1.0", "line-wrap", - "quick-xml", + "quick-xml 0.31.0", "serde", "time", ] @@ -4614,6 +4640,15 @@ version = "1.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" +[[package]] +name = "quick-xml" +version = "0.30.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eff6510e86862b57b210fd8cbe8ed3f0d7d600b9c2863cd4549a2e033c66e956" +dependencies = [ + "memchr", +] + [[package]] name = "quick-xml" version = "0.31.0" @@ -6004,6 +6039,7 @@ dependencies = [ "heck 0.4.1", "http", "ignore", + "notify-rust", "objc", "once_cell", "open", @@ -6173,6 +6209,16 @@ dependencies = [ "toml 0.7.8", ] +[[package]] +name = "tauri-winrt-notification" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "006851c9ccefa3c38a7646b8cec804bb429def3da10497bfa977179869c3e8e2" +dependencies = [ + "quick-xml 0.30.0", + "windows 0.51.1", +] + [[package]] name = "tempfile" version = "3.9.0" @@ -7845,9 +7891,9 @@ checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" [[package]] name = "winnow" -version = "0.5.33" +version = "0.5.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7520bbdec7211caa7c4e682eb1fbe07abe20cee6756b6e00f537c82c11816aa" +checksum = "b7cf47b659b318dccbd69cc4797a39ae128f533dce7902a1096044d1967b9c16" dependencies = [ "memchr", ] diff --git a/rust/windows-client/src-tauri/Cargo.toml b/rust/windows-client/src-tauri/Cargo.toml index af6a17f45..2e3c4144f 100755 --- a/rust/windows-client/src-tauri/Cargo.toml +++ b/rust/windows-client/src-tauri/Cargo.toml @@ -46,7 +46,7 @@ windows-implement = "0.52.0" [target.'cfg(windows)'.dependencies] # Tauri works fine on Linux, but it requires a lot of build-time deps like glib and gdk, so I've blocked it out for now. -tauri = { version = "1.5", features = [ "dialog", "shell-open-api", "system-tray" ] } +tauri = { version = "1.5", features = [ "dialog", "notification", "shell-open-api", "system-tray" ] } tauri-utils = "1.5.1" winreg = "0.51.0" wintun = "0.3.2" diff --git a/rust/windows-client/src-tauri/src/client/gui.rs b/rust/windows-client/src-tauri/src/client/gui.rs index f2af7fa1b..4b260ec0c 100755 --- a/rust/windows-client/src-tauri/src/client/gui.rs +++ b/rust/windows-client/src-tauri/src/client/gui.rs @@ -15,7 +15,7 @@ use connlib_shared::messages::ResourceId; use secrecy::{ExposeSecret, SecretString}; use std::{net::IpAddr, path::PathBuf, str::FromStr, sync::Arc, time::Duration}; use system_tray_menu::Event as TrayMenuEvent; -use tauri::{Manager, SystemTray, SystemTrayEvent}; +use tauri::{api::notification::Notification, Manager, SystemTray, SystemTrayEvent}; use tokio::sync::{mpsc, oneshot, Notify}; use ControllerRequest as Req; @@ -219,6 +219,7 @@ pub(crate) enum ControllerRequest { SignIn, StartStopLogCounting(bool), SignOut, + TunnelReady, } #[derive(Clone)] @@ -251,12 +252,13 @@ impl connlib_client_shared::Callbacks for CallbackHandler { } fn on_tunnel_ready(&self) -> Result<(), Self::Error> { - // TODO: implement tracing::info!("on_tunnel_ready"); + self.ctlr_tx.try_send(ControllerRequest::TunnelReady)?; Ok(()) } fn on_update_resources(&self, resources: Vec) -> Result<(), Self::Error> { + tracing::info!("on_update_resources"); self.resources.store(resources.into()); self.notify_controller.notify_one(); Ok(()) @@ -493,6 +495,14 @@ async fn run_controller( tracing::debug!("cancelled log counting"); } } + Req::TunnelReady => { + // May say "Windows Powershell" in dev mode + // See https://github.com/tauri-apps/tauri/issues/3700 + Notification::new(&controller.app.config().tauri.bundle.identifier) + .title("Firezone connected") + .body("You are now signed in and able to access resources.") + .show()?; + }, } } }