From 8f6f7674797c9b854878a16f65cead8d77fed351 Mon Sep 17 00:00:00 2001 From: Felix Ortmann Date: Tue, 20 Apr 2021 15:50:58 +0200 Subject: [PATCH] Print error message instead of crashing --- src/main.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 602e529..0ed3266 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,8 +1,8 @@ use clap::{App, Arg}; use crossbeam_channel::{select, tick}; use notify_rust::{Notification, Urgency}; -use std::{fs, path, process}; use std::time::Duration; +use std::{fs, path, process}; #[tokio::main] async fn main() { @@ -82,14 +82,17 @@ async fn main() { // Puts a notification to the D-Bus fn send_notification(bat_name: String, cap: i8, icon: &str, timeout: i32) { - Notification::new() + match Notification::new() .summary(&format!("Battery {} - {}%", bat_name, cap)) .body("Charge your battery soon to avoid shutdown") .icon(icon) .urgency(Urgency::Critical) .timeout(timeout) .show() - .unwrap(); + { + Ok(_) => (), + Err(err) => println!("Error sending notification: {}", err), + }; } // Periodically checks the battery status and sends notifications to the user if