diff --git a/src/main.rs b/src/main.rs index d9443c5..93dc33f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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::(()); + app.run::(()); } // Run the app if everything's ready else { - app.run::(()); + 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::(()); } } diff --git a/src/ui/first_run/default_paths.rs b/src/ui/first_run/default_paths.rs index 1cefbda..0c69c09 100644 --- a/src/ui/first_run/default_paths.rs +++ b/src/ui/first_run/default_paths.rs @@ -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() } } } diff --git a/src/ui/first_run/dependencies.rs b/src/ui/first_run/dependencies.rs index b848cf6..25283cc 100644 --- a/src/ui/first_run/dependencies.rs +++ b/src/ui/first_run/dependencies.rs @@ -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() } } } diff --git a/src/ui/first_run/download_components.rs b/src/ui/first_run/download_components.rs index 9fad015..cac088d 100644 --- a/src/ui/first_run/download_components.rs +++ b/src/ui/first_run/download_components.rs @@ -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() } } } diff --git a/src/ui/first_run/finish.rs b/src/ui/first_run/finish.rs index b656688..96662e4 100644 --- a/src/ui/first_run/finish.rs +++ b/src/ui/first_run/finish.rs @@ -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() } } } diff --git a/src/ui/first_run/select_voiceovers.rs b/src/ui/first_run/select_voiceovers.rs index e6d26b6..eb43715 100644 --- a/src/ui/first_run/select_voiceovers.rs +++ b/src/ui/first_run/select_voiceovers.rs @@ -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() } } } diff --git a/src/ui/first_run/tos_warning.rs b/src/ui/first_run/tos_warning.rs index 9143792..08ae5b1 100644 --- a/src/ui/first_run/tos_warning.rs +++ b/src/ui/first_run/tos_warning.rs @@ -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() } } } diff --git a/src/ui/main.rs b/src/ui/main.rs index fcda775..d959a6d 100644 --- a/src/ui/main.rs +++ b/src/ui/main.rs @@ -461,7 +461,7 @@ impl SimpleComponent for App { } fn init( - _counter: Self::Init, + _init: Self::Init, root: &Self::Root, sender: ComponentSender, ) -> ComponentParts {