Debian Codegraph @

src/lib.rs

raw symbols SCIP
1 //! Desktop Notifications for Rust.
2 //!
3 //! Desktop notifications are popup messages generated to notify the user of certain events.
4 //!
5 //! ## Platform Support
6 //!
7 //! This library was originally conceived with the [XDG](https://en.wikipedia.org/wiki/XDG) notification specification in mind.
8 //! Since version 3.3 this crate also builds on macOS, however the semantics of the [XDG](https://en.wikipedia.org/wiki/XDG) specification and macOS `NSNotifications`
9 //! are quite different.
10 //! macOS support has grown significantly; most notification methods work on both backends.
11 //! Some methods are no-ops or backend-specific; see the [platform differences](#platform-differences) table.
12 //!
13 //! # Examples
14 //!
15 //! ## Example 1: Simple Notification
16 //!
17 //! ```no_run
18 //! # use notify_rust::*;
19 //! Notification::new()
20 //! .summary("Firefox News")
21 //! .body("This will almost look like a real firefox notification.")
22 //! .icon("firefox")
23 //! .timeout(Timeout::Milliseconds(6000)) //milliseconds
24 //! .show().unwrap();
25 //! ```
26 //!
27 //! ## Example 2: Persistent Notification
28 //!
29 //! ```no_run
30 //! # use notify_rust::*;
31 //! Notification::new()
32 //! .summary("Category:email")
33 //! .body("This has nothing to do with emails.\nIt should not go away until you acknowledge it.")
34 //! .icon("thunderbird")
35 //! .appname("thunderbird")
36 //! .hint(Hint::Category("email".to_owned()))
37 //! .hint(Hint::Resident(true)) // this is not supported by all implementations
38 //! .timeout(Timeout::Never) // this however is
39 //! .show().unwrap();
40 //! ```
41 //!
42 //! Careful! There are no checks whether you use hints twice.
43 //! It is possible to set `urgency=Low` AND `urgency=Critical`, in which case the behavior of the server is undefined.
44 //!
45 //! ## Example 3: Ask the user to do something
46 //!
47 //! ```no_run
48 //! # use notify_rust::*;
49 //! # #[cfg(all(unix, not(target_os = "macos")))]
50 //! Notification::new().summary("click me")
51 //! .action("default", "default")
52 //! .action("clicked", "click here")
53 //! .hint(Hint::Resident(true))
54 //! .show()
55 //! .unwrap()
56 //! .wait_for_action(|action| match action {
57 //! "default" => println!("you clicked \"default\""),
58 //! "clicked" => println!("that was correct"),
59 //! // here "__closed" is a hard coded keyword
60 //! "__closed" => println!("the notification was closed"),
61 //! _ => ()
62 //! });
63 //! ```
64 //!
65 //! ## Minimal Example
66 //!
67 //! You can omit almost everything
68 //!
69 //! ```no_run
70 //! # use notify_rust::Notification;
71 //! Notification::new().show();
72 //! ```
73 //!
74 //! more [examples](https://github.com/hoodie/notify-rust/tree/main/examples) in the repository.
75 //!
76 //! # Platform Differences
77 //! <details>
78 //! ✔︎ = works <br/>
79 //! - = will not compile
80 //!
81 //! ## `Notification`
82 //! | method | XDG | macOS (`NSUserNotifictation`) | macOS (`UNUserNotificationCenter`) | windows |
83 //! |------------------------------|----------|----------------------------- |------------------------------------|---------|
84 //! | `fn appname(...)` | ✔︎ | silent no-op | silent no-op | |
85 //! | `fn summary(...)` | ✔︎ | ✔︎ | ✔︎ | ✔︎ |
86 //! | `fn subtitle(...)` | | ✔︎ | ✔︎ | ✔︎ |
87 //! | `fn body(...)` | ✔︎ | ✔︎ | ✔︎ | ✔︎ |
88 //! | `fn icon(...)` | ✔︎ | silent no-op | silent no-op | |
89 //! | `fn image_path(...)` | ✔︎ | ✔︎ | ✔︎ | ✔︎ |
90 //! | `fn hint(...)` | ✔︎ | - | - | - |
91 //! | `fn timeout(...)` | ✔︎ | ignored | ✔︎ | ✔︎ |
92 //! | `fn urgency(...)` | ✔︎ | - | ✔︎ (→ `InterruptionLevel`) | ✔︎ |
93 //! | `fn interruption_level(...)` | | | ✔︎ | |
94 //! | `fn action(...)` | ✔︎ | ⚠︎ (labels only) | ✔︎ | |
95 //! | `fn id(...)` | ✔︎ (u32) | ignored | ✔︎ | |
96 //! | `fn show(...)` | ✔︎ | ✔︎ | ✔︎ | ✔︎ |
97 //! | `fn show_async(...)` | ✔︎ | | ✔︎ | |
98 //! | `fn schedule(...)` | | ✔︎ | ✔︎ | |
99 //!
100 //! ## `NotificationHandle`
101 //!
102 //! | method | XDG | macOS (`NSUserNotifictation`) | macOS (`UNUserNotification`) | windows |
103 //! |---------------------------|-----|-------------------------------|------------------------------|---------|
104 //! | `fn wait_for_action(...)` | ✔︎ | ✔︎ | ✔︎ | ✔︎ |
105 //! | `fn on_close(...)` | ✔︎ | ✔︎ | ✔︎ | ✔︎ |
106 //! | `fn close(...)` | ✔︎ | | ✔︎ | |
107 //! | `fn update(...)` | ✔︎ | | ✔︎ | |
108 //! | `fn id(...)` | ✔︎ | | ✔︎ | |
109 //!
110 //! ## Functions
111 //!
112 //! | | XDG | macOS | windows |
113 //! |--------------------------------------------|-----|-------|---------|
114 //! | `fn get_capabilities(...)` | ✔︎ | - | - |
115 //! | `fn get_server_information(...)` | ✔︎ | - | - |
116 //! | `fn set_application(...)` | - | ✔︎ | - |
117 //! | `fn get_bundle_identifier_or_default(...)` | - | ✔︎ | - |
118 //!
119 //!
120 //! ### Toggles
121 //!
122 //! Please use `target_os` toggles if you plan on using methods labeled with -.
123 //!
124 //! ```ignore
125 //! #[cfg(target_os = "macos")]
126 //! // or
127 //! // #### #[cfg(all(unix, not(target_os = "macos")))]
128 //! ```
129 //! </details>
130 //!
131
132 #![deny(
133 missing_copy_implementations,
134 trivial_casts,
135 trivial_numeric_casts,
136 unsafe_code,
137 unused_import_braces,
138 unused_qualifications
139 )]
140 #![warn(
141 missing_docs,
142 clippy::doc_markdown,
143 clippy::semicolon_if_nothing_returned,
144 clippy::single_match_else,
145 clippy::inconsistent_struct_constructor,
146 clippy::map_unwrap_or,
147 clippy::match_same_arms
148 )]
149
150 #[cfg(all(feature = "dbus", unix, not(target_os = "macos")))]
151 extern crate dbusrust-analyzer cargo notify-rust 4.18.0 dbus/;
152
153 #[cfg(target_os = "windows")]
154 extern crate winrt_notification;
155
156 #[macro_use]
157 #[cfg(all(feature = "images_no_default_features", unix, not(target_os = "macos")))]
158 extern crate lazy_staticrust-analyzer cargo notify-rust 4.18.0 lazy_static/;
159
160 pub mod errorrust-analyzer cargo notify-rust 4.18.0 error/;
161 mod hintsrust-analyzer cargo notify-rust 4.18.0 hints/;
162 mod miniverrust-analyzer cargo notify-rust 4.18.0 miniver/;
163 mod notificationrust-analyzer cargo notify-rust 4.18.0 notification/;
164 mod notification_idrust-analyzer cargo notify-rust 4.18.0 notification_id/;
165 mod responserust-analyzer cargo notify-rust 4.18.0 response/;
166 mod timeoutrust-analyzer cargo notify-rust 4.18.0 timeout/;
167 pub(craterust-analyzer cargo notify-rust 4.18.0 crate/) mod urgencyrust-analyzer cargo notify-rust 4.18.0 urgency/;
168
169 #[cfg(target_os = "macos")]
170 mod macos;
171
172 #[cfg(all(target_os = "macos", feature = "preview-macos-un"))]
173 pub use mac_usernotifications::InterruptionLevel;
174
175 #[cfg(target_os = "windows")]
176 mod windows;
177
178 #[cfg(all(unix, not(target_os = "macos")))]
179 mod xdgrust-analyzer cargo notify-rust 4.18.0 xdg/;
180
181 #[cfg(all(feature = "images_no_default_features", unix, not(target_os = "macos")))]
182 mod imagerust-analyzer cargo notify-rust 4.18.0 image/;
183
184 #[cfg(all(target_os = "macos", not(feature = "preview-macos-un")))]
185 pub use macos::NotificationHandle;
186 #[cfg(target_os = "macos")]
187 pub use macos::{get_bundle_identifier_or_default, set_application};
188
189 #[cfg(all(target_os = "macos", feature = "preview-macos-un"))]
190 pub use macos::{
191 check_bundle, get_notification_settings, get_notification_settings_blocking, request_auth,
192 request_auth_blocking, NotificationHandle,
193 };
194
195 #[cfg(all(
196 any(feature = "dbus", feature = "zbus"),
197 unix,
198 not(target_os = "macos")
199 ))]
200 pub use craterust-analyzer cargo notify-rust 4.18.0 crate/::xdgrust-analyzer cargo notify-rust 4.18.0 xdg/::{
201 dbus_stackrust-analyzer cargo notify-rust 4.18.0 xdg/dbus_stack()., get_capabilitiesrust-analyzer cargo notify-rust 4.18.0 xdg/get_capabilities()., get_server_informationrust-analyzer cargo notify-rust 4.18.0 xdg/get_server_information()., handle_actionrust-analyzer cargo notify-rust 4.18.0 xdg/handle_action()., DbusStackrust-analyzer cargo notify-rust 4.18.0 xdg/DbusStack#,
202 NotificationHandlerust-analyzer cargo notify-rust 4.18.0 xdg/NotificationHandle#,
203 };
204
205 // Cross-platform response types (available on all platforms).
206 pub use craterust-analyzer cargo notify-rust 4.18.0 crate/::notification_idrust-analyzer cargo notify-rust 4.18.0 notification_id/::NotificationIdrust-analyzer cargo notify-rust 4.18.0 notification_id/NotificationId#;
207 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#;
208 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#, CloseReasonrust-analyzer cargo notify-rust 4.18.0 response/CloseReason#, NotificationResponserust-analyzer cargo notify-rust 4.18.0 response/NotificationResponse#, ResponseHandlerrust-analyzer cargo notify-rust 4.18.0 response/ResponseHandler#};
209
210 pub use craterust-analyzer cargo notify-rust 4.18.0 crate/::hintsrust-analyzer cargo notify-rust 4.18.0 hints/::Hintrust-analyzer cargo notify-rust 4.18.0 hints/Hint#;
211
212 #[cfg(all(feature = "images_no_default_features", unix, not(target_os = "macos")))]
213 pub use craterust-analyzer cargo notify-rust 4.18.0 crate/::imagerust-analyzer cargo notify-rust 4.18.0 image/::{Imagerust-analyzer cargo notify-rust 4.18.0 image/Image#, ImageErrorrust-analyzer cargo notify-rust 4.18.0 image/ImageError#};
214
215 #[cfg_attr(
216 all(target_os = "macos", not(feature = "preview-macos-un")),
217 deprecated(note = "Urgency is not supported on macOS (NSUserNotificationCenter path)")
218 )]
219 pub use craterust-analyzer cargo notify-rust 4.18.0 crate/::urgencyrust-analyzer cargo notify-rust 4.18.0 urgency/::Urgencyrust-analyzer cargo notify-rust 4.18.0 urgency/Urgency#;
220
221 pub use craterust-analyzer cargo notify-rust 4.18.0 crate/::{notificationrust-analyzer cargo notify-rust 4.18.0 notification/::Notificationrust-analyzer cargo notify-rust 4.18.0 notification/Notification#, timeoutrust-analyzer cargo notify-rust 4.18.0 timeout/::Timeoutrust-analyzer cargo notify-rust 4.18.0 timeout/Timeout#};
222
223 #[cfg(all(feature = "images_no_default_features", unix, not(target_os = "macos")))]
224 lazy_staticrust-analyzer cargo lazy_static 1.5.0 lazy_static!! {
225 /// Read once at runtime. Needed for images.
226 pub static ref SPEC_VERSIONrust-analyzer cargo notify-rust 4.18.0 SPEC_VERSION#: miniverrust-analyzer cargo notify-rust 4.18.0 miniver/::Versionrust-analyzer cargo notify-rust 4.18.0 miniver/Version# =
227 get_server_informationrust-analyzer cargo notify-rust 4.18.0 xdg/get_server_information().()
228 .and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]and_then().(|info| info.spec_versionrust-analyzer cargo notify-rust 4.18.0 xdg/ServerInformation#spec_version..parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().::<miniverrust-analyzer cargo notify-rust 4.18.0 miniver/::Versionrust-analyzer cargo notify-rust 4.18.0 miniver/Version#>())
229 .unwrap_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_or_else().(|_| miniverrust-analyzer cargo notify-rust 4.18.0 miniver/::Versionrust-analyzer cargo notify-rust 4.18.0 miniver/Version#::newrust-analyzer cargo notify-rust 4.18.0 miniver/impl#[Version]new().(1,1));
230 }
231
232 /// Return value of [`get_server_information()`](crate::get_server_information).
233 #[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:)]
234 pub struct ServerInformationrust-analyzer cargo notify-rust 4.18.0 ServerInformation# {
235 /// The product name of the server.
236 pub namerust-analyzer cargo notify-rust 4.18.0 ServerInformation#name.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#,
237 /// The vendor name.
238 pub vendorrust-analyzer cargo notify-rust 4.18.0 ServerInformation#vendor.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#,
239 /// The server's version string.
240 pub versionrust-analyzer cargo notify-rust 4.18.0 ServerInformation#version.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#,
241 /// The specification version the server is compliant with.
242 pub spec_versionrust-analyzer cargo notify-rust 4.18.0 ServerInformation#spec_version.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#,
243 }