use crate::error;
use crate::error::StatusNotifierWatcherError;
#[derive(Debug)]
pub(crate) struct NotifierAddress {
pub(crate) destination: String,
pub(crate) path: String,
}
impl NotifierAddress {
pub(crate) fn from_notifier_service(service: &str) -> error::Result<Self> {
if let Some((destination, path)) = service.split_once('/') {
Ok(NotifierAddress {
destination: destination.to_string(),
path: format!("/{}", path),
})
} else if service.contains(':') {
let split = service.split(':').collect::<Vec<&str>>();
Ok(NotifierAddress {
destination: format!(":{}", split[1]),
path: "/StatusNotifierItem".to_string(),
})
} else {
Err(StatusNotifierWatcherError::DbusAddressError(
service.to_string(),
))
}
}
}