feat: added app launch flags

Added `--run-game` and `--just-run-game` flags which can be used to run the game

1st will launch the game if launcher state is `Launch`.
Otherwise launcher window will appear

2nd will launch the game on `Launch` state,
as well as on `PredownloadAvailable` and `PatchAvailable(Patch::NotAvailable)`.

As well process stopping was changed by proper app exiting
by calling `relm4::main_application().quit()`
This commit is contained in:
Observer KRypt0n_ 2023-03-01 23:47:34 +02:00
parent f74d67a5e5
commit ec30411ef8
No known key found for this signature in database
GPG key ID: 844DA47BA25FE1E2
8 changed files with 52 additions and 33 deletions

View file

@ -1,9 +1,11 @@
use relm4::prelude::*;
use anime_launcher_sdk::config;
use anime_launcher_sdk::states::LauncherState;
use anime_launcher_sdk::consts::launcher_dir;
use anime_launcher_sdk::anime_game_core::prelude::*;
use anime_launcher_sdk::anime_game_core::genshin::prelude::*;
use anime_launcher_sdk::consts::launcher_dir;
use tracing_subscriber::prelude::*;
use tracing_subscriber::filter::*;
@ -14,6 +16,9 @@ pub mod i18n;
pub mod ui;
pub mod background;
use ui::main::*;
use ui::first_run::main::*;
mod prettify_bytes;
pub use prettify_bytes::prettify_bytes;
@ -77,6 +82,12 @@ fn main() {
// Force debug output
let force_debug = std::env::args().any(|arg| &arg == "--debug");
// Run the game
let run_game = std::env::args().any(|arg| &arg == "--run-game");
// Forcely run the game
let just_run_game = std::env::args().any(|arg| &arg == "--just-run-game");
// Prepare stdout logger
let stdout = tracing_subscriber::fmt::layer()
.pretty()
@ -122,9 +133,6 @@ fn main() {
gtk::glib::set_application_name("An Anime Game Launcher");
gtk::glib::set_program_name(Some("An Anime Game Launcher"));
// Create the app
let app = RelmApp::new(APP_ID);
// Set global css
relm4::set_global_css(&format!("
progressbar > text {{
@ -154,6 +162,9 @@ fn main() {
}}
", BACKGROUND_FILE.to_string_lossy()));
// Set game edition
genshin::set_game_edition(CONFIG.launcher.edition.into());
// Set UI language
let lang = CONFIG.launcher.language.parse().expect("Wrong language format used in config");
@ -161,13 +172,40 @@ fn main() {
tracing::info!("Set UI language to {}", i18n::get_lang());
// Create the app
let app = RelmApp::new(APP_ID);
// Run FirstRun window if .first-run file persist
if FIRST_RUN_FILE.exists() {
app.run::<ui::first_run::main::FirstRunApp>(());
app.run::<FirstRunApp>(());
}
// Run the app if everything's ready
else {
app.run::<ui::main::App>(());
if run_game || just_run_game {
let state = LauncherState::get_from_config(|_| {})
.expect("Failed to get launcher state");
match state {
LauncherState::Launch => {
anime_launcher_sdk::game::run().expect("Failed to run the game");
return;
}
LauncherState::PredownloadAvailable { .. } |
LauncherState::PatchAvailable(Patch::NotAvailable) => {
if just_run_game {
anime_launcher_sdk::game::run().expect("Failed to run the game");
return;
}
}
_ => ()
}
}
app.run::<App>(());
}
}

View file

@ -265,10 +265,7 @@ impl SimpleAsyncComponent for DefaultPathsApp {
};
}
DefaultPathsAppMsg::Exit => {
// TODO: relm4 has some function for it
std::process::exit(0);
}
DefaultPathsAppMsg::Exit => relm4::main_application().quit()
}
}
}

View file

@ -193,10 +193,7 @@ impl SimpleAsyncComponent for DependenciesApp {
sender.output(Self::Output::ScrollToDefaultPaths);
}
DependenciesAppMsg::Exit => {
// TODO: relm4 has some function for it
std::process::exit(0);
}
DependenciesAppMsg::Exit => relm4::main_application().quit()
}
}
}

View file

@ -512,10 +512,7 @@ impl SimpleAsyncComponent for DownloadComponentsApp {
sender.output(Self::Output::ScrollToFinish);
}
DownloadComponentsAppMsg::Exit => {
// TODO: relm4 has some function for it
std::process::exit(0);
}
DownloadComponentsAppMsg::Exit => relm4::main_application().quit()
}
}
}

View file

@ -85,14 +85,10 @@ impl SimpleAsyncComponent for FinishApp {
FinishAppMsg::Restart => {
std::process::Command::new(std::env::current_exe().unwrap()).spawn().unwrap();
// TODO: relm4 has some function for it
std::process::exit(0);
relm4::main_application().quit();
}
FinishAppMsg::Exit => {
// TODO: relm4 has some function for it
std::process::exit(0);
}
FinishAppMsg::Exit => relm4::main_application().quit()
}
}
}

View file

@ -146,10 +146,7 @@ impl SimpleAsyncComponent for SelectVoiceoversApp {
};
}
SelectVoiceoversAppMsg::Exit => {
// TODO: relm4 has some function for it
std::process::exit(0);
}
SelectVoiceoversAppMsg::Exit => relm4::main_application().quit()
}
}
}

View file

@ -93,10 +93,7 @@ impl SimpleAsyncComponent for TosWarningApp {
}
}
TosWarningAppMsg::Exit => {
// TODO: relm4 has some function for it
std::process::exit(0);
}
TosWarningAppMsg::Exit => relm4::main_application().quit()
}
}
}

View file

@ -461,7 +461,7 @@ impl SimpleComponent for App {
}
fn init(
_counter: Self::Init,
_init: Self::Init,
root: &Self::Root,
sender: ComponentSender<Self>,
) -> ComponentParts<Self> {