File: images.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 (58 lines) | stat: -rw-r--r-- 1,562 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
#![allow(unused_imports)]

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

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

#[cfg(all(not(feature = "images"), unix, not(target_os = "macos")))]
fn main() {
    println!("please build with '--features=images'")
}

#[cfg(all(
    feature = "images",
    unix,
    not(target_os = "macos"),
    not(target_os = "windows")
))]
fn main() -> Result<(), Box<dyn std::error::Error>> {
    fn image_data() -> Vec<u8> {
        let mut image_data = vec![0; 128 * 128 * 3];
        for i in 0..128 * 128 * 3 {
            image_data[i] = (i % 256) as u8;
        }
        image_data
    }

    Notification::new()
        .summary("Generated Image (.hint())")
        .body("You should see stripes in this notification")
        .hint(Hint::ImageData(Image::from_rgb(128, 128, image_data())?))
        .show()?;

    Notification::new()
        .summary("Generated Image (.image_data())")
        .body("You should see stripes in this notification")
        .image_data(Image::from_rgb(128, 128, image_data())?)
        .show()?;

    Notification::new()
        .summary(".image()")
        .body("Trying to open an image")
        .image("./examples/octodex.jpg")?
        .show()?;

    Notification::new()
        .summary(".image_path()")
        .body("Trying to open an image")
        .image_path("./examples/octodex.jpg")
        .show()?;

    Ok(())
}