#[cfg(all(unix, not(target_os = "macos")))]
use notify_rust::Hint;
use notify_rust::{Notification as OsNotification, Timeout};
pub struct Notification;
impl Notification {
pub fn transfer_completed<S: AsRef<str>>(body: S) {
Self::notify(
"Transfer completed ✅",
body.as_ref(),
Some("transfer.complete"),
);
}
pub fn transfer_error<S: AsRef<str>>(body: S) {
Self::notify("Transfer failed ❌", body.as_ref(), Some("transfer.error"));
}
pub fn update_available<S: AsRef<str>>(version: S) {
Self::notify(
"New version available ⬇️",
format!("termscp {} is now available for download", version.as_ref()).as_str(),
None,
);
}
pub fn update_installed<S: AsRef<str>>(version: S) {
Self::notify(
"Update installed 🎉",
format!("termscp {} has been installed! Restart termscp to enjoy the latest version of termscp 🙂", version.as_ref()).as_str(),
None,
);
}
pub fn update_failed<S: AsRef<str>>(err: S) {
Self::notify("Update installation failed ❌", err.as_ref(), None);
}
#[allow(unused_variables)]
fn notify(summary: &str, body: &str, category: Option<&str>) {
let mut notification = OsNotification::new();
notification
.appname(env!("CARGO_PKG_NAME"))
.summary(summary)
.body(body)
.timeout(Timeout::Milliseconds(10000));
#[cfg(all(unix, not(target_os = "macos")))]
if let Some(category) = category {
notification.hint(Hint::Category(category.to_string()));
}
let _ = notification.show();
}
}