Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Project crashes due unavalibity of ui files when compiling app from crates.io #25

Closed
qarmin opened this issue Jan 1, 2022 · 5 comments

Comments

@qarmin
Copy link

qarmin commented Jan 1, 2022

The problem is that ui is loaded in runtime.

GTK-rs allows to include ui into binary:

        let glade_src = include_str!("../ui/main_window.glade").to_string();
        let builder = Builder::from_string(glade_src.as_str());

        //// Windows
        let window_main: gtk::Window = builder.object("window_main").unwrap();

https://github.com/qarmin/czkawka/blob/aeeb59d9a6b3429f4c35a9c1f71914293b4981d6/czkawka_gui/src/gui_data.rs#L85-L89

@xlmnxp
Copy link
Owner

xlmnxp commented Jan 1, 2022

that will not work as we expect it
include_str! work in compile not in runtime

@qarmin
Copy link
Author

qarmin commented Jan 1, 2022

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"),
);
}

 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());

@xlmnxp
Copy link
Owner

xlmnxp commented Jan 2, 2022

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"),
);
}

 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

@xlmnxp
Copy link
Owner

xlmnxp commented Jan 14, 2022

I did it 👍🏼

@xlmnxp xlmnxp closed this as completed Jan 14, 2022
@xlmnxp
Copy link
Owner

xlmnxp commented Jan 14, 2022

thank you

ochibani pushed a commit to ochibani/blue-recorder that referenced this issue Jan 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants