File: hints.rs

package info (click to toggle)
rust-notify-rust 4.11.6-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 604 kB
  • sloc: sh: 18; makefile: 4
file content (106 lines) | stat: -rw-r--r-- 2,924 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#![allow(unused_imports, dead_code)]
use std::{thread::sleep, time::Duration};

#[cfg(all(feature = "images", unix, not(target_os = "macos")))]
use notify_rust::Image;
use notify_rust::{Hint, Notification, Urgency::*};

fn freeze(message: &str) {
    println!("{}\n", message);
    let mut _devnull = String::new();
    let _ = std::io::stdin().read_line(&mut _devnull);
}

#[cfg(any(target_os = "windows", target_os = "macos"))]
fn main() {
    println!("this is an xdg only feature")
}

#[cfg(all(unix, not(target_os = "macos")))]
fn main() -> Result<(), Box<dyn std::error::Error>> {
    println!("Pay close attention to the output of:");
    println!("$ dbus-monitor \"interface=org.freedesktop.Notifications\"");

    freeze("actionicons");
    Notification::new().hint(Hint::ActionIcons(true)).show()?;

    freeze("urgency: low, medium, high");
    Notification::new()
        .summary("low")
        .hint(Hint::Urgency(Low))
        .show()?;
    Notification::new()
        .summary("normal")
        .hint(Hint::Urgency(Normal))
        .show()?;
    Notification::new()
        .summary("critical")
        .hint(Hint::Urgency(Critical))
        .show()?;

    freeze("category");
    Notification::new()
        .hint(Hint::Category("device.removed".into()))
        .show()?;

    freeze("DesktopEntry");
    Notification::new()
        .summary("desktop entry")
        .hint(Hint::DesktopEntry("firefox".into()))
        .show()?;

    freeze("ImagePath");
    Notification::new()
        .summary("iconpath")
        .hint(Hint::ImagePath(
            "/usr/share/icons/hicolor/128x128/apps/firefox.png".into(),
        ))
        .show()?;

    freeze("Resident");
    Notification::new()
        .summary("resident")
        .hint(Hint::Resident(true))
        .show()?;

    freeze("SoundFile");
    Notification::new()
        .summary("soundfile")
        .hint(Hint::SoundFile(
            "/usr/share/sounds/alsa/Front_Left.wav".to_owned(),
        ))
        .hint(Hint::SoundName("system sound".to_owned()))
        .hint(Hint::SuppressSound(false))
        .show()?;

    freeze("Transient");
    Notification::new()
        .summary("transient")
        .hint(Hint::Transient(false))
        .show()?;

    freeze("X and Y");
    Notification::new()
        .hint(Hint::X(200))
        .hint(Hint::Y(200))
        .show()?;

    #[cfg(all(feature = "images", unix, not(target_os = "macos")))]
    {
        freeze("ImageData");
        let mut image_data = vec![0; 128 * 128 * 3];
        for i in 0..128 * 128 * 3 {
            image_data[i] = (i % 256) as u8;
        }
        Notification::new()
            .hint(Hint::ImageData(
                Image::from_rgb(128, 128, image_data).unwrap(),
            ))
            .summary("You should see stripes in this notification");
    }

    Ok(())

    // freeze("Custom");
    // Notification::new().hint(Hint::Custom("foo","bar")).show();
}