2023-12-18 16:59:56 +00:00
|
|
|
use gio::resources_lookup_data;
|
|
|
|
use gtk::{prelude::*, STYLE_PROVIDER_PRIORITY_USER};
|
2023-11-20 03:47:36 +00:00
|
|
|
use std::env;
|
|
|
|
|
2023-12-07 14:45:56 +00:00
|
|
|
const APP_ID_DEV: &str = "com.luminescent-dreams.fitnesstrax.dev";
|
2023-12-07 14:56:10 +00:00
|
|
|
const APP_ID_PROD: &str = "com.luminescent-dreams.fitnesstrax";
|
2023-12-07 14:45:56 +00:00
|
|
|
|
2023-12-18 16:59:56 +00:00
|
|
|
const RESOURCE_BASE_PATH: &str = "/com/luminescent-dreams/fitnesstrax/";
|
2023-12-07 14:45:56 +00:00
|
|
|
|
2023-11-20 03:47:36 +00:00
|
|
|
struct AppState {}
|
|
|
|
|
|
|
|
struct AppWindow {
|
|
|
|
window: adw::ApplicationWindow,
|
|
|
|
}
|
|
|
|
|
2023-11-13 13:52:10 +00:00
|
|
|
fn main() {
|
2023-12-18 16:59:56 +00:00
|
|
|
// 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
|
2023-12-07 14:56:10 +00:00
|
|
|
} else {
|
2023-12-18 16:59:56 +00:00
|
|
|
APP_ID_PROD
|
2023-12-07 14:56:10 +00:00
|
|
|
};
|
2023-12-07 14:45:56 +00:00
|
|
|
|
|
|
|
let settings = gio::Settings::new(app_id);
|
|
|
|
|
|
|
|
println!("database path: {}", settings.string("series-path"));
|
|
|
|
|
2023-11-20 03:47:36 +00:00
|
|
|
let app = adw::Application::builder()
|
2023-12-07 14:45:56 +00:00
|
|
|
.application_id(app_id)
|
2023-12-18 16:59:56 +00:00
|
|
|
.resource_base_path(RESOURCE_BASE_PATH)
|
2023-11-20 03:47:36 +00:00
|
|
|
.build();
|
|
|
|
|
|
|
|
/*
|
|
|
|
let runtime = tokio::runtime::Builder::new_multi_thread()
|
|
|
|
.enable_all()
|
|
|
|
.build()
|
|
|
|
.unwrap();
|
|
|
|
*/
|
|
|
|
|
|
|
|
let app = adw::Application::builder()
|
2023-12-18 16:59:56 +00:00
|
|
|
.application_id(app_id)
|
|
|
|
.resource_base_path(RESOURCE_BASE_PATH)
|
2023-11-20 03:47:36 +00:00
|
|
|
.build();
|
|
|
|
|
|
|
|
app.connect_activate(move |app| {
|
2023-12-18 16:59:56 +00:00
|
|
|
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);
|
|
|
|
|
2023-11-20 03:47:36 +00:00
|
|
|
let window = adw::ApplicationWindow::new(app);
|
2023-12-18 16:59:56 +00:00
|
|
|
let context = window.style_context();
|
|
|
|
context.add_provider(&provider, STYLE_PROVIDER_PRIORITY_USER);
|
|
|
|
|
2023-11-20 03:47:36 +00:00
|
|
|
window.present();
|
|
|
|
});
|
|
|
|
|
|
|
|
let args: Vec<String> = env::args().collect();
|
|
|
|
ApplicationExtManual::run_with_args(&app, &args);
|
2023-11-13 13:52:10 +00:00
|
|
|
}
|