From 44cd444abc5008920ba75d58899cd5e9ba653f57 Mon Sep 17 00:00:00 2001 From: Misieq01 Date: Mon, 28 Oct 2024 08:59:27 +0100 Subject: [PATCH] remove unwraps --- src-tauri/src/main.rs | 2 +- src-tauri/src/notification_manager.rs | 22 ++++++++++++++++------ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 36a636e77..447088a5e 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -1070,7 +1070,7 @@ async fn get_seed_words( #[tauri::command] async fn trigger_notification(summary: &str, body: &str) -> Result<(), String> { - NotificationManager::current().trigger_notification(summary, body); + let _ = NotificationManager::current().trigger_notification(summary, body); Ok(()) } diff --git a/src-tauri/src/notification_manager.rs b/src-tauri/src/notification_manager.rs index 7c52757e7..c809be0cb 100644 --- a/src-tauri/src/notification_manager.rs +++ b/src-tauri/src/notification_manager.rs @@ -1,8 +1,8 @@ +use anyhow::Error; +use log::{info, warn}; use notify_rust::Notification; use std::sync::LazyLock; -use log::info; - use crate::utils::platform_utils::{CurrentOperatingSystem, PlatformUtils}; const LOG_TARGET: &str = "tari::universe::notification_manager"; @@ -15,24 +15,34 @@ impl NotificationManager { Self {} } - pub fn trigger_notification(&self, summary: &str, body: &str) { + pub fn trigger_notification(&self, summary: &str, body: &str) -> Result<(), Error> { info!(target: LOG_TARGET, "Triggering notification with summary: {} and body: {}", summary, body); let notification = self.build_notification(summary, body); match PlatformUtils::detect_current_os() { CurrentOperatingSystem::Linux => { #[cfg(target_os = "linux")] - notification.show().unwrap().on_close(|notification| { + let handle = notification.show().inspect_err( + |e| warn!(target: LOG_TARGET, "Failed to show notification: {:?}", e), + )?; + handle.on_close(|notification| { info!(target: LOG_TARGET, "Notification closed: {:?}", notification); }); + Ok(()) } CurrentOperatingSystem::MacOS => { #[cfg(target_os = "macos")] - notification.show().unwrap(); + notification.show().inspect_err( + |e| warn!(target: LOG_TARGET, "Failed to show notification: {:?}", e), + )?; + Ok(()) } CurrentOperatingSystem::Windows => { #[cfg(target_os = "windows")] - notification.show().unwrap(); + notification.show().inspect_err( + |e| warn!(target: LOG_TARGET, "Failed to show notification: {:?}", e), + )?; + Ok(()) } } }