summaryrefslogtreecommitdiffstats
path: root/src/components
diff options
context:
space:
mode:
authorManos Pitsidianakis <el13635@mail.ntua.gr>2020-09-12 21:06:50 +0300
committerManos Pitsidianakis <el13635@mail.ntua.gr>2020-09-12 21:06:50 +0300
commit41664bbe91b7481053c355903d5ea0525e6dd85c (patch)
tree69925638eed84f0ccde3457138d571620e51bbab /src/components
parent4829e13c478021bd96690287509008049b8d8732 (diff)
Don't panic if no dbus notification server is available
Diffstat (limited to 'src/components')
-rw-r--r--src/components/notifications.rs31
1 files changed, 23 insertions, 8 deletions
diff --git a/src/components/notifications.rs b/src/components/notifications.rs
index d3a9a261..685252bf 100644
--- a/src/components/notifications.rs
+++ b/src/components/notifications.rs
@@ -87,7 +87,13 @@ mod dbus {
notification.hint(notify_rust::Hint::SuppressSound(true));
}
- notification.show().unwrap();
+ if let Err(err) = notification.show() {
+ debug!("Could not show dbus notification: {:?}", &err);
+ melib::log(
+ format!("Could not show dbus notification: {}", err),
+ melib::ERROR,
+ );
+ }
}
false
}
@@ -182,13 +188,9 @@ impl Component for NotificationCommand {
if *kind == Some(NotificationType::NEWMAIL) {
if let Some(ref path) = context.settings.notifications.xbiff_file_path {
- let mut file = std::fs::OpenOptions::new().append(true) /* writes will append to a file instead of overwriting previous contents */
- .create(true) /* a new file will be created if the file does not yet already exist.*/
- .open(path).unwrap();
- if file.metadata().unwrap().len() > 128 {
- file.set_len(0).unwrap();
- } else {
- std::io::Write::write_all(&mut file, b"z").unwrap();
+ if let Err(err) = update_xbiff(path) {
+ debug!("Could not update xbiff file: {:?}", &err);
+ melib::log(format!("Could not update xbiff file: {}.", err), ERROR);
}
}
}
@@ -204,3 +206,16 @@ impl Component for NotificationCommand {
fn set_dirty(&mut self, _value: bool) {}
fn set_id(&mut self, _id: ComponentId) {}
}
+
+fn update_xbiff(path: &str) -> Result<()> {
+ let mut file = std::fs::OpenOptions::new()
+ .append(true) /* writes will append to a file instead of overwriting previous contents */
+ .create(true) /* a new file will be created if the file does not yet already exist.*/
+ .open(path)?;
+ if file.metadata()?.len() > 128 {
+ file.set_len(0)?;
+ } else {
+ std::io::Write::write_all(&mut file, b"z")?;
+ }
+ Ok(())
+}