-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.rs
64 lines (55 loc) · 2.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
use image::Rgba;
use slint_build::CompilerConfiguration;
use std::{env, fs, path::Path};
const DARK_INACTIVE_PNG_ICON: &[u8] = include_bytes!("assets/icon-dark-inactive.png");
const DARK_ACTIVE_PNG_ICON: &[u8] = include_bytes!("assets/icon-dark-active.png");
const LIGHT_INACTIVE_PNG_ICON: &[u8] = include_bytes!("assets/icon-light-inactive.png");
const LIGHT_ACTIVE_PNG_ICON: &[u8] = include_bytes!("assets/icon-light-active.png");
fn convert(img: &[u8]) -> Result<Vec<u8>, image::ImageError> {
let img = image::load_from_memory(img)?;
let mut img = img.to_rgba8();
for Rgba(pixel) in img.pixels_mut() {
*pixel = u32::from_be_bytes(*pixel).rotate_right(8).to_be_bytes();
}
Ok(img.into_raw())
}
fn main() {
slint_build::compile_with_config(
"ui/main.slint",
CompilerConfiguration::new().with_style("fluent-dark".to_string()),
)
.unwrap();
if env::var_os("CARGO_CFG_TARGET_OS").unwrap() == "linux" {
let out_dir = &env::var_os("OUT_DIR").unwrap();
let out_path = Path::new(out_dir);
fs::write(
out_path.join("linux-dark-inactive-icon"),
convert(DARK_INACTIVE_PNG_ICON).unwrap(),
)
.unwrap();
fs::write(
out_path.join("linux-dark-active-icon"),
convert(DARK_ACTIVE_PNG_ICON).unwrap(),
)
.unwrap();
fs::write(
out_path.join("linux-light-inactive-icon"),
convert(LIGHT_INACTIVE_PNG_ICON).unwrap(),
)
.unwrap();
fs::write(
out_path.join("linux-light-active-icon"),
convert(LIGHT_ACTIVE_PNG_ICON).unwrap(),
)
.unwrap();
}
if env::var_os("CARGO_CFG_TARGET_OS").unwrap() == "windows" {
embed_resource::compile("assets/icons.rc", embed_resource::NONE);
}
println!("cargo:rerun-if-changed=assets/icons.rc");
println!("cargo:rerun-if-changed=assets/icon-dark-inactive.ico");
println!("cargo:rerun-if-changed=assets/icon-dark-active.ico");
println!("cargo:rerun-if-changed=assets/icon-light-inactive.ico");
println!("cargo:rerun-if-changed=assets/icon-light-active.ico");
println!("cargo:rerun-if-changed=build.rs");
}