-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathnotification.rs
38 lines (33 loc) · 970 Bytes
/
notification.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
use gdk_pixbuf::gio::FileIcon;
use relm4::gtk::gio::{prelude::ApplicationExt, Notification};
use relm4::gtk::{IconLookupFlags, IconTheme, TextDirection};
pub fn log_result(msg: &str, notify: bool) {
println!("{}", msg);
if notify {
show_notification(msg);
}
}
fn show_notification(msg: &str) {
// construct
let notification = Notification::new("Satty");
notification.set_body(Some(msg));
// lookup sattys icon
let theme = IconTheme::default();
if theme.has_icon("satty") {
if let Some(icon_file) = theme
.lookup_icon(
"satty",
&[],
96,
1,
TextDirection::Ltr,
IconLookupFlags::empty(),
)
.file()
{
notification.set_icon(&FileIcon::new(&icon_file));
}
}
// send notification
relm4::main_application().send_notification(None, ¬ification);
}