mirror of
https://github.com/an-anime-team/sleepy-launcher.git
synced 2025-04-02 23:13:28 +03:00
Added icon loading from "icon" file, added --run-game
argument
This commit is contained in:
parent
6e2ca304ff
commit
13de707baa
4 changed files with 56 additions and 13 deletions
|
@ -40,7 +40,7 @@ Adw.ApplicationWindow window {
|
||||||
visible: false;
|
visible: false;
|
||||||
|
|
||||||
Adw.PreferencesGroup {
|
Adw.PreferencesGroup {
|
||||||
Gtk.Image {
|
Gtk.Image icon {
|
||||||
resource: "/org/app/assets/images/icon.png";
|
resource: "/org/app/assets/images/icon.png";
|
||||||
|
|
||||||
vexpand: true;
|
vexpand: true;
|
||||||
|
|
49
src/main.rs
49
src/main.rs
|
@ -3,6 +3,8 @@ use libadwaita as adw;
|
||||||
|
|
||||||
use gtk::{CssProvider, StyleContext, STYLE_PROVIDER_PRIORITY_APPLICATION};
|
use gtk::{CssProvider, StyleContext, STYLE_PROVIDER_PRIORITY_APPLICATION};
|
||||||
use gtk::gdk::Display;
|
use gtk::gdk::Display;
|
||||||
|
use gtk::glib;
|
||||||
|
use gtk::glib::clone;
|
||||||
|
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
@ -25,8 +27,8 @@ fn main() {
|
||||||
.expect("Failed to register resources");
|
.expect("Failed to register resources");
|
||||||
|
|
||||||
// Set application's title
|
// Set application's title
|
||||||
gtk::glib::set_application_name("An Anime Game Launcher");
|
glib::set_application_name("An Anime Game Launcher");
|
||||||
gtk::glib::set_program_name(Some("An Anime Game Launcher"));
|
glib::set_program_name(Some("An Anime Game Launcher"));
|
||||||
|
|
||||||
// Create app
|
// Create app
|
||||||
let application = gtk::Application::new(
|
let application = gtk::Application::new(
|
||||||
|
@ -34,8 +36,27 @@ fn main() {
|
||||||
Default::default()
|
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
|
// Init app window and show it
|
||||||
application.connect_activate(|app| {
|
application.connect_activate(move |app| {
|
||||||
// Apply CSS styles to the application
|
// Apply CSS styles to the application
|
||||||
let provider = CssProvider::new();
|
let provider = CssProvider::new();
|
||||||
|
|
||||||
|
@ -65,10 +86,28 @@ fn main() {
|
||||||
|
|
||||||
anime_game_core::consts::set_game_edition(config.launcher.edition.into());
|
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");
|
let main = MainApp::new(app).expect("Failed to init MainApp");
|
||||||
|
|
||||||
main.show();
|
// 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()
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -45,6 +45,7 @@ pub struct AppWidgets {
|
||||||
pub status_page: adw::StatusPage,
|
pub status_page: adw::StatusPage,
|
||||||
pub launcher_content: adw::PreferencesPage,
|
pub launcher_content: adw::PreferencesPage,
|
||||||
|
|
||||||
|
pub icon: gtk::Image,
|
||||||
pub launch_game: gtk::Button,
|
pub launch_game: gtk::Button,
|
||||||
pub open_preferences: gtk::Button,
|
pub open_preferences: gtk::Button,
|
||||||
|
|
||||||
|
@ -71,6 +72,7 @@ impl AppWidgets {
|
||||||
status_page: get_object(&builder, "status_page")?,
|
status_page: get_object(&builder, "status_page")?,
|
||||||
launcher_content: get_object(&builder, "launcher_content")?,
|
launcher_content: get_object(&builder, "launcher_content")?,
|
||||||
|
|
||||||
|
icon: get_object(&builder, "icon")?,
|
||||||
launch_game: get_object(&builder, "launch_game")?,
|
launch_game: get_object(&builder, "launch_game")?,
|
||||||
open_preferences: get_object(&builder, "open_preferences")?,
|
open_preferences: get_object(&builder, "open_preferences")?,
|
||||||
|
|
||||||
|
@ -87,6 +89,11 @@ impl AppWidgets {
|
||||||
if crate::APP_DEBUG {
|
if crate::APP_DEBUG {
|
||||||
result.window.add_css_class("devel");
|
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
|
// Set default About Dialog values
|
||||||
if crate::APP_DEBUG {
|
if crate::APP_DEBUG {
|
||||||
|
@ -198,9 +205,6 @@ impl App {
|
||||||
// Bind app to the window
|
// Bind app to the window
|
||||||
result.widgets.window.set_application(Some(app));
|
result.widgets.window.set_application(Some(app));
|
||||||
|
|
||||||
// Load initial launcher state
|
|
||||||
result.update_state();
|
|
||||||
|
|
||||||
Ok(result)
|
Ok(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
use gtk4::{self as gtk, prelude::*};
|
use gtk4::{self as gtk, prelude::*};
|
||||||
use libadwaita as adw;
|
use libadwaita as adw;
|
||||||
|
|
||||||
mod first_run;
|
pub mod first_run;
|
||||||
mod main;
|
pub mod main;
|
||||||
mod preferences;
|
pub mod preferences;
|
||||||
mod traits;
|
pub mod traits;
|
||||||
|
|
||||||
pub mod components;
|
pub mod components;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue