summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/backup.rs6
-rw-r--r--src/main.rs18
2 files changed, 19 insertions, 5 deletions
diff --git a/src/backup.rs b/src/backup.rs
index b468917..c0621fc 100644
--- a/src/backup.rs
+++ b/src/backup.rs
@@ -13,7 +13,7 @@ use crate::{
13 config::Config, 13 config::Config,
14 error::{Error, Result}, 14 error::{Error, Result},
15 packages::PackageList, 15 packages::PackageList,
16 pathinfo::PathInfo, send_notification, 16 pathinfo::PathInfo, send_notification, Urgency,
17}; 17};
18 18
19pub type Id = String; 19pub type Id = String;
@@ -62,7 +62,7 @@ impl Backup {
62 path.save(&backup_root)?; 62 path.save(&backup_root)?;
63 } 63 }
64 64
65 send_notification("Backup created" , "", notify_rust::Urgency::Normal)?; 65 send_notification("Backup created" , "", Urgency::Normal)?;
66 66
67 Ok(()) 67 Ok(())
68 } 68 }
@@ -126,7 +126,7 @@ impl Backup {
126 path.restore(config, &backup_root)?; 126 path.restore(config, &backup_root)?;
127 } 127 }
128 128
129 send_notification("Backup restored" , "", notify_rust::Urgency::Normal)?; 129 send_notification("Backup restored" , "", Urgency::Normal)?;
130 130
131 Ok(()) 131 Ok(())
132 } 132 }
diff --git a/src/main.rs b/src/main.rs
index ab23ab7..dad98c6 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -3,7 +3,6 @@ use clap::Parser;
3use cli::Subcommands; 3use cli::Subcommands;
4use config::Config; 4use config::Config;
5use error::{Error, Result}; 5use error::{Error, Result};
6use notify_rust::Urgency;
7use tracing::{debug, error, level_filters::LevelFilter}; 6use tracing::{debug, error, level_filters::LevelFilter};
8use tracing_subscriber::{fmt, layer::SubscriberExt, util::SubscriberInitExt, EnvFilter}; 7use tracing_subscriber::{fmt, layer::SubscriberExt, util::SubscriberInitExt, EnvFilter};
9 8
@@ -72,6 +71,21 @@ fn run_cli() -> Result<()> {
72 Ok(()) 71 Ok(())
73} 72}
74 73
74enum Urgency {
75 Normal,
76 Critical
77}
78
79#[cfg(feature = "notifications")]
80impl From<Urgency> for notify_rust::Urgency {
81 fn from(value: Urgency) -> Self {
82 match value {
83 Urgency::Normal => Self::Normal,
84 Urgency::Critical => Self::Critical,
85 }
86 }
87}
88
75fn send_notification(summary: &str, body: &str, urgency: Urgency) -> Result<()> { 89fn send_notification(summary: &str, body: &str, urgency: Urgency) -> Result<()> {
76 #[cfg(feature = "notifications")] 90 #[cfg(feature = "notifications")]
77 { 91 {
@@ -86,7 +100,7 @@ fn send_notification(summary: &str, body: &str, urgency: Urgency) -> Result<()>
86 .body(body) 100 .body(body)
87 .icon(&icon.to_string_lossy()) 101 .icon(&icon.to_string_lossy())
88 .timeout(0) 102 .timeout(0)
89 .urgency(urgency) 103 .urgency(urgency.into())
90 .show()?; 104 .show()?;
91 } 105 }
92 Ok(()) 106 Ok(())