mirror of
https://github.com/niri-wm/niri.git
synced 2026-06-22 02:01:55 +07:00
Remove notify-rust dependency
It uses outdated zbus.
This commit is contained in:
+3
-1
@@ -4545,7 +4545,9 @@ impl Niri {
|
||||
}
|
||||
|
||||
#[cfg(feature = "dbus")]
|
||||
crate::utils::show_screenshot_notification(image_path);
|
||||
if let Err(err) = crate::utils::show_screenshot_notification(image_path) {
|
||||
warn!("error showing screenshot notification: {err:?}");
|
||||
}
|
||||
#[cfg(not(feature = "dbus"))]
|
||||
drop(image_path);
|
||||
});
|
||||
|
||||
+31
-11
@@ -307,20 +307,20 @@ pub fn center_preferring_top_left_in_area(
|
||||
}
|
||||
|
||||
#[cfg(feature = "dbus")]
|
||||
pub fn show_screenshot_notification(image_path: Option<PathBuf>) {
|
||||
let mut notification = notify_rust::Notification::new();
|
||||
notification
|
||||
.summary("Screenshot captured")
|
||||
.body("You can paste the image from the clipboard.")
|
||||
.urgency(notify_rust::Urgency::Normal)
|
||||
.hint(notify_rust::Hint::Transient(true));
|
||||
pub fn show_screenshot_notification(image_path: Option<PathBuf>) -> anyhow::Result<()> {
|
||||
use std::collections::HashMap;
|
||||
|
||||
use zbus::zvariant;
|
||||
|
||||
let conn = zbus::blocking::Connection::session()?;
|
||||
|
||||
// Try to add the screenshot as an image if possible.
|
||||
let mut image_url = None;
|
||||
if let Some(path) = image_path {
|
||||
match path.canonicalize() {
|
||||
Ok(path) => match url::Url::from_file_path(path) {
|
||||
Ok(url) => {
|
||||
notification.image_path(url.as_str());
|
||||
image_url = Some(url);
|
||||
}
|
||||
Err(err) => {
|
||||
warn!("error converting screenshot path to file url: {err:?}");
|
||||
@@ -332,9 +332,29 @@ pub fn show_screenshot_notification(image_path: Option<PathBuf>) {
|
||||
}
|
||||
}
|
||||
|
||||
if let Err(err) = notification.show() {
|
||||
warn!("error showing screenshot notification: {err:?}");
|
||||
}
|
||||
let actions: &[&str] = &[];
|
||||
|
||||
conn.call_method(
|
||||
Some("org.freedesktop.Notifications"),
|
||||
"/org/freedesktop/Notifications",
|
||||
Some("org.freedesktop.Notifications"),
|
||||
"Notify",
|
||||
&(
|
||||
"niri",
|
||||
0u32,
|
||||
image_url.as_ref().map(|url| url.as_str()).unwrap_or(""),
|
||||
"Screenshot captured",
|
||||
"You can paste the image from the clipboard.",
|
||||
actions,
|
||||
HashMap::from([
|
||||
("transient", zvariant::Value::Bool(true)),
|
||||
("urgency", zvariant::Value::U8(1)),
|
||||
]),
|
||||
-1,
|
||||
),
|
||||
)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[inline(never)]
|
||||
|
||||
Reference in New Issue
Block a user