From 72ad266403c7699bf3aa573f7833c94258c0b7fb Mon Sep 17 00:00:00 2001 From: Jordan Petridis Date: Fri, 10 Nov 2017 19:28:24 +0200 Subject: [PATCH] Initial implementation for Gresource support. --- Cargo.toml | 1 + build.rs | 9 ++++++++- res/resources.gresource | Bin 0 -> 44264 bytes res/resources.xml | 8 ++++++++ src/app.rs | 15 +++++++++------ src/build.rs | 0 src/main.rs | 6 ++++++ src/static_resources.rs | 19 +++++++++++++++++++ 8 files changed, 51 insertions(+), 7 deletions(-) create mode 100644 res/resources.gresource create mode 100644 res/resources.xml create mode 100644 src/build.rs create mode 100644 src/static_resources.rs 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 0000000000000000000000000000000000000000..75c3cec678bd6b15ede18c292e392162974b8f0a GIT binary patch literal 44264 zcmeHQxs&7Ad2ijWQDSEbA+AfBEj2-0yn4EOwVKhaWsg={+q0`GB`h?ECb0to6ae-y zE(b1$PJ9JUT;+e}NPG_q_*z4-dpaHoJSeJiWyo^5Grd`|j_1 z2R`}IjyyX^4${Bx;osl#?@zyz72@Bor}E|pXLZyvll_#OWJZ+!mZ zf4=|eH`4EaaBz8W@U?@3zy8~UgMa^*uOIv`{^EogU{7J{KxN8KlJ^(=;z`b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Hgn zIzVWsk4@FkwXua3h$0aX=!ERCp~49-4uPK$#bs1Wl@S_H!{z$B8QmhCX zqs+wE6u29thZ##58er4_AB~MLOdIOJB#o%S@BlVzq-q+Fhq5tfr~^u&3^T;6^)Ya? zE){WPfIAWUpr_5Hh6&m*-oyBLUE-`kpUq=1By7S`5avK|@R%_qol1EFZ~$gRGKtnh zKx+2Ks0of3YS6}tG3tZfW6*ewB?H_9vO{*)WzPYfrH+tC5(;5?FyTHURfafIN7t5S z5c{qXXTpyd=*V`g@dg^E^IGFgC=>9uE;ThHr71)XYKd4D(h1%fYZeKoP>2qO2!kSYiiv*;O(7+f#ze0f#1qZ6B4F(qR+5li{hz^8ObO + + + 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(()) +}