the-honkers-railway-launcher/src/main.rs

53 lines
1.4 KiB
Rust
Raw Normal View History

2022-06-28 21:59:20 +00:00
use gtk4::{self as gtk, prelude::*};
use libadwaita::{self as adw, prelude::*};
2022-06-28 21:59:20 +00:00
use gtk::{CssProvider, StyleContext, gdk::Display, STYLE_PROVIDER_PRIORITY_APPLICATION};
pub mod ui;
pub mod lib;
2022-06-28 21:59:20 +00:00
use ui::*;
2022-06-28 21:59:20 +00:00
#[tokio::main]
async fn main() {
2022-06-28 21:59:20 +00:00
gtk::init().expect("GTK initialization failed");
adw::init();
// Register and include resources
gtk::gio::resources_register_include!(".assets.gresource")
.expect("Failed to register resources");
2022-06-28 21:59:20 +00:00
// Create app
let application = gtk::Application::new(
Some("com.gitlab.an-anime-team.an-anime-game-launcher-gtk"),
2022-06-28 21:59:20 +00:00
Default::default()
);
// Init app window and show it
application.connect_activate(|app| {
// Apply CSS styles to the application
let provider = CssProvider::new();
provider.load_from_data(include_bytes!("../assets/styles.css"));
StyleContext::add_provider_for_display(
&Display::default().expect("Could not connect to a display"),
&provider,
STYLE_PROVIDER_PRIORITY_APPLICATION
);
// Load main window and show it
let main = MainApp::new(app).expect("Failed to init MainApp");
2022-06-28 21:59:20 +00:00
main.show();
2022-06-28 21:59:20 +00:00
});
// Flush config from the memory to the file before closing the app
application.connect_shutdown(|_| {
lib::config::flush().expect("Failed to save config data");
});
2022-06-28 21:59:20 +00:00
// Run app
application.run();
}