From dde62f887ed2908e2d951f2b6770cf255a630e97 Mon Sep 17 00:00:00 2001 From: Reactor Scram Date: Mon, 29 Apr 2024 16:20:36 -0500 Subject: [PATCH] chore(linux GUI): enable update notifications (#4820) Closes #4815 image You can copy-paste the URL, which is better than nothing. We could also put an update nag in the tray menu if we really wanted, it would be easy to catch the click from that. --- rust/gui-client/src-tauri/src/client/gui.rs | 11 +++----- .../src-tauri/src/client/gui/os_linux.rs | 27 +++++++------------ .../src-tauri/src/client/gui/os_windows.rs | 20 +++++++++----- 3 files changed, 27 insertions(+), 31 deletions(-) diff --git a/rust/gui-client/src-tauri/src/client/gui.rs b/rust/gui-client/src-tauri/src/client/gui.rs index 5038ce404..91053ff55 100644 --- a/rust/gui-client/src-tauri/src/client/gui.rs +++ b/rust/gui-client/src-tauri/src/client/gui.rs @@ -468,6 +468,8 @@ fn handle_system_tray_event(app: &tauri::AppHandle, event: TrayMenuEvent) -> Res Ok(()) } +// Allow dead code because `UpdateNotificationClicked` doesn't work on Linux yet +#[allow(dead_code)] pub(crate) enum ControllerRequest { /// The GUI wants us to use these settings in-memory, they've already been saved to disk ApplySettings(AdvancedSettings), @@ -615,7 +617,7 @@ impl Controller { if let Some(req) = self.auth.start_sign_in()? { let url = req.to_url(&self.advanced_settings.auth_base_url); self.refresh_system_tray_menu()?; - os::open_url(&self.app, &url)?; + tauri::api::shell::open(&self.app.shell_scope(), url.expose_secret(), None)?; self.app .get_window("welcome") .context("Couldn't get handle to Welcome window")? @@ -675,12 +677,7 @@ impl Controller { // We don't need to route through the controller here either, we could // use the `open` crate directly instead of Tauri's wrapper // `tauri::api::shell::open` - os::show_clickable_notification( - &title, - "Click here to download the new version.", - self.ctlr_tx.clone(), - Req::UpdateNotificationClicked(release.download_url), - )?; + os::show_update_notification(self.ctlr_tx.clone(), &title, release.download_url)?; } Req::UpdateNotificationClicked(download_url) => { tracing::info!("UpdateNotificationClicked in run_controller!"); diff --git a/rust/gui-client/src-tauri/src/client/gui/os_linux.rs b/rust/gui-client/src-tauri/src/client/gui/os_linux.rs index f5d2aa5a6..9315e7cde 100644 --- a/rust/gui-client/src-tauri/src/client/gui/os_linux.rs +++ b/rust/gui-client/src-tauri/src/client/gui/os_linux.rs @@ -1,11 +1,14 @@ -use super::{ControllerRequest, CtlrTx}; use anyhow::Result; -use secrecy::{ExposeSecret, SecretString}; -use tauri::{api::notification::Notification, Manager}; +use tauri::api::notification::Notification; -/// Open a URL in the user's default browser -pub(crate) fn open_url(app: &tauri::AppHandle, url: &SecretString) -> Result<()> { - tauri::api::shell::open(&app.shell_scope(), url.expose_secret(), None)?; +/// Since clickable notifications don't work on Linux yet, the update text +/// must be different on different platforms +pub(crate) fn show_update_notification( + _ctlr_tx: super::CtlrTx, + title: &str, + download_url: url::Url, +) -> Result<()> { + show_notification(title, download_url.to_string().as_ref())?; Ok(()) } @@ -17,15 +20,3 @@ pub(crate) fn show_notification(title: &str, body: &str) -> Result<()> { .show()?; Ok(()) } - -/// Show a notification that signals `Controller` when clicked -pub(crate) fn show_clickable_notification( - _title: &str, - _body: &str, - _tx: CtlrTx, - _req: ControllerRequest, -) -> Result<()> { - // TODO: Tauri doesn't seem to have clickable notifications on Linux. - // No indication if it'll be in 2.x or if there's a good third-party replacement - Ok(()) -} diff --git a/rust/gui-client/src-tauri/src/client/gui/os_windows.rs b/rust/gui-client/src-tauri/src/client/gui/os_windows.rs index 47fa88ce5..9ce36137d 100644 --- a/rust/gui-client/src-tauri/src/client/gui/os_windows.rs +++ b/rust/gui-client/src-tauri/src/client/gui/os_windows.rs @@ -1,12 +1,20 @@ use super::{ControllerRequest, CtlrTx}; use anyhow::{Context, Result}; use connlib_shared::BUNDLE_ID; -use secrecy::{ExposeSecret, SecretString}; -use tauri::Manager; -/// Open a URL in the user's default browser -pub(crate) fn open_url(app: &tauri::AppHandle, url: &SecretString) -> Result<()> { - tauri::api::shell::open(&app.shell_scope(), url.expose_secret(), None)?; +/// Since clickable notifications don't work on Linux yet, the update text +/// must be different on different platforms +pub(crate) fn show_update_notification( + ctlr_tx: CtlrTx, + title: &str, + download_url: url::Url, +) -> Result<()> { + show_clickable_notification( + title, + "Click here to download the new version.", + ctlr_tx, + ControllerRequest::UpdateNotificationClicked(download_url), + )?; Ok(()) } @@ -70,6 +78,6 @@ pub(crate) fn show_clickable_notification( Ok(()) }) .show() - .context("Couldn't show clickable notification")?; + .context("Couldn't show clickable URL notification")?; Ok(()) }