Skip to content

Commit

Permalink
remove unwraps
Browse files Browse the repository at this point in the history
  • Loading branch information
Misieq01 committed Oct 28, 2024
1 parent 463d436 commit 44cd444
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}

Expand Down
22 changes: 16 additions & 6 deletions src-tauri/src/notification_manager.rs
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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(())
}
}
}
Expand Down

0 comments on commit 44cd444

Please sign in to comment.