forked from jpochyla/psst
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.rs
46 lines (41 loc) · 1.18 KB
/
build.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
43
44
45
46
fn main() {
#[cfg(windows)]
add_windows_icon();
}
#[cfg(windows)]
fn add_windows_icon() {
use image::{
codecs::ico::{IcoEncoder, IcoFrame},
ColorType,
};
let ico_path = "assets/logo.ico";
if std::fs::metadata(ico_path).is_err() {
let ico_frames = load_images();
save_ico(&ico_frames, ico_path);
}
let mut res = winres::WindowsResource::new();
res.set_icon(ico_path);
res.compile().expect("Could not attach exe icon");
fn load_images() -> Vec<IcoFrame<'static>> {
let sizes = vec![32, 64, 128, 256];
sizes
.iter()
.map(|s| {
IcoFrame::as_png(
image::open(format!("assets/logo_{}.png", s))
.unwrap()
.as_bytes(),
*s,
*s,
ColorType::Rgba8,
)
.unwrap()
})
.collect()
}
fn save_ico(images: &[IcoFrame<'_>], ico_path: &str) {
let file = std::fs::File::create(ico_path).unwrap();
let encoder = IcoEncoder::new(file);
encoder.encode_images(images).unwrap();
}
}