diff --git a/Cargo.toml b/Cargo.toml index 6951ba40..c91819b5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,6 +2,7 @@ authors = ["Daniel Garcia "] name = "fractal" version = "0.1.0" +build = "build.rs" [dependencies] gdk = "0.6.0" diff --git a/build.rs b/build.rs index 05ce6713..df197c8d 100644 --- a/build.rs +++ b/build.rs @@ -2,7 +2,7 @@ use std::env; use std::fs::File; use std::io::Write; use std::path::Path; - +use std::process::Command; fn main() { let out_dir = env::var("OUT_DIR").unwrap(); @@ -20,4 +20,11 @@ fn main() { ", fractal_res); f.write_all(code.as_bytes()).unwrap(); + + // Compile Gresource + Command::new("glib-compile-resources") + .args(&["--generate", "resources.xml"]) + .current_dir("res") + .status() + .unwrap(); } diff --git a/res/resources.gresource b/res/resources.gresource new file mode 100644 index 00000000..75c3cec6 Binary files /dev/null and b/res/resources.gresource differ diff --git a/res/resources.xml b/res/resources.xml new file mode 100644 index 00000000..61500683 --- /dev/null +++ b/res/resources.xml @@ -0,0 +1,8 @@ + + + + main_window.glade + fractal.svg + app.css + + diff --git a/src/app.rs b/src/app.rs index 18921f22..883a601b 100644 --- a/src/app.rs +++ b/src/app.rs @@ -1221,7 +1221,7 @@ impl App { let bk = Backend::new(tx); let apptx = bk.run(); - let gtk_builder = gtk::Builder::new_from_file(&config::datadir("main_window.glade")); + let gtk_builder = gtk::Builder::new_from_resource("/org/gnome/fractal/main_window.glade"); let op = Arc::new(Mutex::new(AppOp { gtk_builder: gtk_builder.clone(), load_more_btn: gtk::Button::new_with_label("Load more messages"), @@ -1376,7 +1376,9 @@ impl App { .expect("Couldn't find main_window in ui file."); window.set_title("Fractal"); - let _ = window.set_icon_from_file(&config::datadir("fractal.svg")); + let pxbf = Pixbuf::new_from_resource("/org/gnome/fractal/fractal.svg").unwrap(); + let _ = window.set_icon(&pxbf); + // let _ = window.set_icon_from_file(&config::datadir("fractal.svg")); window.show_all(); let op = self.op.clone(); @@ -1685,10 +1687,11 @@ impl App { glib::set_prgname(Some("fractal")); let provider = gtk::CssProvider::new(); - let uri = config::datadir("app.css"); - if let Err(_) = provider.load_from_path(&uri) { - println!("Error: Failed to add application style"); - } + provider.load_from_resource("/org/gnome/fractal/app.css"); + // let uri = config::datadir("app.css"); + // if let Err(_) = provider.load_from_path(&uri) { + // println!("Error: Failed to add application style"); + // } gtk::StyleContext::add_provider_for_screen(&gdk::Screen::get_default().unwrap(), &provider, 600); gtk::main(); diff --git a/src/build.rs b/src/build.rs new file mode 100644 index 00000000..e69de29b diff --git a/src/main.rs b/src/main.rs index 52b58195..ffe11c71 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,7 @@ + +extern crate glib; +extern crate gio; + #[macro_use] extern crate serde_json; #[macro_use] @@ -11,11 +15,13 @@ mod cache; mod backend; mod model; mod app; +mod static_resources; use app::App; fn main() { + static_resources::init().expect("GResource initialization failed."); let app = App::new(); app.run(); } diff --git a/src/static_resources.rs b/src/static_resources.rs new file mode 100644 index 00000000..a500e44b --- /dev/null +++ b/src/static_resources.rs @@ -0,0 +1,19 @@ +use gio::{resources_register, Error, Resource}; +use glib::Bytes; + +pub fn init() -> Result<(), Error> { + // load the gresource binary at build time and include/link it into the final binary. + let res_bytes = include_bytes!("../res/resources.gresource"); + + // Create Resource it will live as long the value lives. + // TODO: change it into Bytes::From_static once the fix lands + // https://bugzilla.gnome.org/show_bug.cgi?id=790030 + let gbytes = Bytes::from(&res_bytes.as_ref()); + let resource = Resource::new_from_data(&gbytes)?; + // let resource = Resource::new_from_data(&res_bytes.as_ref().into())?; + + // Register the resource so It wont be dropped and will continue to live in memory. + resources_register(&resource); + + Ok(()) +}