Debian Codegraph @

src/xdg/mod.rs

raw symbols SCIP
1 //! This module contains `XDG` and `DBus` specific code.
2 //!
3 //! it should not be available under any platform other than `(unix, not(target_os = "macos"))`
4
5 #[cfg(feature = "dbus")]
6 use dbusrust-analyzer cargo dbus 0.9.12 crate/::ffidisprust-analyzer cargo dbus 0.9.12 ffidisp/::Connectionrust-analyzer cargo dbus 0.9.12 ffidisp/connection/Connection# as DbusConnectionrust-analyzer cargo dbus 0.9.12 ffidisp/connection/Connection#;
7 #[cfg(feature = "zbus")]
8 use zbusrust-analyzer cargo zbus 5.19.0 crate/::{block_onrust-analyzer cargo zbus 5.19.0 utils/block_on()., zvariantrust-analyzer cargo zvariant 5.15.0 crate/};
9
10 use craterust-analyzer cargo notify-rust 4.18.0 crate/::{errorrust-analyzer cargo notify-rust 4.18.0 error/::*, notificationrust-analyzer cargo notify-rust 4.18.0 notification/::Notificationrust-analyzer cargo notify-rust 4.18.0 notification/Notification#};
11
12 pub use craterust-analyzer cargo notify-rust 4.18.0 crate/::responserust-analyzer cargo notify-rust 4.18.0 response/::ActionResponserust-analyzer cargo notify-rust 4.18.0 response/ActionResponse#;
13 pub use craterust-analyzer cargo notify-rust 4.18.0 crate/::responserust-analyzer cargo notify-rust 4.18.0 response/::{CloseHandlerrust-analyzer cargo notify-rust 4.18.0 response/CloseHandler#, NotificationResponserust-analyzer cargo notify-rust 4.18.0 response/NotificationResponse#, ResponseHandlerrust-analyzer cargo notify-rust 4.18.0 response/ResponseHandler#};
14
15 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::opsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/::{Derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#, DerefMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/DerefMut#};
16
17 #[cfg(feature = "dbus")]
18 mod dbus_rsrust-analyzer cargo notify-rust 4.18.0 xdg/dbus_rs/;
19 #[cfg(all(feature = "dbus", not(feature = "zbus")))]
20 use dbus_rsrust-analyzer cargo notify-rust 4.18.0 xdg/dbus_rs/::busrust-analyzer cargo notify-rust 4.18.0 xdg/dbus_rs/bus/;
21
22 #[cfg(feature = "zbus")]
23 mod zbus_rsrust-analyzer cargo notify-rust 4.18.0 xdg/zbus_rs/;
24 #[cfg(all(feature = "zbus", not(feature = "dbus")))]
25 use zbus_rsrust-analyzer cargo notify-rust 4.18.0 xdg/zbus_rs/::busrust-analyzer cargo notify-rust 4.18.0 xdg/zbus_rs/bus/;
26
27 #[cfg(all(feature = "dbus", feature = "zbus"))]
28 mod busrust-analyzer cargo notify-rust 4.18.0 xdg/bus/;
29
30 // #[cfg(all(feature = "server", feature = "dbus", unix, not(target_os = "macos")))]
31 // pub mod server_dbus;
32
33 // #[cfg(all(feature = "server", feature = "zbus", unix, not(target_os = "macos")))]
34 // pub mod server_zbus;
35
36 // #[cfg(all(feature = "server", unix, not(target_os = "macos")))]
37 // pub mod server;
38
39 #[cfg(not(feature = "debug_namespace"))]
40 #[doc(hidden)]
41 pub static NOTIFICATION_DEFAULT_BUS: &str = "org.freedesktop.Notifications";
42
43 #[cfg(feature = "debug_namespace")]
44 #[doc(hidden)]
45 // #[deprecated]
46 pub static NOTIFICATION_DEFAULT_BUSrust-analyzer cargo notify-rust 4.18.0 xdg/NOTIFICATION_DEFAULT_BUS.: &str = "de.hoodie.Notifications";
47
48 #[doc(hidden)]
49 pub static NOTIFICATION_INTERFACErust-analyzer cargo notify-rust 4.18.0 xdg/NOTIFICATION_INTERFACE.: &str = "org.freedesktop.Notifications";
50
51 #[doc(hidden)]
52 pub static NOTIFICATION_OBJECTPATHrust-analyzer cargo notify-rust 4.18.0 xdg/NOTIFICATION_OBJECTPATH.: &str = "/org/freedesktop/Notifications";
53
54 pub(craterust-analyzer cargo notify-rust 4.18.0 crate/) use busrust-analyzer cargo notify-rust 4.18.0 xdg/bus/::NotificationBusrust-analyzer cargo notify-rust 4.18.0 xdg/bus/NotificationBus#;
55
56 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
57 enum NotificationHandleInnerrust-analyzer cargo notify-rust 4.18.0 xdg/NotificationHandleInner# {
58 #[cfg(feature = "dbus")]
59 Dbusrust-analyzer cargo notify-rust 4.18.0 xdg/NotificationHandleInner#Dbus#(dbus_rsrust-analyzer cargo notify-rust 4.18.0 xdg/dbus_rs/::DbusNotificationHandlerust-analyzer cargo notify-rust 4.18.0 xdg/dbus_rs/DbusNotificationHandle#),
60
61 #[cfg(feature = "zbus")]
62 Zbusrust-analyzer cargo notify-rust 4.18.0 xdg/NotificationHandleInner#Zbus#(zbus_rsrust-analyzer cargo notify-rust 4.18.0 xdg/zbus_rs/::ZbusNotificationHandlerust-analyzer cargo notify-rust 4.18.0 xdg/zbus_rs/ZbusNotificationHandle#),
63 }
64
65 /// A handle to a shown notification.
66 ///
67 /// Keeps a connection alive to ensure actions work on certain desktops.
68 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
69 pub struct NotificationHandlerust-analyzer cargo notify-rust 4.18.0 xdg/NotificationHandle# {
70 innerrust-analyzer cargo notify-rust 4.18.0 xdg/NotificationHandle#inner.: NotificationHandleInnerrust-analyzer cargo notify-rust 4.18.0 xdg/NotificationHandleInner#,
71 }
72
73 #[allow(dead_code)]
74 impl NotificationHandlerust-analyzer cargo notify-rust 4.18.0 xdg/NotificationHandle# {
75 #[cfg(feature = "dbus")]
76 pub(craterust-analyzer cargo notify-rust 4.18.0 crate/) fn for_dbusrust-analyzer cargo notify-rust 4.18.0 xdg/impl#[NotificationHandle]for_dbus().(
77 id: u32,
78 connection: DbusConnectionrust-analyzer cargo dbus 0.9.12 ffidisp/connection/Connection#,
79 notification: Notificationrust-analyzer cargo notify-rust 4.18.0 notification/Notification#,
80 ) -> NotificationHandlerust-analyzer cargo notify-rust 4.18.0 xdg/NotificationHandle# {
81 NotificationHandlerust-analyzer cargo notify-rust 4.18.0 xdg/NotificationHandle# {
82 innerrust-analyzer cargo notify-rust 4.18.0 xdg/NotificationHandle#inner.: dbus_rsrust-analyzer cargo notify-rust 4.18.0 xdg/dbus_rs/::DbusNotificationHandlerust-analyzer cargo notify-rust 4.18.0 xdg/dbus_rs/DbusNotificationHandle#::newrust-analyzer cargo notify-rust 4.18.0 xdg/dbus_rs/impl#[DbusNotificationHandle]new().(id, connection, notification).intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(),
83 }
84 }
85
86 #[cfg(feature = "zbus")]
87 pub(craterust-analyzer cargo notify-rust 4.18.0 crate/) fn for_zbusrust-analyzer cargo notify-rust 4.18.0 xdg/impl#[NotificationHandle]for_zbus().(
88 id: u32,
89 connection: zbusrust-analyzer cargo zbus 5.19.0 crate/::Connectionrust-analyzer cargo zbus 5.19.0 connection/Connection#,
90 notification: Notificationrust-analyzer cargo notify-rust 4.18.0 notification/Notification#,
91 ) -> NotificationHandlerust-analyzer cargo notify-rust 4.18.0 xdg/NotificationHandle# {
92 NotificationHandlerust-analyzer cargo notify-rust 4.18.0 xdg/NotificationHandle# {
93 innerrust-analyzer cargo notify-rust 4.18.0 xdg/NotificationHandle#inner.: zbus_rsrust-analyzer cargo notify-rust 4.18.0 xdg/zbus_rs/::ZbusNotificationHandlerust-analyzer cargo notify-rust 4.18.0 xdg/zbus_rs/ZbusNotificationHandle#::newrust-analyzer cargo notify-rust 4.18.0 xdg/zbus_rs/impl#[ZbusNotificationHandle]new().(id, connection, notification).intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(),
94 }
95 }
96
97 /// Waits for the user to act on a notification and then calls
98 /// `invocation_closure` with the name of the corresponding action.
99 pub fn wait_for_actionrust-analyzer cargo notify-rust 4.18.0 xdg/impl#[NotificationHandle]wait_for_action().<F>(self, invocation_closure: F)
100 where
101 F: FnOncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnOnce#(&str),
102 {
103 match self.innerrust-analyzer cargo notify-rust 4.18.0 xdg/NotificationHandle#inner. {
104 #[cfg(feature = "dbus")]
105 NotificationHandleInnerrust-analyzer cargo notify-rust 4.18.0 xdg/NotificationHandleInner#::Dbusrust-analyzer cargo notify-rust 4.18.0 xdg/NotificationHandleInner#Dbus#(inner) => {
106 let _ = inner.wait_for_actionrust-analyzer cargo notify-rust 4.18.0 xdg/dbus_rs/impl#[DbusNotificationHandle]wait_for_action().(|response: &NotificationResponserust-analyzer cargo notify-rust 4.18.0 response/NotificationResponse#| match response {
107 NotificationResponserust-analyzer cargo notify-rust 4.18.0 response/NotificationResponse#::Defaultrust-analyzer cargo notify-rust 4.18.0 response/NotificationResponse#Default# => invocation_closure("default"),
108 NotificationResponserust-analyzer cargo notify-rust 4.18.0 response/NotificationResponse#::Actionrust-analyzer cargo notify-rust 4.18.0 response/NotificationResponse#Action#(ref action) => invocation_closure(action),
109 NotificationResponserust-analyzer cargo notify-rust 4.18.0 response/NotificationResponse#::Replyrust-analyzer cargo notify-rust 4.18.0 response/NotificationResponse#Reply#(_) => { /* XDG does not support inline replies */ }
110 NotificationResponserust-analyzer cargo notify-rust 4.18.0 response/NotificationResponse#::Closedrust-analyzer cargo notify-rust 4.18.0 response/NotificationResponse#Closed#(_) => invocation_closure("__closed"),
111 });
112 }
113
114 #[cfg(feature = "zbus")]
115 NotificationHandleInnerrust-analyzer cargo notify-rust 4.18.0 xdg/NotificationHandleInner#::Zbusrust-analyzer cargo notify-rust 4.18.0 xdg/NotificationHandleInner#Zbus#(inner) => {
116 block_onrust-analyzer cargo zbus 5.19.0 utils/block_on().(
117 inner.wait_for_actionrust-analyzer cargo notify-rust 4.18.0 xdg/zbus_rs/impl#[ZbusNotificationHandle]wait_for_action().(|response: &NotificationResponserust-analyzer cargo notify-rust 4.18.0 response/NotificationResponse#| match response {
118 NotificationResponserust-analyzer cargo notify-rust 4.18.0 response/NotificationResponse#::Defaultrust-analyzer cargo notify-rust 4.18.0 response/NotificationResponse#Default# => invocation_closure("default"),
119 NotificationResponserust-analyzer cargo notify-rust 4.18.0 response/NotificationResponse#::Actionrust-analyzer cargo notify-rust 4.18.0 response/NotificationResponse#Action#(ref action) => invocation_closure(action),
120 NotificationResponserust-analyzer cargo notify-rust 4.18.0 response/NotificationResponse#::Replyrust-analyzer cargo notify-rust 4.18.0 response/NotificationResponse#Reply#(_) => { /* XDG does not support inline replies */ }
121 NotificationResponserust-analyzer cargo notify-rust 4.18.0 response/NotificationResponse#::Closedrust-analyzer cargo notify-rust 4.18.0 response/NotificationResponse#Closed#(_) => invocation_closure("__closed"), // FIXME: remove backward compatibility with 5.0
122 }),
123 );
124 }
125 };
126 }
127
128 /// Waits for the user to act on a notification and then calls `handler`
129 /// with a typed [`NotificationResponse`].
130 ///
131 /// This is the typed, forward-compatible replacement for [`wait_for_action`](Self::wait_for_action).
132 pub fn wait_for_responserust-analyzer cargo notify-rust 4.18.0 xdg/impl#[NotificationHandle]wait_for_response().(self, handler: impl ResponseHandlerrust-analyzer cargo notify-rust 4.18.0 response/ResponseHandler#) -> Resultrust-analyzer cargo notify-rust 4.18.0 error/Result#<()> {
133 match self.innerrust-analyzer cargo notify-rust 4.18.0 xdg/NotificationHandle#inner. {
134 #[cfg(feature = "dbus")]
135 NotificationHandleInnerrust-analyzer cargo notify-rust 4.18.0 xdg/NotificationHandleInner#::Dbusrust-analyzer cargo notify-rust 4.18.0 xdg/NotificationHandleInner#Dbus#(inner) => inner.wait_for_actionrust-analyzer cargo notify-rust 4.18.0 xdg/dbus_rs/impl#[DbusNotificationHandle]wait_for_action().(handler),
136 #[cfg(feature = "zbus")]
137 NotificationHandleInnerrust-analyzer cargo notify-rust 4.18.0 xdg/NotificationHandleInner#::Zbusrust-analyzer cargo notify-rust 4.18.0 xdg/NotificationHandleInner#Zbus#(inner) => {
138 block_onrust-analyzer cargo zbus 5.19.0 utils/block_on().(inner.wait_for_actionrust-analyzer cargo notify-rust 4.18.0 xdg/zbus_rs/impl#[ZbusNotificationHandle]wait_for_action().(handler));
139 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
140 }
141 }
142 }
143
144 /// Returns a future that waits for the user to act on a notification and then calls
145 /// `invocation_closure` with the name of the corresponding action.
146 ///
147 /// # Panics
148 ///
149 /// Panics if called with a [`Dbus`](DbusStack::Dbus) backend.
150 ///
151 /// # Example
152 ///
153 /// ```no_run
154 /// # use notify_rust::*;
155 /// # use async_std::task::sleep;
156 /// # use std::time::Duration;
157 /// # use futures_lite::future::zip;
158 /// # async fn wait_for_action_async_example() -> Result<(), Box<dyn std::error::Error>> {
159 /// let handle: NotificationHandle = Notification::new()
160 /// .action("do-stuff", "my fancy button")
161 /// .show_async()
162 /// .await?;
163 ///
164 /// let wait_future = handle.wait_for_action_async(|action| {
165 /// // handle action
166 /// # let _ = action;
167 /// });
168 /// let close_future = async {
169 /// sleep(Duration::from_secs(5)).await;
170 /// handle.close_async();
171 /// };
172 ///
173 /// // run both futures concurrently
174 /// # let _ =
175 /// zip(wait_future, close_future).await;
176 /// # Ok(())
177 /// # }
178 /// ```
179 // TODO: make this consume `self` in 5.0
180 #[cfg(feature = "zbus")]
181 pub async fn wait_for_action_asyncrust-analyzer cargo notify-rust 4.18.0 xdg/impl#[NotificationHandle]wait_for_action_async().<F>(&self, invocation_closure: F)
182 where
183 F: FnOncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnOnce#(&NotificationResponserust-analyzer cargo notify-rust 4.18.0 response/NotificationResponse#),
184 {
185 match &self.innerrust-analyzer cargo notify-rust 4.18.0 xdg/NotificationHandle#inner. {
186 #[cfg(feature = "dbus")]
187 NotificationHandleInnerrust-analyzer cargo notify-rust 4.18.0 xdg/NotificationHandleInner#::Dbusrust-analyzer cargo notify-rust 4.18.0 xdg/NotificationHandleInner#Dbus#(_) => {
188 unimplementedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/unimplemented!!("async methods are not supported with the `dbus` backend");
189 }
190 #[cfg(feature = "zbus")]
191 NotificationHandleInnerrust-analyzer cargo notify-rust 4.18.0 xdg/NotificationHandleInner#::Zbusrust-analyzer cargo notify-rust 4.18.0 xdg/NotificationHandleInner#Zbus#(inner) => inner.wait_for_actionrust-analyzer cargo notify-rust 4.18.0 xdg/zbus_rs/impl#[ZbusNotificationHandle]wait_for_action().(invocation_closure).rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().,
192 }
193 }
194
195 /// Manually close the notification
196 ///
197 /// # Example
198 ///
199 /// ```no_run
200 /// # use notify_rust::*;
201 /// let handle: NotificationHandle = Notification::new()
202 /// .summary("oh no")
203 /// .hint(notify_rust::Hint::Transient(true))
204 /// .body("I'll be here till you close me!")
205 /// .hint(Hint::Resident(true)) // does not work on kde
206 /// .timeout(Timeout::Never) // works on kde and gnome
207 /// .show()
208 /// .unwrap();
209 /// // ... and then later
210 /// handle.close();
211 /// ```
212 pub fn closerust-analyzer cargo notify-rust 4.18.0 xdg/impl#[NotificationHandle]close().(self) {
213 match self.innerrust-analyzer cargo notify-rust 4.18.0 xdg/NotificationHandle#inner. {
214 #[cfg(feature = "dbus")]
215 NotificationHandleInnerrust-analyzer cargo notify-rust 4.18.0 xdg/NotificationHandleInner#::Dbusrust-analyzer cargo notify-rust 4.18.0 xdg/NotificationHandleInner#Dbus#(inner) => inner.closerust-analyzer cargo notify-rust 4.18.0 xdg/dbus_rs/impl#[DbusNotificationHandle]close().(),
216 #[cfg(feature = "zbus")]
217 NotificationHandleInnerrust-analyzer cargo notify-rust 4.18.0 xdg/NotificationHandleInner#::Zbusrust-analyzer cargo notify-rust 4.18.0 xdg/NotificationHandleInner#Zbus#(inner) => block_onrust-analyzer cargo zbus 5.19.0 utils/block_on().(inner.closerust-analyzer cargo notify-rust 4.18.0 xdg/zbus_rs/impl#[ZbusNotificationHandle]close().()),
218 }
219 }
220
221 /// Async version of [`close`](Self::close).
222 ///
223 /// # Panics
224 ///
225 /// Panics if called with a [`Dbus`](DbusStack::Dbus) backend.
226 #[cfg(feature = "zbus")]
227 pub async fn close_asyncrust-analyzer cargo notify-rust 4.18.0 xdg/impl#[NotificationHandle]close_async().(&self) {
228 match &self.innerrust-analyzer cargo notify-rust 4.18.0 xdg/NotificationHandle#inner. {
229 #[cfg(feature = "dbus")]
230 NotificationHandleInnerrust-analyzer cargo notify-rust 4.18.0 xdg/NotificationHandleInner#::Dbusrust-analyzer cargo notify-rust 4.18.0 xdg/NotificationHandleInner#Dbus#(_) => {
231 unimplementedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/unimplemented!!("async methods are not supported with the `dbus` backend");
232 }
233 #[cfg(feature = "zbus")]
234 NotificationHandleInnerrust-analyzer cargo notify-rust 4.18.0 xdg/NotificationHandleInner#::Zbusrust-analyzer cargo notify-rust 4.18.0 xdg/NotificationHandleInner#Zbus#(inner) => inner.closerust-analyzer cargo notify-rust 4.18.0 xdg/zbus_rs/impl#[ZbusNotificationHandle]close().().rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().,
235 }
236 }
237
238 /// Executes a closure after the notification has closed.
239 ///
240 /// ## Example 1: *I don't care about why it closed* (the good ole API)
241 ///
242 /// ```no_run
243 /// # use notify_rust::Notification;
244 /// Notification::new().summary("Time is running out")
245 /// .body("This will go away.")
246 /// .icon("clock")
247 /// .show()
248 /// .unwrap()
249 /// .on_close(|| println!("closed"));
250 /// ```
251 ///
252 /// ## Example 2: *I **do** care about why it closed* (added in v4.5.0)
253 ///
254 /// ```no_run
255 /// # use notify_rust::Notification;
256 /// Notification::new().summary("Time is running out")
257 /// .body("This will go away.")
258 /// .icon("clock")
259 /// .show()
260 /// .unwrap()
261 /// .on_close(|reason| println!("closed: {:?}", reason));
262 /// ```
263 // #[deprecated(
264 // since = "4.18.0",
265 // note = "Use `wait_for_response()` and match on `ActionResponse::Closed` instead"
266 // )]
267 pub fn on_closerust-analyzer cargo notify-rust 4.18.0 xdg/impl#[NotificationHandle]on_close().<A>(self, handler: impl CloseHandlerrust-analyzer cargo notify-rust 4.18.0 response/CloseHandler#<A>) {
268 match self.innerrust-analyzer cargo notify-rust 4.18.0 xdg/NotificationHandle#inner. {
269 #[cfg(feature = "dbus")]
270 NotificationHandleInnerrust-analyzer cargo notify-rust 4.18.0 xdg/NotificationHandleInner#::Dbusrust-analyzer cargo notify-rust 4.18.0 xdg/NotificationHandleInner#Dbus#(inner) => {
271 let _ = inner.wait_for_actionrust-analyzer cargo notify-rust 4.18.0 xdg/dbus_rs/impl#[DbusNotificationHandle]wait_for_action().(|action: &NotificationResponserust-analyzer cargo notify-rust 4.18.0 response/NotificationResponse#| {
272 if let NotificationResponserust-analyzer cargo notify-rust 4.18.0 response/NotificationResponse#::Closedrust-analyzer cargo notify-rust 4.18.0 response/NotificationResponse#Closed#(reason) = action {
273 handler.callrust-analyzer cargo notify-rust 4.18.0 response/CloseHandler#call().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().reason);
274 }
275 });
276 }
277 #[cfg(feature = "zbus")]
278 NotificationHandleInnerrust-analyzer cargo notify-rust 4.18.0 xdg/NotificationHandleInner#::Zbusrust-analyzer cargo notify-rust 4.18.0 xdg/NotificationHandleInner#Zbus#(inner) => {
279 block_onrust-analyzer cargo zbus 5.19.0 utils/block_on().(inner.wait_for_actionrust-analyzer cargo notify-rust 4.18.0 xdg/zbus_rs/impl#[ZbusNotificationHandle]wait_for_action().(|action: &NotificationResponserust-analyzer cargo notify-rust 4.18.0 response/NotificationResponse#| {
280 if let NotificationResponserust-analyzer cargo notify-rust 4.18.0 response/NotificationResponse#::Closedrust-analyzer cargo notify-rust 4.18.0 response/NotificationResponse#Closed#(reason) = action {
281 handler.callrust-analyzer cargo notify-rust 4.18.0 response/CloseHandler#call().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().reason);
282 }
283 }));
284 }
285 };
286 }
287
288 /// Replace the original notification with an updated version
289 /// ## Example
290 /// ```no_run
291 /// # use notify_rust::Notification;
292 /// let mut notification = Notification::new().summary("Latest News")
293 /// .body("Bayern Dortmund 3:2")
294 /// .show()
295 /// .unwrap();
296 ///
297 /// std::thread::sleep_ms(1_500);
298 ///
299 /// notification.summary("Latest News (Correction)")
300 /// .body("Bayern Dortmund 3:3");
301 ///
302 /// notification.update().unwrap();
303 /// ```
304 /// Watch out for different implementations of the
305 /// notification server! On plasma5 for instance, you should also change the appname, so the old
306 /// message is really replaced and not just amended. Xfce behaves well, all others have not
307 /// been tested by the developer.
308 pub fn updaterust-analyzer cargo notify-rust 4.18.0 xdg/impl#[NotificationHandle]update().(&mut self) -> Resultrust-analyzer cargo notify-rust 4.18.0 error/Result#<()> {
309 match self.innerrust-analyzer cargo notify-rust 4.18.0 xdg/NotificationHandle#inner. {
310 #[cfg(feature = "dbus")]
311 NotificationHandleInnerrust-analyzer cargo notify-rust 4.18.0 xdg/NotificationHandleInner#::Dbusrust-analyzer cargo notify-rust 4.18.0 xdg/NotificationHandleInner#Dbus#(ref mut inner) => inner.updaterust-analyzer cargo notify-rust 4.18.0 xdg/dbus_rs/impl#[DbusNotificationHandle]update().(),
312 #[cfg(feature = "zbus")]
313 NotificationHandleInnerrust-analyzer cargo notify-rust 4.18.0 xdg/NotificationHandleInner#::Zbusrust-analyzer cargo notify-rust 4.18.0 xdg/NotificationHandleInner#Zbus#(ref mut inner) => inner.updaterust-analyzer cargo notify-rust 4.18.0 xdg/zbus_rs/impl#[ZbusNotificationHandle]update().(),
314 }
315 }
316
317 /// Returns the handle's id.
318 pub fn idrust-analyzer cargo notify-rust 4.18.0 xdg/impl#[NotificationHandle]id().(&self) -> u32 {
319 match self.innerrust-analyzer cargo notify-rust 4.18.0 xdg/NotificationHandle#inner. {
320 #[cfg(feature = "dbus")]
321 NotificationHandleInnerrust-analyzer cargo notify-rust 4.18.0 xdg/NotificationHandleInner#::Dbusrust-analyzer cargo notify-rust 4.18.0 xdg/NotificationHandleInner#Dbus#(ref inner) => inner.idrust-analyzer cargo notify-rust 4.18.0 xdg/dbus_rs/DbusNotificationHandle#id.,
322 #[cfg(feature = "zbus")]
323 NotificationHandleInnerrust-analyzer cargo notify-rust 4.18.0 xdg/NotificationHandleInner#::Zbusrust-analyzer cargo notify-rust 4.18.0 xdg/NotificationHandleInner#Zbus#(ref inner) => inner.idrust-analyzer cargo notify-rust 4.18.0 xdg/zbus_rs/ZbusNotificationHandle#id.,
324 }
325 }
326 }
327
328 /// Required for [`DerefMut`].
329 impl Derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref# for NotificationHandlerust-analyzer cargo notify-rust 4.18.0 xdg/NotificationHandle# {
330 type Targetrust-analyzer cargo notify-rust 4.18.0 xdg/impl#[NotificationHandle][Deref]Target# = Notificationrust-analyzer cargo notify-rust 4.18.0 notification/Notification#;
331
332 fn derefrust-analyzer cargo notify-rust 4.18.0 xdg/impl#[NotificationHandle][Deref]deref().(&self) -> &Notificationrust-analyzer cargo notify-rust 4.18.0 notification/Notification# {
333 match self.innerrust-analyzer cargo notify-rust 4.18.0 xdg/NotificationHandle#inner. {
334 #[cfg(feature = "dbus")]
335 NotificationHandleInnerrust-analyzer cargo notify-rust 4.18.0 xdg/NotificationHandleInner#::Dbusrust-analyzer cargo notify-rust 4.18.0 xdg/NotificationHandleInner#Dbus#(ref inner) => &inner.notificationrust-analyzer cargo notify-rust 4.18.0 xdg/dbus_rs/DbusNotificationHandle#notification.,
336 #[cfg(feature = "zbus")]
337 NotificationHandleInnerrust-analyzer cargo notify-rust 4.18.0 xdg/NotificationHandleInner#::Zbusrust-analyzer cargo notify-rust 4.18.0 xdg/NotificationHandleInner#Zbus#(ref inner) => &inner.notificationrust-analyzer cargo notify-rust 4.18.0 xdg/zbus_rs/ZbusNotificationHandle#notification.,
338 }
339 }
340 }
341
342 /// Allows easy modification of notification properties.
343 impl DerefMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/DerefMut# for NotificationHandlerust-analyzer cargo notify-rust 4.18.0 xdg/NotificationHandle# {
344 fn deref_mutrust-analyzer cargo notify-rust 4.18.0 xdg/impl#[NotificationHandle][DerefMut]deref_mut().(&mut self) -> &mut Notificationrust-analyzer cargo notify-rust 4.18.0 notification/Notification# {
345 match self.innerrust-analyzer cargo notify-rust 4.18.0 xdg/NotificationHandle#inner. {
346 #[cfg(feature = "dbus")]
347 NotificationHandleInnerrust-analyzer cargo notify-rust 4.18.0 xdg/NotificationHandleInner#::Dbusrust-analyzer cargo notify-rust 4.18.0 xdg/NotificationHandleInner#Dbus#(ref mut inner) => &mut inner.notificationrust-analyzer cargo notify-rust 4.18.0 xdg/dbus_rs/DbusNotificationHandle#notification.,
348 #[cfg(feature = "zbus")]
349 NotificationHandleInnerrust-analyzer cargo notify-rust 4.18.0 xdg/NotificationHandleInner#::Zbusrust-analyzer cargo notify-rust 4.18.0 xdg/NotificationHandleInner#Zbus#(ref mut inner) => &mut inner.notificationrust-analyzer cargo notify-rust 4.18.0 xdg/zbus_rs/ZbusNotificationHandle#notification.,
350 }
351 }
352 }
353
354 #[cfg(feature = "dbus")]
355 impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<dbus_rsrust-analyzer cargo notify-rust 4.18.0 xdg/dbus_rs/::DbusNotificationHandlerust-analyzer cargo notify-rust 4.18.0 xdg/dbus_rs/DbusNotificationHandle#> for NotificationHandleInnerrust-analyzer cargo notify-rust 4.18.0 xdg/NotificationHandleInner# {
356 fn fromrust-analyzer cargo notify-rust 4.18.0 xdg/impl#[NotificationHandleInner][`From<dbus_rs::DbusNotificationHandle>`]from().(handle: dbus_rsrust-analyzer cargo notify-rust 4.18.0 xdg/dbus_rs/::DbusNotificationHandlerust-analyzer cargo notify-rust 4.18.0 xdg/dbus_rs/DbusNotificationHandle#) -> NotificationHandleInnerrust-analyzer cargo notify-rust 4.18.0 xdg/NotificationHandleInner# {
357 NotificationHandleInnerrust-analyzer cargo notify-rust 4.18.0 xdg/NotificationHandleInner#::Dbusrust-analyzer cargo notify-rust 4.18.0 xdg/NotificationHandleInner#Dbus#(handle)
358 }
359 }
360
361 #[cfg(feature = "zbus")]
362 impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<zbus_rsrust-analyzer cargo notify-rust 4.18.0 xdg/zbus_rs/::ZbusNotificationHandlerust-analyzer cargo notify-rust 4.18.0 xdg/zbus_rs/ZbusNotificationHandle#> for NotificationHandleInnerrust-analyzer cargo notify-rust 4.18.0 xdg/NotificationHandleInner# {
363 fn fromrust-analyzer cargo notify-rust 4.18.0 xdg/impl#[NotificationHandleInner][`From<zbus_rs::ZbusNotificationHandle>`]from().(handle: zbus_rsrust-analyzer cargo notify-rust 4.18.0 xdg/zbus_rs/::ZbusNotificationHandlerust-analyzer cargo notify-rust 4.18.0 xdg/zbus_rs/ZbusNotificationHandle#) -> NotificationHandleInnerrust-analyzer cargo notify-rust 4.18.0 xdg/NotificationHandleInner# {
364 NotificationHandleInnerrust-analyzer cargo notify-rust 4.18.0 xdg/NotificationHandleInner#::Zbusrust-analyzer cargo notify-rust 4.18.0 xdg/NotificationHandleInner#Zbus#(handle)
365 }
366 }
367
368 #[cfg(feature = "dbus")]
369 impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<dbus_rsrust-analyzer cargo notify-rust 4.18.0 xdg/dbus_rs/::DbusNotificationHandlerust-analyzer cargo notify-rust 4.18.0 xdg/dbus_rs/DbusNotificationHandle#> for NotificationHandlerust-analyzer cargo notify-rust 4.18.0 xdg/NotificationHandle# {
370 fn fromrust-analyzer cargo notify-rust 4.18.0 xdg/impl#[NotificationHandle][`From<dbus_rs::DbusNotificationHandle>`]from().(handle: dbus_rsrust-analyzer cargo notify-rust 4.18.0 xdg/dbus_rs/::DbusNotificationHandlerust-analyzer cargo notify-rust 4.18.0 xdg/dbus_rs/DbusNotificationHandle#) -> NotificationHandlerust-analyzer cargo notify-rust 4.18.0 xdg/NotificationHandle# {
371 NotificationHandlerust-analyzer cargo notify-rust 4.18.0 xdg/NotificationHandle# {
372 innerrust-analyzer cargo notify-rust 4.18.0 xdg/NotificationHandle#inner.: handle.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(),
373 }
374 }
375 }
376
377 #[cfg(feature = "zbus")]
378 impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<zbus_rsrust-analyzer cargo notify-rust 4.18.0 xdg/zbus_rs/::ZbusNotificationHandlerust-analyzer cargo notify-rust 4.18.0 xdg/zbus_rs/ZbusNotificationHandle#> for NotificationHandlerust-analyzer cargo notify-rust 4.18.0 xdg/NotificationHandle# {
379 fn fromrust-analyzer cargo notify-rust 4.18.0 xdg/impl#[NotificationHandle][`From<zbus_rs::ZbusNotificationHandle>`]from().(handle: zbus_rsrust-analyzer cargo notify-rust 4.18.0 xdg/zbus_rs/::ZbusNotificationHandlerust-analyzer cargo notify-rust 4.18.0 xdg/zbus_rs/ZbusNotificationHandle#) -> NotificationHandlerust-analyzer cargo notify-rust 4.18.0 xdg/NotificationHandle# {
380 NotificationHandlerust-analyzer cargo notify-rust 4.18.0 xdg/NotificationHandle# {
381 innerrust-analyzer cargo notify-rust 4.18.0 xdg/NotificationHandle#inner.: handle.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(),
382 }
383 }
384 }
385
386 // here be public functions
387
388 // TODO: breaking change, wait for 5.0
389 // #[cfg(all(feature = "dbus", feature = "zbus"))]
390 //compile_error!("the z and d features are mutually exclusive");
391
392 #[cfg(all(
393 not(any(feature = "dbus", feature = "zbus")),
394 unix,
395 not(target_os = "macos")
396 ))]
397 compile_errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/compile_error!!("you have to build with either zbus or dbus turned on");
398
399 /// Which D-Bus implementation is in use.
400 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
401 pub enum DbusStackrust-analyzer cargo notify-rust 4.18.0 xdg/DbusStack# {
402 /// Using [dbus-rs](https://docs.rs/dbus-rs).
403 Dbusrust-analyzer cargo notify-rust 4.18.0 xdg/DbusStack#Dbus#,
404 /// Using [zbus](https://docs.rs/zbus).
405 Zbusrust-analyzer cargo notify-rust 4.18.0 xdg/DbusStack#Zbus#,
406 }
407
408 #[cfg(all(feature = "dbus", feature = "zbus"))]
409 const DBUS_SWITCH_VARrust-analyzer cargo notify-rust 4.18.0 xdg/DBUS_SWITCH_VAR.: &str = "DBUSRS";
410
411 #[cfg(all(feature = "zbus", not(feature = "dbus")))]
412 pub(craterust-analyzer cargo notify-rust 4.18.0 crate/) fn show_notification(notification: &Notificationrust-analyzer cargo notify-rust 4.18.0 notification/Notification#) -> Resultrust-analyzer cargo notify-rust 4.18.0 error/Result#<NotificationHandlerust-analyzer cargo notify-rust 4.18.0 xdg/NotificationHandle#> {
413 block_onrust-analyzer cargo zbus 5.19.0 utils/block_on().(zbus_rsrust-analyzer cargo notify-rust 4.18.0 xdg/zbus_rs/::connect_and_send_notificationrust-analyzer cargo notify-rust 4.18.0 xdg/zbus_rs/connect_and_send_notification().(notification)).map(Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#::into)
414 }
415
416 #[cfg(feature = "zbus")]
417 pub(craterust-analyzer cargo notify-rust 4.18.0 crate/) async fn show_notification_asyncrust-analyzer cargo notify-rust 4.18.0 xdg/show_notification_async().(
418 notification: &Notificationrust-analyzer cargo notify-rust 4.18.0 notification/Notification#,
419 ) -> Resultrust-analyzer cargo notify-rust 4.18.0 error/Result#<NotificationHandlerust-analyzer cargo notify-rust 4.18.0 xdg/NotificationHandle#> {
420 zbus_rsrust-analyzer cargo notify-rust 4.18.0 xdg/zbus_rs/::connect_and_send_notificationrust-analyzer cargo notify-rust 4.18.0 xdg/zbus_rs/connect_and_send_notification().(notification)
421 .rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().
422 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map().(Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#::intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().)
423 }
424
425 #[cfg(feature = "zbus")]
426 pub(craterust-analyzer cargo notify-rust 4.18.0 crate/) async fn show_notification_async_at_busrust-analyzer cargo notify-rust 4.18.0 xdg/show_notification_async_at_bus().(
427 notification: &Notificationrust-analyzer cargo notify-rust 4.18.0 notification/Notification#,
428 bus: NotificationBusrust-analyzer cargo notify-rust 4.18.0 xdg/bus/NotificationBus#,
429 ) -> Resultrust-analyzer cargo notify-rust 4.18.0 error/Result#<NotificationHandlerust-analyzer cargo notify-rust 4.18.0 xdg/NotificationHandle#> {
430 zbus_rsrust-analyzer cargo notify-rust 4.18.0 xdg/zbus_rs/::connect_and_send_notification_at_busrust-analyzer cargo notify-rust 4.18.0 xdg/zbus_rs/connect_and_send_notification_at_bus().(notification, bus)
431 .rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().
432 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map().(Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#::intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().)
433 }
434
435 #[cfg(all(feature = "dbus", not(feature = "zbus")))]
436 pub(craterust-analyzer cargo notify-rust 4.18.0 crate/) fn show_notification(notification: &Notificationrust-analyzer cargo notify-rust 4.18.0 notification/Notification#) -> Resultrust-analyzer cargo notify-rust 4.18.0 error/Result#<NotificationHandlerust-analyzer cargo notify-rust 4.18.0 xdg/NotificationHandle#> {
437 dbus_rsrust-analyzer cargo notify-rust 4.18.0 xdg/dbus_rs/::connect_and_send_notificationrust-analyzer cargo notify-rust 4.18.0 xdg/dbus_rs/connect_and_send_notification().(notification).map(Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#::into)
438 }
439
440 #[cfg(all(feature = "dbus", feature = "zbus"))]
441 pub(craterust-analyzer cargo notify-rust 4.18.0 crate/) fn show_notificationrust-analyzer cargo notify-rust 4.18.0 xdg/show_notification().(notification: &Notificationrust-analyzer cargo notify-rust 4.18.0 notification/Notification#) -> Resultrust-analyzer cargo notify-rust 4.18.0 error/Result#<NotificationHandlerust-analyzer cargo notify-rust 4.18.0 xdg/NotificationHandle#> {
442 if stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::envrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/::varrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/var().(DBUS_SWITCH_VARrust-analyzer cargo notify-rust 4.18.0 xdg/DBUS_SWITCH_VAR.).is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().() {
443 dbus_rsrust-analyzer cargo notify-rust 4.18.0 xdg/dbus_rs/::connect_and_send_notificationrust-analyzer cargo notify-rust 4.18.0 xdg/dbus_rs/connect_and_send_notification().(notification).maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map().(Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#::intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().)
444 } else {
445 block_onrust-analyzer cargo zbus 5.19.0 utils/block_on().(zbus_rsrust-analyzer cargo notify-rust 4.18.0 xdg/zbus_rs/::connect_and_send_notificationrust-analyzer cargo notify-rust 4.18.0 xdg/zbus_rs/connect_and_send_notification().(notification)).maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map().(Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#::intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().)
446 }
447 }
448
449 /// Get the currently active [`DbusStack`].
450 ///
451 /// (zbus only)
452 #[cfg(all(feature = "zbus", not(feature = "dbus")))]
453 pub fn dbus_stack() -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<DbusStackrust-analyzer cargo notify-rust 4.18.0 xdg/DbusStack#> {
454 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(DbusStackrust-analyzer cargo notify-rust 4.18.0 xdg/DbusStack#::Zbusrust-analyzer cargo notify-rust 4.18.0 xdg/DbusStack#Zbus#)
455 }
456
457 /// Get the currently active [`DbusStack`].
458 ///
459 /// (dbus-rs only)
460 #[cfg(all(feature = "dbus", not(feature = "zbus")))]
461 pub fn dbus_stack() -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<DbusStackrust-analyzer cargo notify-rust 4.18.0 xdg/DbusStack#> {
462 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(DbusStackrust-analyzer cargo notify-rust 4.18.0 xdg/DbusStack#::Dbusrust-analyzer cargo notify-rust 4.18.0 xdg/DbusStack#Dbus#)
463 }
464
465 /// Get the currently active [`DbusStack`].
466 ///
467 /// Both dbus-rs and zbus are compiled in; switch via the `$DBUSRS` environment variable.
468 #[cfg(all(feature = "dbus", feature = "zbus"))]
469 pub fn dbus_stackrust-analyzer cargo notify-rust 4.18.0 xdg/dbus_stack().() -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<DbusStackrust-analyzer cargo notify-rust 4.18.0 xdg/DbusStack#> {
470 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(if stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::envrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/::varrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/var().(DBUS_SWITCH_VARrust-analyzer cargo notify-rust 4.18.0 xdg/DBUS_SWITCH_VAR.).is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().() {
471 DbusStackrust-analyzer cargo notify-rust 4.18.0 xdg/DbusStack#::Dbusrust-analyzer cargo notify-rust 4.18.0 xdg/DbusStack#Dbus#
472 } else {
473 DbusStackrust-analyzer cargo notify-rust 4.18.0 xdg/DbusStack#::Zbusrust-analyzer cargo notify-rust 4.18.0 xdg/DbusStack#Zbus#
474 })
475 }
476
477 /// Get the currently active [`DbusStack`].
478 ///
479 /// Neither `zbus` nor `dbus-rs` are configured; always returns `None`.
480 #[cfg(all(not(feature = "dbus"), not(feature = "zbus")))]
481 pub fn dbus_stack() -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<DbusStackrust-analyzer cargo notify-rust 4.18.0 xdg/DbusStack#> {
482 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
483 }
484
485 /// Returns a list of all capabilities of the running notification server.
486 ///
487 /// (zbus only)
488 #[cfg(all(feature = "zbus", not(feature = "dbus")))]
489 pub fn get_capabilities() -> Resultrust-analyzer cargo notify-rust 4.18.0 error/Result#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>> {
490 block_onrust-analyzer cargo zbus 5.19.0 utils/block_on().(zbus_rsrust-analyzer cargo notify-rust 4.18.0 xdg/zbus_rs/::get_capabilitiesrust-analyzer cargo notify-rust 4.18.0 xdg/zbus_rs/get_capabilities().())
491 }
492
493 /// Returns a list of all capabilities of the running notification server.
494 ///
495 /// (dbus-rs only)
496 #[cfg(all(feature = "dbus", not(feature = "zbus")))]
497 pub fn get_capabilities() -> Resultrust-analyzer cargo notify-rust 4.18.0 error/Result#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>> {
498 dbus_rsrust-analyzer cargo notify-rust 4.18.0 xdg/dbus_rs/::get_capabilitiesrust-analyzer cargo notify-rust 4.18.0 xdg/dbus_rs/get_capabilities().()
499 }
500
501 /// Returns a list of all capabilities of the running notification server.
502 ///
503 /// Both dbus-rs and zbus are compiled in; switch via the `$DBUSRS` environment variable.
504 #[cfg(all(feature = "dbus", feature = "zbus"))]
505 pub fn get_capabilitiesrust-analyzer cargo notify-rust 4.18.0 xdg/get_capabilities().() -> Resultrust-analyzer cargo notify-rust 4.18.0 error/Result#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>> {
506 if stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::envrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/::varrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/var().(DBUS_SWITCH_VARrust-analyzer cargo notify-rust 4.18.0 xdg/DBUS_SWITCH_VAR.).is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().() {
507 dbus_rsrust-analyzer cargo notify-rust 4.18.0 xdg/dbus_rs/::get_capabilitiesrust-analyzer cargo notify-rust 4.18.0 xdg/dbus_rs/get_capabilities().()
508 } else {
509 block_onrust-analyzer cargo zbus 5.19.0 utils/block_on().(zbus_rsrust-analyzer cargo notify-rust 4.18.0 xdg/zbus_rs/::get_capabilitiesrust-analyzer cargo notify-rust 4.18.0 xdg/zbus_rs/get_capabilities().())
510 }
511 }
512
513 /// Returns a [`ServerInformation`] struct describing the running notification server.
514 ///
515 /// The struct contains `name`, `vendor`, `version`, and `spec_version`.
516 ///
517 /// (zbus only)
518 #[cfg(all(feature = "zbus", not(feature = "dbus")))]
519 pub fn get_server_information() -> Resultrust-analyzer cargo notify-rust 4.18.0 error/Result#<ServerInformationrust-analyzer cargo notify-rust 4.18.0 xdg/ServerInformation#> {
520 block_onrust-analyzer cargo zbus 5.19.0 utils/block_on().(zbus_rsrust-analyzer cargo notify-rust 4.18.0 xdg/zbus_rs/::get_server_informationrust-analyzer cargo notify-rust 4.18.0 xdg/zbus_rs/get_server_information().())
521 }
522
523 /// Returns a [`ServerInformation`] struct describing the running notification server.
524 ///
525 /// The struct contains `name`, `vendor`, `version`, and `spec_version`.
526 ///
527 /// (dbus-rs only)
528 #[cfg(all(feature = "dbus", not(feature = "zbus")))]
529 pub fn get_server_information() -> Resultrust-analyzer cargo notify-rust 4.18.0 error/Result#<ServerInformationrust-analyzer cargo notify-rust 4.18.0 xdg/ServerInformation#> {
530 dbus_rsrust-analyzer cargo notify-rust 4.18.0 xdg/dbus_rs/::get_server_informationrust-analyzer cargo notify-rust 4.18.0 xdg/dbus_rs/get_server_information().()
531 }
532
533 /// Returns a [`ServerInformation`] struct describing the running notification server.
534 ///
535 /// The struct contains `name`, `vendor`, `version`, and `spec_version`.
536 ///
537 /// Both dbus-rs and zbus are compiled in; switch via the `$DBUSRS` environment variable.
538 #[cfg(all(feature = "dbus", feature = "zbus"))]
539 pub fn get_server_informationrust-analyzer cargo notify-rust 4.18.0 xdg/get_server_information().() -> Resultrust-analyzer cargo notify-rust 4.18.0 error/Result#<ServerInformationrust-analyzer cargo notify-rust 4.18.0 xdg/ServerInformation#> {
540 if stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::envrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/::varrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/var().(DBUS_SWITCH_VARrust-analyzer cargo notify-rust 4.18.0 xdg/DBUS_SWITCH_VAR.).is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().() {
541 dbus_rsrust-analyzer cargo notify-rust 4.18.0 xdg/dbus_rs/::get_server_informationrust-analyzer cargo notify-rust 4.18.0 xdg/dbus_rs/get_server_information().()
542 } else {
543 block_onrust-analyzer cargo zbus 5.19.0 utils/block_on().(zbus_rsrust-analyzer cargo notify-rust 4.18.0 xdg/zbus_rs/::get_server_informationrust-analyzer cargo notify-rust 4.18.0 xdg/zbus_rs/get_server_information().())
544 }
545 }
546
547 /// Return value of [`get_server_information()`].
548 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
549 #[cfg_attr(feature = "serde", derive(serderust-analyzer cargo serde 1.0.229 crate/::Deserializerust-analyzer cargo serde_derive 1.0.229 Deserialize:))]
550 #[cfg_attr(feature = "zbus", derive(zvariantrust-analyzer cargo zvariant 5.15.0 crate/::Typerust-analyzer cargo zvariant_derive 5.15.0 Type:))]
551 pub struct ServerInformationrust-analyzer cargo notify-rust 4.18.0 xdg/ServerInformation# {
552 /// The product name of the server.
553 pub namerust-analyzer cargo notify-rust 4.18.0 xdg/ServerInformation#name.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#,
554 /// The vendor name.
555 pub vendorrust-analyzer cargo notify-rust 4.18.0 xdg/ServerInformation#vendor.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#,
556 /// The server's version string.
557 pub versionrust-analyzer cargo notify-rust 4.18.0 xdg/ServerInformation#version.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#,
558 /// The specification version the server is compliant with.
559 pub spec_versionrust-analyzer cargo notify-rust 4.18.0 xdg/ServerInformation#spec_version.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#,
560 }
561
562 // /// Strictly internal.
563 // /// The NotificationServer implemented here exposes a "Stop" function.
564 // /// stops the notification server
565 // #[cfg(all(feature = "server", unix, not(target_os = "macos")))]
566 // #[doc(hidden)]
567 // pub fn stop_server() {
568 // #[cfg(feature = "dbus")]
569 // dbus_rs::stop_server()
570 // }
571
572 /// Listens for the `ActionInvoked(UInt32, String)` signal.
573 ///
574 /// Prefer [`NotificationHandle::wait_for_action`] instead.
575 /// (xdg only)
576 #[cfg(all(feature = "zbus", not(feature = "dbus")))]
577 // #[deprecated(note="please use [`NotificationHandle::wait_for_action`]")]
578 pub fn handle_action<F>(id: u32, func: F) -> Resultrust-analyzer cargo notify-rust 4.18.0 error/Result#<()>
579 where
580 F: FnOncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnOnce#(&ActionResponserust-analyzer cargo notify-rust 4.18.0 response/ActionResponse#<'_>),
581 {
582 block_onrust-analyzer cargo zbus 5.19.0 utils/block_on().(zbus_rsrust-analyzer cargo notify-rust 4.18.0 xdg/zbus_rs/::handle_actionrust-analyzer cargo notify-rust 4.18.0 xdg/zbus_rs/handle_action().(id, action_response_adapterrust-analyzer cargo notify-rust 4.18.0 xdg/action_response_adapter().(func)));
583 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
584 }
585
586 /// Listens for the `ActionInvoked(UInt32, String)` signal.
587 ///
588 /// Prefer [`NotificationHandle::wait_for_action`] instead.
589 /// (xdg only)
590 #[cfg(all(feature = "dbus", not(feature = "zbus")))]
591 // #[deprecated(note="please use `NotificationHandle::wait_for_action`")]
592 pub fn handle_action<F>(id: u32, func: F) -> Resultrust-analyzer cargo notify-rust 4.18.0 error/Result#<()>
593 where
594 F: FnOncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnOnce#(&ActionResponserust-analyzer cargo notify-rust 4.18.0 response/ActionResponse#<'_>),
595 {
596 dbus_rsrust-analyzer cargo notify-rust 4.18.0 xdg/dbus_rs/::handle_actionrust-analyzer cargo notify-rust 4.18.0 xdg/dbus_rs/handle_action().(id, action_response_adapterrust-analyzer cargo notify-rust 4.18.0 xdg/action_response_adapter().(func))
597 }
598
599 /// Listens for the `ActionInvoked(UInt32, String)` signal.
600 ///
601 /// Prefer [`NotificationHandle::wait_for_action`] instead.
602 /// Both dbus-rs and zbus are compiled in; switch via the `$DBUSRS` environment variable.
603 #[cfg(all(feature = "dbus", feature = "zbus"))]
604 // #[deprecated(note="please use `NotificationHandle::wait_for_action`")]
605 pub fn handle_actionrust-analyzer cargo notify-rust 4.18.0 xdg/handle_action().<F>(id: u32, func: F) -> Resultrust-analyzer cargo notify-rust 4.18.0 error/Result#<()>
606 where
607 F: FnOncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnOnce#(&ActionResponserust-analyzer cargo notify-rust 4.18.0 response/ActionResponse#<'_>),
608 {
609 if stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::envrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/::varrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/var().(DBUS_SWITCH_VARrust-analyzer cargo notify-rust 4.18.0 xdg/DBUS_SWITCH_VAR.).is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().() {
610 dbus_rsrust-analyzer cargo notify-rust 4.18.0 xdg/dbus_rs/::handle_actionrust-analyzer cargo notify-rust 4.18.0 xdg/dbus_rs/handle_action().(id, action_response_adapterrust-analyzer cargo notify-rust 4.18.0 xdg/action_response_adapter().(func))
611 } else {
612 block_onrust-analyzer cargo zbus 5.19.0 utils/block_on().(zbus_rsrust-analyzer cargo notify-rust 4.18.0 xdg/zbus_rs/::handle_actionrust-analyzer cargo notify-rust 4.18.0 xdg/zbus_rs/handle_action().(id, action_response_adapterrust-analyzer cargo notify-rust 4.18.0 xdg/action_response_adapter().(func)));
613 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
614 }
615 }
616
617 /// Wraps an old-style `FnOnce(&ActionResponse)` into a new-style `FnOnce(&NotificationResponse)`
618 /// so legacy callers of [`handle_action`] keep working.
619 fn action_response_adapterrust-analyzer cargo notify-rust 4.18.0 xdg/action_response_adapter().<F>(func: F) -> impl FnOncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnOnce#(&NotificationResponserust-analyzer cargo notify-rust 4.18.0 response/NotificationResponse#)
620 where
621 F: FnOncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnOnce#(&ActionResponserust-analyzer cargo notify-rust 4.18.0 response/ActionResponse#<'_>),
622 {
623 move |response: &NotificationResponserust-analyzer cargo notify-rust 4.18.0 response/NotificationResponse#| match response {
624 NotificationResponserust-analyzer cargo notify-rust 4.18.0 response/NotificationResponse#::Defaultrust-analyzer cargo notify-rust 4.18.0 response/NotificationResponse#Default# => func(&ActionResponserust-analyzer cargo notify-rust 4.18.0 response/ActionResponse#::Customrust-analyzer cargo notify-rust 4.18.0 response/ActionResponse#Custom#("default")),
625 NotificationResponserust-analyzer cargo notify-rust 4.18.0 response/NotificationResponse#::Actionrust-analyzer cargo notify-rust 4.18.0 response/NotificationResponse#Action#(ref s) => func(&ActionResponserust-analyzer cargo notify-rust 4.18.0 response/ActionResponse#::Customrust-analyzer cargo notify-rust 4.18.0 response/ActionResponse#Custom#(s.as_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_str().())),
626 NotificationResponserust-analyzer cargo notify-rust 4.18.0 response/NotificationResponse#::Replyrust-analyzer cargo notify-rust 4.18.0 response/NotificationResponse#Reply#(_) => { /* XDG does not support inline replies */ }
627 NotificationResponserust-analyzer cargo notify-rust 4.18.0 response/NotificationResponse#::Closedrust-analyzer cargo notify-rust 4.18.0 response/NotificationResponse#Closed#(r) => func(&ActionResponserust-analyzer cargo notify-rust 4.18.0 response/ActionResponse#::Closedrust-analyzer cargo notify-rust 4.18.0 response/ActionResponse#Closed#(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().r)),
628 }
629 }