/
single.rs
42 lines (37 loc) · 1.3 KB
/
single.rs
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
// Copyright 2020-2022 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
use std::path::Path;
use win7_notifications::{Notification, Timeout};
use winit::{
event::{Event, StartCause},
event_loop::{ControlFlow, EventLoop},
};
fn main() {
let event_loop = EventLoop::new().unwrap();
let path = concat!(env!("CARGO_MANIFEST_DIR"), "/examples/icon.png");
let (icon, w, h) = load_icon(Path::new(path));
event_loop
.run(move |event, event_loop| {
event_loop.set_control_flow(ControlFlow::Poll);
if let Event::NewEvents(StartCause::Init) = event {
Notification::new()
.appname("App name")
.summary("Critical Error")
.body("Just kidding, this is just the notification example.")
.icon(icon.clone(), w, h)
.timeout(Timeout::Default)
.show()
.unwrap();
}
})
.unwrap();
}
fn load_icon(path: &Path) -> (Vec<u8>, u32, u32) {
let image = image::open(path)
.expect("Failed to open icon path")
.into_rgba8();
let (width, height) = image.dimensions();
let rgba = image.into_raw();
(rgba, width, height)
}