2023-12-18 23:36:22 +00:00
|
|
|
/*
|
2024-02-19 23:41:38 +00:00
|
|
|
Copyright 2023 - 2024, Savanni D'Gerinel <savanni@luminescent-dreams.com>
|
2023-12-18 23:36:22 +00:00
|
|
|
|
|
|
|
This file is part of FitnessTrax.
|
|
|
|
|
|
|
|
FitnessTrax is free software: you can redistribute it and/or modify it under the terms of the GNU
|
|
|
|
General Public License as published by the Free Software Foundation, either version 3 of the
|
|
|
|
License, or (at your option) any later version.
|
|
|
|
|
|
|
|
FitnessTrax is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
|
|
|
|
even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License along with FitnessTrax. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2023-12-19 02:14:08 +00:00
|
|
|
|
2024-02-19 23:41:38 +00:00
|
|
|
mod about;
|
2023-12-22 20:08:34 +00:00
|
|
|
mod app;
|
2023-12-22 19:54:38 +00:00
|
|
|
mod app_window;
|
|
|
|
mod components;
|
2024-01-30 13:46:10 +00:00
|
|
|
#[cfg(test)]
|
|
|
|
mod gtk_init;
|
2023-12-28 15:28:51 +00:00
|
|
|
mod types;
|
2024-01-20 16:16:31 +00:00
|
|
|
mod view_models;
|
2023-12-22 19:54:38 +00:00
|
|
|
mod views;
|
2023-12-19 02:14:08 +00:00
|
|
|
|
2023-12-18 23:30:41 +00:00
|
|
|
use adw::prelude::*;
|
2023-12-22 19:54:38 +00:00
|
|
|
use app_window::AppWindow;
|
2024-02-19 21:14:08 +00:00
|
|
|
use gio::ActionEntry;
|
2023-12-22 20:08:34 +00:00
|
|
|
use std::{env, path::PathBuf};
|
2023-11-20 03:47:36 +00:00
|
|
|
|
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
|
|
|
|
2024-02-19 23:41:38 +00:00
|
|
|
fn setup_app_about_action(app: &adw::Application) {
|
|
|
|
let action = ActionEntry::builder("about")
|
2024-02-19 23:47:48 +00:00
|
|
|
.activate(|_app: &adw::Application, _, _| {
|
2024-02-19 23:41:38 +00:00
|
|
|
let window = about::AboutWindow::default();
|
|
|
|
window.present();
|
|
|
|
}).build();
|
|
|
|
app.add_action_entries([action]);
|
|
|
|
}
|
|
|
|
|
2024-02-19 17:05:21 +00:00
|
|
|
/// Sets up an application-global action, `app.quit`, which will terminate the application.
|
|
|
|
fn setup_app_close_action(app: &adw::Application) {
|
|
|
|
let action = ActionEntry::builder("quit")
|
|
|
|
.activate(|app: &adw::Application, _, _| {
|
|
|
|
// right now, stopping the application is dirt simple. But we could use this
|
|
|
|
// block to add extra code that does additional shutdown steps if we ever want
|
|
|
|
// some states that shouldn't be discarded.
|
|
|
|
app.quit();
|
|
|
|
})
|
|
|
|
.build();
|
|
|
|
app.add_action_entries([action]);
|
|
|
|
app.set_accels_for_action("app.quit", &["<Ctrl>Q"]);
|
|
|
|
}
|
|
|
|
|
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);
|
2023-12-29 00:09:12 +00:00
|
|
|
let ft_app = app::App::new({
|
2023-12-22 19:08:16 +00:00
|
|
|
let path = settings.string("series-path");
|
|
|
|
if path.is_empty() {
|
|
|
|
None
|
|
|
|
} else {
|
|
|
|
Some(PathBuf::from(path))
|
|
|
|
}
|
|
|
|
});
|
2023-11-20 03:47:36 +00:00
|
|
|
|
2023-12-18 23:30:41 +00:00
|
|
|
let adw_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();
|
|
|
|
|
2023-12-18 23:30:41 +00:00
|
|
|
adw_app.connect_activate(move |adw_app| {
|
2024-01-25 14:03:55 +00:00
|
|
|
let icon_theme = gtk::IconTheme::for_display(&gdk::Display::default().unwrap());
|
|
|
|
icon_theme.add_resource_path(&(RESOURCE_BASE_PATH.to_owned() + "/icons/scalable/actions"));
|
|
|
|
|
2024-02-19 23:41:38 +00:00
|
|
|
setup_app_about_action(adw_app);
|
2024-02-19 21:14:08 +00:00
|
|
|
setup_app_close_action(adw_app);
|
2024-02-19 16:58:01 +00:00
|
|
|
|
2023-12-29 00:09:12 +00:00
|
|
|
AppWindow::new(app_id, RESOURCE_BASE_PATH, adw_app, ft_app.clone());
|
2023-11-20 03:47:36 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
let args: Vec<String> = env::args().collect();
|
2023-12-18 23:30:41 +00:00
|
|
|
ApplicationExtManual::run_with_args(&adw_app, &args);
|
2023-11-13 13:52:10 +00:00
|
|
|
}
|