Closed qarmin closed 2 years ago
that will not work as we expect it include_str! work in compile not in runtime
Yes it works in compile time(builder don't need to be set in runtime), so this code https://github.com/xlmnxp/blue-recorder/blob/58585c3210be6707597d0cbcdcb5214638b2c95f/src/main.rs#L36-L52
let builder: Builder;
let user_interface_path_abs = {
let mut current_exec_dir = std::env::current_exe().unwrap();
current_exec_dir.pop();
current_exec_dir
}
.join(Path::new("interfaces/main.ui"));
if user_interface_path_abs.exists() {
builder = Builder::from_file(user_interface_path_abs);
} else {
builder = Builder::from_file(
std::env::var("INTERFACES_DIR")
.unwrap_or(String::from("interfaces/"))
.add("main.ui"),
);
}
could be simplified to
let ui_src = include_str!("../interfaces/main.ui").to_string();
let builder = Builder::from_string(ui_src.as_str());
Yes it works in compile time(builder don't need to be set in runtime), so this code
let builder: Builder; let user_interface_path_abs = { let mut current_exec_dir = std::env::current_exe().unwrap(); current_exec_dir.pop(); current_exec_dir } .join(Path::new("interfaces/main.ui")); if user_interface_path_abs.exists() { builder = Builder::from_file(user_interface_path_abs); } else { builder = Builder::from_file( std::env::var("INTERFACES_DIR") .unwrap_or(String::from("interfaces/")) .add("main.ui"), ); }
could be simplified to
let ui_src = include_str!("../interfaces/main.ui").to_string(); let builder = Builder::from_string(ui_src.as_str());
That will remove the need to INTERFACES_DIR
environment
I did it 👍🏼
thank you
The problem is that
ui
is loaded in runtime.GTK-rs allows to include ui into binary:
https://github.com/qarmin/czkawka/blob/aeeb59d9a6b3429f4c35a9c1f71914293b4981d6/czkawka_gui/src/gui_data.rs#L85-L89