Added icon loading from "icon" file, added --run-game argument

This commit is contained in:
Observer KRypt0n_ 2022-08-08 21:31:46 +02:00
parent 6e2ca304ff
commit 13de707baa
No known key found for this signature in database
GPG key ID: 844DA47BA25FE1E2
4 changed files with 56 additions and 13 deletions

View file

@ -40,7 +40,7 @@ Adw.ApplicationWindow window {
visible: false;
Adw.PreferencesGroup {
Gtk.Image {
Gtk.Image icon {
resource: "/org/app/assets/images/icon.png";
vexpand: true;

View file

@ -3,6 +3,8 @@ use libadwaita as adw;
use gtk::{CssProvider, StyleContext, STYLE_PROVIDER_PRIORITY_APPLICATION};
use gtk::gdk::Display;
use gtk::glib;
use gtk::glib::clone;
use std::path::Path;
use std::fs;
@ -25,8 +27,8 @@ fn main() {
.expect("Failed to register resources");
// Set application's title
gtk::glib::set_application_name("An Anime Game Launcher");
gtk::glib::set_program_name(Some("An Anime Game Launcher"));
glib::set_application_name("An Anime Game Launcher");
glib::set_program_name(Some("An Anime Game Launcher"));
// Create app
let application = gtk::Application::new(
@ -34,8 +36,27 @@ fn main() {
Default::default()
);
application.add_main_option(
"run-game",
glib::Char::from(0),
glib::OptionFlags::empty(),
glib::OptionArg::None,
"Run the game",
None
);
let run_game = std::rc::Rc::new(std::cell::Cell::new(false));
application.connect_handle_local_options(clone!(@strong run_game => move |_, arg| {
if arg.contains("run-game") {
run_game.set(true);
}
-1
}));
// Init app window and show it
application.connect_activate(|app| {
application.connect_activate(move |app| {
// Apply CSS styles to the application
let provider = CssProvider::new();
@ -65,11 +86,29 @@ fn main() {
anime_game_core::consts::set_game_edition(config.launcher.edition.into());
// Load and show main window
// Load main window
let main = MainApp::new(app).expect("Failed to init MainApp");
// Load initial launcher state
let awaiter = main.update_state();
if !run_game.get() {
main.show();
}
else {
awaiter.then(move |state| {
match state.as_ref().expect("Failed to load launcher state") {
lib::launcher::states::LauncherState::Launch => {
main.update(ui::main::Actions::PerformButtonEvent).unwrap();
std::process::exit(0);
},
_ => main.show()
}
});
}
}
});
// Flush config from the memory to the file before closing the app

View file

@ -45,6 +45,7 @@ pub struct AppWidgets {
pub status_page: adw::StatusPage,
pub launcher_content: adw::PreferencesPage,
pub icon: gtk::Image,
pub launch_game: gtk::Button,
pub open_preferences: gtk::Button,
@ -71,6 +72,7 @@ impl AppWidgets {
status_page: get_object(&builder, "status_page")?,
launcher_content: get_object(&builder, "launcher_content")?,
icon: get_object(&builder, "icon")?,
launch_game: get_object(&builder, "launch_game")?,
open_preferences: get_object(&builder, "open_preferences")?,
@ -88,6 +90,11 @@ impl AppWidgets {
result.window.add_css_class("devel");
}
// Load icon from "icon" file if it exists
if std::path::Path::new("icon").exists() {
result.icon.set_from_file(Some("icon"));
}
// Set default About Dialog values
if crate::APP_DEBUG {
result.about.set_version(Some(format!("{} (development)", crate::APP_VERSION).as_str()));
@ -198,9 +205,6 @@ impl App {
// Bind app to the window
result.widgets.window.set_application(Some(app));
// Load initial launcher state
result.update_state();
Ok(result)
}

View file

@ -1,10 +1,10 @@
use gtk4::{self as gtk, prelude::*};
use libadwaita as adw;
mod first_run;
mod main;
mod preferences;
mod traits;
pub mod first_run;
pub mod main;
pub mod preferences;
pub mod traits;
pub mod components;