| 1 | //! Show Volume example |
| 2 | //! |
| 3 | //! Only works on unity |
| 4 | //! |
| 5 | |
| 6 | #![allow(unused_imports, dead_code)] |
| 7 | use notify_rustrust-analyzer cargo notify-rust 4.18.0 crate/::Hintrust-analyzer cargo notify-rust 4.18.0 hints/Hint#; |
| 8 | use notify_rustrust-analyzer cargo notify-rust 4.18.0 crate/::Notificationrust-analyzer cargo notify-rust 4.18.0 notification/Notification#; |
| 9 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::timerust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/::Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#; |
| 10 | |
| 11 | enum Volumerust-analyzer cargo notify-rust 4.18.0 Volume# { |
| 12 | Mutedrust-analyzer cargo notify-rust 4.18.0 Volume#Muted#, |
| 13 | Percentrust-analyzer cargo notify-rust 4.18.0 Volume#Percent#(i32), |
| 14 | } |
| 15 | |
| 16 | #[cfg(all(unix, not(target_os = "macos")))] |
| 17 | fn show_volumerust-analyzer cargo notify-rust 4.18.0 show_volume().(percent: Volumerust-analyzer cargo notify-rust 4.18.0 Volume#) { |
| 18 | let icon = match percent { |
| 19 | Volumerust-analyzer cargo notify-rust 4.18.0 Volume#::Mutedrust-analyzer cargo notify-rust 4.18.0 Volume#Muted# => "notification-audio-volume-muted", |
| 20 | Volumerust-analyzer cargo notify-rust 4.18.0 Volume#::Percentrust-analyzer cargo notify-rust 4.18.0 Volume#Percent#(0) => "notification-audio-volume-off", |
| 21 | Volumerust-analyzer cargo notify-rust 4.18.0 Volume#::Percentrust-analyzer cargo notify-rust 4.18.0 Volume#Percent#(x) if x rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]lt().33 => "notification-audio-volume-low", |
| 22 | Volumerust-analyzer cargo notify-rust 4.18.0 Volume#::Percentrust-analyzer cargo notify-rust 4.18.0 Volume#Percent#(x) if x rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]lt().67 => "notification-audio-volume-medium", |
| 23 | _ => "notification-audio-volume-high", |
| 24 | }; |
| 25 | |
| 26 | let value = match percent { |
| 27 | Volumerust-analyzer cargo notify-rust 4.18.0 Volume#::Mutedrust-analyzer cargo notify-rust 4.18.0 Volume#Muted# => 0, |
| 28 | Volumerust-analyzer cargo notify-rust 4.18.0 Volume#::Percentrust-analyzer cargo notify-rust 4.18.0 Volume#Percent#(p) => p, |
| 29 | }; |
| 30 | |
| 31 | Notificationrust-analyzer cargo notify-rust 4.18.0 notification/Notification#::newrust-analyzer cargo notify-rust 4.18.0 notification/impl#[Notification]new().() |
| 32 | .summaryrust-analyzer cargo notify-rust 4.18.0 notification/impl#[Notification]summary().(" ") |
| 33 | .iconrust-analyzer cargo notify-rust 4.18.0 notification/impl#[Notification]icon().(icon) |
| 34 | .hintrust-analyzer cargo notify-rust 4.18.0 notification/impl#[Notification]hint().(Hintrust-analyzer cargo notify-rust 4.18.0 hints/Hint#::SoundNamerust-analyzer cargo notify-rust 4.18.0 hints/Hint#SoundName#("audio-volume-change".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().())) |
| 35 | .hintrust-analyzer cargo notify-rust 4.18.0 notification/impl#[Notification]hint().(Hintrust-analyzer cargo notify-rust 4.18.0 hints/Hint#::Customrust-analyzer cargo notify-rust 4.18.0 hints/Hint#Custom#("synchronous".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), "volume".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().())) |
| 36 | .hintrust-analyzer cargo notify-rust 4.18.0 notification/impl#[Notification]hint().(Hintrust-analyzer cargo notify-rust 4.18.0 hints/Hint#::CustomIntrust-analyzer cargo notify-rust 4.18.0 hints/Hint#CustomInt#("value".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), value)) |
| 37 | .showrust-analyzer cargo notify-rust 4.18.0 notification/impl#[Notification]show().() |
| 38 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 39 | } |
| 40 | |
| 41 | #[cfg(any(windows, target_os = "macos"))] |
| 42 | fn main() { |
| 43 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("this is an xdg only feature") |
| 44 | } |
| 45 | |
| 46 | #[cfg(all(unix, not(target_os = "macos")))] |
| 47 | fn mainrust-analyzer cargo notify-rust 4.18.0 main().() { |
| 48 | show_volumerust-analyzer cargo notify-rust 4.18.0 show_volume().(Volumerust-analyzer cargo notify-rust 4.18.0 Volume#::Mutedrust-analyzer cargo notify-rust 4.18.0 Volume#Muted#); |
| 49 | for i in 1..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#11 { |
| 50 | stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::threadrust-analyzer cargo std https://github.com/rust-lang/rust/library/std thread/::sleeprust-analyzer cargo std https://github.com/rust-lang/rust/library/std thread/functions/sleep().(Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#::from_millisrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/impl#[Duration]from_millis().(1_000)); |
| 51 | show_volumerust-analyzer cargo notify-rust 4.18.0 show_volume().(Volumerust-analyzer cargo notify-rust 4.18.0 Volume#::Percentrust-analyzer cargo notify-rust 4.18.0 Volume#Percent#(i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Mul<Self>`]mul().10)); |
| 52 | } |
| 53 | } |