118 lines
3.1 KiB
Rust
118 lines
3.1 KiB
Rust
use std::{fs, path::Path};
|
|
|
|
use quote::quote;
|
|
use serde::Deserialize;
|
|
|
|
fn main() {
|
|
let lib = probe_libqalculate();
|
|
build_cxx_bridge(&lib);
|
|
emit_cargo_metadata();
|
|
load_config();
|
|
}
|
|
|
|
fn probe_libqalculate() -> pkg_config::Library {
|
|
pkg_config::probe_library("libqalculate")
|
|
.expect("libqalculate not found — install it via your package manager")
|
|
}
|
|
|
|
fn build_cxx_bridge(lib: &pkg_config::Library) {
|
|
cxx_build::bridge("src/update.rs")
|
|
.file("src/qalc_bridge.cc")
|
|
.includes(&lib.include_paths)
|
|
.include("src")
|
|
.flag_if_supported("-std=c++17")
|
|
.compiler("g++")
|
|
.compile("qalc-bridge");
|
|
}
|
|
|
|
fn emit_cargo_metadata() {
|
|
let out_dir = std::env::var("OUT_DIR").unwrap();
|
|
println!("cargo:rustc-link-search=native={out_dir}");
|
|
println!("cargo:rustc-link-lib=static=qalc-bridge");
|
|
|
|
for file in &["src/update.rs", "src/qalc_bridge.cc", "src/qalc_bridge.h"] {
|
|
println!("cargo:rerun-if-changed={file}");
|
|
}
|
|
}
|
|
|
|
fn load_config() {
|
|
println!("cargo:rerun-if-changed=config.toml");
|
|
|
|
let config: Config =
|
|
toml::from_str(&fs::read_to_string(Path::new("./config.toml")).unwrap_or_default())
|
|
.unwrap_or_default();
|
|
|
|
let theme = if !config.enable {
|
|
quote! {
|
|
use iced::Theme;
|
|
use crate::state::State;
|
|
|
|
pub const BORDER_RADIUS: f32 = 15.;
|
|
pub const BORDER_WIDTH: f32 = 2.;
|
|
pub const PADDING: f32 = 8.;
|
|
pub const WINDOW_SIZE: (u32, u32) = (400, 400);
|
|
pub const BG_ALPHA: f32 = 0.75;
|
|
|
|
pub fn theme(_state: &State) -> Theme {
|
|
match dark_light::detect() {
|
|
Ok(dark_light::Mode::Light) => Theme::Light,
|
|
_ => Theme::CatppuccinMocha,
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
quote! {
|
|
use iced::Theme;
|
|
use crate::state::State;
|
|
|
|
pub const BORDER_RADIUS: f32 = #&config.border.radius;
|
|
pub const BORDER_WIDTH: f32 = #&config.border.width;
|
|
pub const PADDING: f32 = #&config.border.padding;
|
|
pub const WINDOW_SIZE: (u32, u32) = (#(&config.window_size.width), #&config.window_size.height);
|
|
pub const BG_ALPHA: f32 = 0.75;
|
|
|
|
pub fn theme(_state: &State) -> Theme {
|
|
match dark_light::detect() {
|
|
Ok(dark_light::Mode::Light) => Theme::Light,
|
|
_ => Theme::CatppuccinMocha,
|
|
}
|
|
}
|
|
}
|
|
};
|
|
|
|
let out_dir = std::env::var("OUT_DIR").unwrap();
|
|
std::fs::write(format!("{out_dir}/theme.rs"), theme.to_string()).unwrap();
|
|
}
|
|
|
|
#[derive(Deserialize, Default)]
|
|
struct WindowSize {
|
|
width: u32,
|
|
height: u32,
|
|
}
|
|
|
|
#[derive(Deserialize, Default)]
|
|
struct Border {
|
|
radius: f32,
|
|
width: f32,
|
|
padding: f32,
|
|
}
|
|
|
|
#[derive(Deserialize, Default)]
|
|
struct Palette {
|
|
background: String,
|
|
text: String,
|
|
primary: String,
|
|
success: String,
|
|
warning: String,
|
|
danger: String,
|
|
}
|
|
|
|
#[derive(Deserialize, Default)]
|
|
struct Config {
|
|
enable: bool,
|
|
transparency: f32,
|
|
|
|
window_size: WindowSize,
|
|
border: Border,
|
|
palette: Palette,
|
|
}
|