Medlar/crates/app/src/launcher.rs

31 lines
1.2 KiB
Rust

//! Progress on the dock or launcher icon, through the Unity launcher entry signal that KDE, GNOME's dash-to-dock and
//! others read. Nothing happens when there is no session bus.
use std::collections::HashMap;
use zbus::blocking::Connection;
use zbus::zvariant::Value;
const URI: &str = "application://medlar.desktop";
pub struct Launcher {
conn: Connection,
}
impl Launcher {
pub fn start() -> Option<Launcher> {
Connection::session().ok().map(|conn| Launcher { conn })
}
/// `progress` 0 to 1, None to hide the bar; `count` shows as the badge when above 0.
pub fn set(&self, progress: Option<f64>, count: usize) {
let mut props: HashMap<&str, Value> = HashMap::new();
props.insert("progress", Value::from(progress.unwrap_or(0.0)));
props.insert("progress-visible", Value::from(progress.is_some()));
props.insert("count", Value::from(count as i64));
props.insert("count-visible", Value::from(count > 0));
let sent = self.conn.emit_signal(None::<&str>, "/com/canonical/unity/launcherentry/medlar", "com.canonical.Unity.LauncherEntry", "Update", &(URI, props));
if let Err(e) = sent {
log::debug!("launcher: {e}");
}
}
}