Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
fix(linux): safely deliver screenshot and automation notifications
Richie McIlroy42484de1a398
diff --git a/Cargo.lock b/Cargo.lockindex 0aa200420..ebda8bf77 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -1485,6 +1485,7 @@ dependencies = ["lz4_flex","md5","nix 0.29.0",+ "notify-rust","objc","objc2 0.6.2","objc2-app-kit 0.3.1",diff --git a/apps/desktop/src-tauri/Cargo.toml b/apps/desktop/src-tauri/Cargo.tomlindex 953b9fc17..8f0ebdc60 100644--- a/apps/desktop/src-tauri/Cargo.toml+++ b/apps/desktop/src-tauri/Cargo.toml@@ -153,6 +153,7 @@ parakeet-rs = "0.3.4"[target.'cfg(target_os = "linux")'.dependencies]libappindicator = "0.9.0"+notify-rust = "4.11"[target.'cfg(target_os= "windows")'.dependencies]windows = { workspace = true, features = [diff --git a/apps/desktop/src-tauri/src/automation.rs b/apps/desktop/src-tauri/src/automation.rsindex a05f0a030..abf41047e 100644--- a/apps/desktop/src-tauri/src/automation.rs+++ b/apps/desktop/src-tauri/src/automation.rs@@ -4,6 +4,7 @@ use cap_automation::{Trigger, TriggerContext, sanitize_filename_component,};use cap_recording::sources::screen_capture::ScreenCaptureTarget;+#[cfg(not(target_os = "linux"))]use clipboard_rs::Clipboard;use clipboard_rs::common::RustImage;use serde_json::json;@@ -426,6 +427,7 @@ impl AutomationHost for DesktopAutomationHost {title_template: &str,body_template: &str,) -> Result<(), String> {+ #[cfg(not(target_os = "linux"))]use tauri_plugin_notification::NotificationExt;let enabled = crate::general_settings::GeneralSettingsStore::get(&self.app)@@ -439,6 +441,10 @@ impl AutomationHost for DesktopAutomationHost {let title = apply_body_template(&apply_filename_template(title_template, ctx), ctx);let body = apply_body_template(&apply_filename_template(body_template, ctx), ctx);+ #[cfg(target_os = "linux")]+ crate::notifications::show_linux_notification(&title, &body).await?;++ #[cfg(not(target_os = "linux"))]self.app.notification().builder()diff --git a/apps/desktop/src-tauri/src/notifications.rs b/apps/desktop/src-tauri/src/notifications.rsindex d872fd838..be0d16563 100644--- a/apps/desktop/src-tauri/src/notifications.rs+++ b/apps/desktop/src-tauri/src/notifications.rs@@ -1,4 +1,5 @@use crate::{AppSounds, general_settings::GeneralSettingsStore};+#[cfg(not(target_os = "linux"))]use tauri_plugin_notification::NotificationExt;#[allow(unused)]@@ -99,6 +100,14 @@ pub fn send_notification(app: &tauri::AppHandle, notification_type: Notificationlet (title, body, _is_error) = notification_type.details();+ #[cfg(target_os = "linux")]+ tauri::async_runtime::spawn(async move {+ if let Err(error) = show_linux_notification(title, body).await {+ tracing::warn!(%error, "Failed to send notification");+ }+ });++ #[cfg(not(target_os = "linux"))]app.notification().builder().title(title)@@ -118,3 +127,34 @@ pub fn send_notification(app: &tauri::AppHandle, notification_type: NotificationAppSounds::Notification.play();}}++#[cfg(target_os = "linux")]+fn build_linux_notification(title: &str, body: &str) -> notify_rust::Notification {+ let mut notification = notify_rust::Notification::new();+ notification.summary(title).body(body).auto_icon();+ notification+}++#[cfg(target_os = "linux")]+pub(crate) async fn show_linux_notification(title: &str, body: &str) -> Result<(), String> {+ build_linux_notification(title, body)+ .show_async()+ .await+ .map(|_| ())+ .map_err(|error| format!("Failed to send notification: {error}"))+}++#[cfg(all(test, target_os = "linux"))]+mod tests {+ use super::build_linux_notification;++ #[test]+ fn linux_notification_preserves_content_and_application_icon() {+ let notification = build_linux_notification("Screenshot Saved", "Saved successfully");++ assert_eq!(notification.summary, "Screenshot Saved");+ assert_eq!(notification.body, "Saved successfully");+ assert_eq!(notification.icon, notification.appname);+ assert!(!notification.icon.is_empty());+ }+}