diff --git a/fitnesstrax/app/build.rs b/fitnesstrax/app/build.rs new file mode 100644 index 0000000..6943702 --- /dev/null +++ b/fitnesstrax/app/build.rs @@ -0,0 +1,7 @@ +fn main() { + glib_build_tools::compile_resources( + &["resources"], + "resources/gresources.xml", + "com.luminescent-dreams.fitnesstrax.gresource", + ); +} diff --git a/fitnesstrax/app/resources/com.luminescent-dreams.fitnesstrax.dev.gschema.xml b/fitnesstrax/app/resources/com.luminescent-dreams.fitnesstrax.dev.gschema.xml index 53d1d41..af4fb36 100644 --- a/fitnesstrax/app/resources/com.luminescent-dreams.fitnesstrax.dev.gschema.xml +++ b/fitnesstrax/app/resources/com.luminescent-dreams.fitnesstrax.dev.gschema.xml @@ -1,5 +1,11 @@ + + + "" + Path to the series + + "" diff --git a/fitnesstrax/app/resources/gresources.xml b/fitnesstrax/app/resources/gresources.xml new file mode 100644 index 0000000..a597670 --- /dev/null +++ b/fitnesstrax/app/resources/gresources.xml @@ -0,0 +1,6 @@ + + + + style.css + + diff --git a/fitnesstrax/app/resources/style.css b/fitnesstrax/app/resources/style.css new file mode 100644 index 0000000..e69de29 diff --git a/fitnesstrax/app/src/main.rs b/fitnesstrax/app/src/main.rs index fdfe8f2..570c7c9 100644 --- a/fitnesstrax/app/src/main.rs +++ b/fitnesstrax/app/src/main.rs @@ -1,11 +1,11 @@ -use gtk::prelude::*; +use gio::resources_lookup_data; +use gtk::{prelude::*, STYLE_PROVIDER_PRIORITY_USER}; use std::env; const APP_ID_DEV: &str = "com.luminescent-dreams.fitnesstrax.dev"; const APP_ID_PROD: &str = "com.luminescent-dreams.fitnesstrax"; -const RESOURCE_BASE_PATH_DEV: &str = "/com/luminescent-dreams/fitnesstrax/dev/"; -const RESOURCE_BASE_PATH_PROD: &str = "/com/luminescent-dreams/fitnesstrax/"; +const RESOURCE_BASE_PATH: &str = "/com/luminescent-dreams/fitnesstrax/"; struct AppState {} @@ -14,10 +14,17 @@ struct AppWindow { } fn main() { - let (app_id, base_path) = if std::env::var_os("ENV") == Some("dev".into()) { - (APP_ID_DEV, RESOURCE_BASE_PATH_DEV) + // I still don't fully understand gio resources. resources_register_include! is convenient + // because I don't have to deal with filesystem locations at runtime. However, I think other + // GTK applications do that rather than compiling the resources directly into the app. So, I'm + // unclear as to how I want to handle this. + gio::resources_register_include!("com.luminescent-dreams.fitnesstrax.gresource") + .expect("to register resources"); + + let app_id = if std::env::var_os("ENV") == Some("dev".into()) { + APP_ID_DEV } else { - (APP_ID_PROD, RESOURCE_BASE_PATH_PROD) + APP_ID_PROD }; let settings = gio::Settings::new(app_id); @@ -26,7 +33,7 @@ fn main() { let app = adw::Application::builder() .application_id(app_id) - .resource_base_path(base_path) + .resource_base_path(RESOURCE_BASE_PATH) .build(); /* @@ -37,12 +44,28 @@ fn main() { */ let app = adw::Application::builder() - .application_id("com.luminescent-dreams.fitnesstrax") - .resource_base_path("/com/luminescent-dreams/fitnesstrax") + .application_id(app_id) + .resource_base_path(RESOURCE_BASE_PATH) .build(); app.connect_activate(move |app| { + let stylesheet = String::from_utf8( + resources_lookup_data( + &format!("{}style.css", RESOURCE_BASE_PATH), + gio::ResourceLookupFlags::NONE, + ) + .expect("stylesheet must be available in the resources") + .to_vec(), + ) + .expect("to parse stylesheet"); + + let provider = gtk::CssProvider::new(); + provider.load_from_data(&stylesheet); + let window = adw::ApplicationWindow::new(app); + let context = window.style_context(); + context.add_provider(&provider, STYLE_PROVIDER_PRIORITY_USER); + window.present(); });