mirror of
https://github.com/an-anime-team/sleepy-launcher.git
synced 2025-02-18 10:49:46 +03:00
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:
parent
f74d67a5e5
commit
ec30411ef8
8 changed files with 52 additions and 33 deletions
50
src/main.rs
50
src/main.rs
|
@ -1,9 +1,11 @@
|
||||||
use relm4::prelude::*;
|
use relm4::prelude::*;
|
||||||
|
|
||||||
use anime_launcher_sdk::config;
|
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::prelude::*;
|
||||||
use anime_launcher_sdk::anime_game_core::genshin::prelude::*;
|
use anime_launcher_sdk::anime_game_core::genshin::prelude::*;
|
||||||
use anime_launcher_sdk::consts::launcher_dir;
|
|
||||||
|
|
||||||
use tracing_subscriber::prelude::*;
|
use tracing_subscriber::prelude::*;
|
||||||
use tracing_subscriber::filter::*;
|
use tracing_subscriber::filter::*;
|
||||||
|
@ -14,6 +16,9 @@ pub mod i18n;
|
||||||
pub mod ui;
|
pub mod ui;
|
||||||
pub mod background;
|
pub mod background;
|
||||||
|
|
||||||
|
use ui::main::*;
|
||||||
|
use ui::first_run::main::*;
|
||||||
|
|
||||||
mod prettify_bytes;
|
mod prettify_bytes;
|
||||||
|
|
||||||
pub use prettify_bytes::prettify_bytes;
|
pub use prettify_bytes::prettify_bytes;
|
||||||
|
@ -77,6 +82,12 @@ fn main() {
|
||||||
// Force debug output
|
// Force debug output
|
||||||
let force_debug = std::env::args().any(|arg| &arg == "--debug");
|
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
|
// Prepare stdout logger
|
||||||
let stdout = tracing_subscriber::fmt::layer()
|
let stdout = tracing_subscriber::fmt::layer()
|
||||||
.pretty()
|
.pretty()
|
||||||
|
@ -122,9 +133,6 @@ fn main() {
|
||||||
gtk::glib::set_application_name("An Anime Game Launcher");
|
gtk::glib::set_application_name("An Anime Game Launcher");
|
||||||
gtk::glib::set_program_name(Some("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
|
// Set global css
|
||||||
relm4::set_global_css(&format!("
|
relm4::set_global_css(&format!("
|
||||||
progressbar > text {{
|
progressbar > text {{
|
||||||
|
@ -154,6 +162,9 @@ fn main() {
|
||||||
}}
|
}}
|
||||||
", BACKGROUND_FILE.to_string_lossy()));
|
", BACKGROUND_FILE.to_string_lossy()));
|
||||||
|
|
||||||
|
// Set game edition
|
||||||
|
genshin::set_game_edition(CONFIG.launcher.edition.into());
|
||||||
|
|
||||||
// Set UI language
|
// Set UI language
|
||||||
let lang = CONFIG.launcher.language.parse().expect("Wrong language format used in config");
|
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());
|
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
|
// Run FirstRun window if .first-run file persist
|
||||||
if FIRST_RUN_FILE.exists() {
|
if FIRST_RUN_FILE.exists() {
|
||||||
app.run::<ui::first_run::main::FirstRunApp>(());
|
app.run::<FirstRunApp>(());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run the app if everything's ready
|
// Run the app if everything's ready
|
||||||
else {
|
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>(());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -265,10 +265,7 @@ impl SimpleAsyncComponent for DefaultPathsApp {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
DefaultPathsAppMsg::Exit => {
|
DefaultPathsAppMsg::Exit => relm4::main_application().quit()
|
||||||
// TODO: relm4 has some function for it
|
|
||||||
std::process::exit(0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -193,10 +193,7 @@ impl SimpleAsyncComponent for DependenciesApp {
|
||||||
sender.output(Self::Output::ScrollToDefaultPaths);
|
sender.output(Self::Output::ScrollToDefaultPaths);
|
||||||
}
|
}
|
||||||
|
|
||||||
DependenciesAppMsg::Exit => {
|
DependenciesAppMsg::Exit => relm4::main_application().quit()
|
||||||
// TODO: relm4 has some function for it
|
|
||||||
std::process::exit(0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -512,10 +512,7 @@ impl SimpleAsyncComponent for DownloadComponentsApp {
|
||||||
sender.output(Self::Output::ScrollToFinish);
|
sender.output(Self::Output::ScrollToFinish);
|
||||||
}
|
}
|
||||||
|
|
||||||
DownloadComponentsAppMsg::Exit => {
|
DownloadComponentsAppMsg::Exit => relm4::main_application().quit()
|
||||||
// TODO: relm4 has some function for it
|
|
||||||
std::process::exit(0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,14 +85,10 @@ impl SimpleAsyncComponent for FinishApp {
|
||||||
FinishAppMsg::Restart => {
|
FinishAppMsg::Restart => {
|
||||||
std::process::Command::new(std::env::current_exe().unwrap()).spawn().unwrap();
|
std::process::Command::new(std::env::current_exe().unwrap()).spawn().unwrap();
|
||||||
|
|
||||||
// TODO: relm4 has some function for it
|
relm4::main_application().quit();
|
||||||
std::process::exit(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FinishAppMsg::Exit => {
|
FinishAppMsg::Exit => relm4::main_application().quit()
|
||||||
// TODO: relm4 has some function for it
|
|
||||||
std::process::exit(0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -146,10 +146,7 @@ impl SimpleAsyncComponent for SelectVoiceoversApp {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
SelectVoiceoversAppMsg::Exit => {
|
SelectVoiceoversAppMsg::Exit => relm4::main_application().quit()
|
||||||
// TODO: relm4 has some function for it
|
|
||||||
std::process::exit(0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,10 +93,7 @@ impl SimpleAsyncComponent for TosWarningApp {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TosWarningAppMsg::Exit => {
|
TosWarningAppMsg::Exit => relm4::main_application().quit()
|
||||||
// TODO: relm4 has some function for it
|
|
||||||
std::process::exit(0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -461,7 +461,7 @@ impl SimpleComponent for App {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn init(
|
fn init(
|
||||||
_counter: Self::Init,
|
_init: Self::Init,
|
||||||
root: &Self::Root,
|
root: &Self::Root,
|
||||||
sender: ComponentSender<Self>,
|
sender: ComponentSender<Self>,
|
||||||
) -> ComponentParts<Self> {
|
) -> ComponentParts<Self> {
|
||||||
|
|
Loading…
Add table
Reference in a new issue