2022-06-28 21:59:20 +00:00
|
|
|
use gtk4::{self as gtk, prelude::*};
|
2022-07-28 12:07:16 +00:00
|
|
|
use libadwaita as adw;
|
2022-06-28 21:59:20 +00:00
|
|
|
|
2022-07-26 15:34:46 +00:00
|
|
|
use gtk::{CssProvider, StyleContext, STYLE_PROVIDER_PRIORITY_APPLICATION};
|
|
|
|
use gtk::gdk::Display;
|
2022-07-09 15:57:42 +00:00
|
|
|
|
2022-07-27 15:37:52 +00:00
|
|
|
use std::path::Path;
|
|
|
|
use std::fs;
|
|
|
|
|
2022-06-29 07:11:19 +00:00
|
|
|
pub mod ui;
|
2022-06-30 19:40:25 +00:00
|
|
|
pub mod lib;
|
2022-06-28 21:59:20 +00:00
|
|
|
|
2022-07-02 10:18:44 +00:00
|
|
|
use ui::*;
|
2022-06-28 21:59:20 +00:00
|
|
|
|
2022-07-26 08:57:12 +00:00
|
|
|
pub const APP_ID: &str = "com.gitlab.an-anime-team.an-anime-game-launcher-gtk";
|
|
|
|
pub const APP_VERSION: &str = env!("CARGO_PKG_VERSION");
|
2022-07-26 15:34:46 +00:00
|
|
|
pub const APP_DEBUG: bool = cfg!(debug_assertions);
|
2022-07-26 08:57:12 +00:00
|
|
|
|
2022-07-14 12:53:51 +00:00
|
|
|
#[tokio::main]
|
|
|
|
async fn main() {
|
2022-06-28 21:59:20 +00:00
|
|
|
gtk::init().expect("GTK initialization failed");
|
|
|
|
adw::init();
|
|
|
|
|
2022-07-24 12:02:14 +00:00
|
|
|
// Register and include resources
|
|
|
|
gtk::gio::resources_register_include!(".assets.gresource")
|
|
|
|
.expect("Failed to register resources");
|
|
|
|
|
2022-07-26 15:34:46 +00:00
|
|
|
// Set application's title
|
2022-07-28 15:00:39 +00:00
|
|
|
gtk::glib::set_prgname(Some("An Anime Game Launcher"));
|
2022-07-26 15:34:46 +00:00
|
|
|
|
2022-06-28 21:59:20 +00:00
|
|
|
// Create app
|
|
|
|
let application = gtk::Application::new(
|
2022-07-26 08:57:12 +00:00
|
|
|
Some(APP_ID),
|
2022-06-28 21:59:20 +00:00
|
|
|
Default::default()
|
|
|
|
);
|
|
|
|
|
|
|
|
// Init app window and show it
|
|
|
|
application.connect_activate(|app| {
|
2022-07-09 15:57:42 +00:00
|
|
|
// Apply CSS styles to the application
|
|
|
|
let provider = CssProvider::new();
|
|
|
|
|
2022-07-10 09:55:49 +00:00
|
|
|
provider.load_from_data(include_bytes!("../assets/styles.css"));
|
2022-07-09 15:57:42 +00:00
|
|
|
|
|
|
|
StyleContext::add_provider_for_display(
|
|
|
|
&Display::default().expect("Could not connect to a display"),
|
|
|
|
&provider,
|
|
|
|
STYLE_PROVIDER_PRIORITY_APPLICATION
|
|
|
|
);
|
|
|
|
|
2022-07-27 15:37:52 +00:00
|
|
|
// Create default launcher folder if needed
|
|
|
|
let launcher_dir = lib::consts::launcher_dir().unwrap();
|
|
|
|
|
|
|
|
if !Path::new(&launcher_dir).exists() || Path::new(&format!("{}/.first-run", launcher_dir)).exists() {
|
|
|
|
fs::create_dir_all(&launcher_dir).expect("Failed to create default launcher dir");
|
|
|
|
fs::write(format!("{}/.first-run", launcher_dir), "").expect("Failed to create .first-run file");
|
|
|
|
|
|
|
|
let first_run = FirstRunApp::new(app).expect("Failed to init FirstRunApp");
|
|
|
|
|
|
|
|
first_run.show();
|
|
|
|
}
|
|
|
|
|
2022-07-09 15:57:42 +00:00
|
|
|
// Load main window and show it
|
2022-07-27 15:37:52 +00:00
|
|
|
else {
|
|
|
|
let main = MainApp::new(app).expect("Failed to init MainApp");
|
2022-06-28 21:59:20 +00:00
|
|
|
|
2022-07-27 15:37:52 +00:00
|
|
|
main.show();
|
|
|
|
}
|
2022-06-28 21:59:20 +00:00
|
|
|
});
|
|
|
|
|
2022-07-24 13:01:59 +00:00
|
|
|
// Flush config from the memory to the file before closing the app
|
|
|
|
application.connect_shutdown(|_| {
|
2022-07-24 20:04:35 +00:00
|
|
|
lib::config::flush().expect("Failed to save config file");
|
2022-07-24 13:01:59 +00:00
|
|
|
});
|
|
|
|
|
2022-06-28 21:59:20 +00:00
|
|
|
// Run app
|
|
|
|
application.run();
|
|
|
|
}
|