| 1 | #![allow(dead_code)] |
| 2 | use notify_rust::Notification; |
| 3 | use std::time::Duration; |
| 4 | |
| 5 | #[cfg(target_os = "windows")] |
| 6 | fn main() { |
| 7 | println!("This is not a windows feature") |
| 8 | } |
| 9 | |
| 10 | #[cfg(all(unix, not(target_os = "macos")))] |
| 11 | fn update_via_handle() { |
| 12 | let mut notification_handle = Notification::new() |
| 13 | .summary("First Notification") |
| 14 | .body("This notification will be changed!") |
| 15 | .icon("dialog-warning") |
| 16 | .show() |
| 17 | .unwrap(); |
| 18 | |
| 19 | std::thread::sleep(Duration::from_millis(1_500)); |
| 20 | |
| 21 | notification_handle |
| 22 | .appname("foo") // changing appname to keep plasma from merging the new and the old one |
| 23 | .icon("dialog-ok") |
| 24 | .body("<b>This</b> has been changed through the notification_handle"); |
| 25 | |
| 26 | notification_handle.update().unwrap(); |
| 27 | } |
| 28 | |
| 29 | #[allow(dead_code)] |
| 30 | #[cfg(all(unix, not(target_os = "macos")))] |
| 31 | fn update_via_manually_stored_id() { |
| 32 | let handle = Notification::new() |
| 33 | .summary("First Notification") |
| 34 | .body("This notification will be changed!") |
| 35 | .icon("dialog-warning") |
| 36 | .show() |
| 37 | .unwrap(); |
| 38 | |
| 39 | let id = handle.id(); |
| 40 | std::thread::sleep(Duration::from_millis(1_500)); |
| 41 | |
| 42 | Notification::new() |
| 43 | .appname("foo") // changing appname to keep plasma from merging the new and the old one |
| 44 | .icon("dialog-ok") |
| 45 | .body("<b>This</b> has been changed by sending a new notification with the same id") |
| 46 | .id(id) |
| 47 | .show() |
| 48 | .unwrap(); |
| 49 | } |
| 50 | |
| 51 | fn recycling_one_id() { |
| 52 | for i in 1..5 { |
| 53 | let id = 6666; // you should probably not do this at all |
| 54 | std::thread::sleep(Duration::from_millis(500)); |
| 55 | Notification::new() |
| 56 | .icon("dialog-ok") |
| 57 | .body(&format!("notification{i}")) |
| 58 | .id(id) |
| 59 | .show() |
| 60 | .unwrap(); |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | #[cfg(target_os = "macos")] |
| 65 | fn main() { |
| 66 | println!("this is a xdg only feature") |
| 67 | } |
| 68 | |
| 69 | #[cfg(all(unix, not(target_os = "macos")))] |
| 70 | fn main() { |
| 71 | // please use the handle to update a notification |
| 72 | update_via_handle(); |
| 73 | |
| 74 | //// If your really have to, store the if yourself |
| 75 | // update_via_manually_stored_id(); |
| 76 | |
| 77 | //// or come up with your own don't do this: |
| 78 | recycling_one_id() |
| 79 | } |