feat: improved app args parsing

This commit is contained in:
Observer KRypt0n_ 2024-03-24 11:23:15 +02:00
parent f86c86e1fd
commit 919de100c1
No known key found for this signature in database
GPG key ID: 844DA47BA25FE1E2

View file

@ -135,22 +135,24 @@ fn main() -> anyhow::Result<()> {
let mut no_verbose_tracing = false; let mut no_verbose_tracing = false;
let args = std::env::args().collect::<Vec<_>>(); let args = std::env::args().collect::<Vec<_>>();
let mut gtk_args = Vec::new();
// Parse arguments // Parse arguments
for i in 0..args.len() { for i in 0..args.len() {
if args[i] == "--debug" { match args[i].as_str() {
force_debug = true; "--debug" => force_debug = true,
} else if args[i] == "--run-game" { "--run-game" => run_game = true,
run_game = true; "--just-run-game" => just_run_game = true,
} else if args[i] == "--just-run-game" { "--no-verbose-tracing" => no_verbose_tracing = true,
just_run_game = true;
} else if args[i] == "--no-verbose-tracing" { "--session" => {
no_verbose_tracing = true; // Switch active session prior running the app
} else if args[i] == "--session" { if let Some(session) = args.get(i + 1) {
// Switch active session prior running the app Sessions::set_current(session.to_owned())?;
if let Some(session) = args.get(i + 1) { }
Sessions::set_current(session.to_owned())?; },
}
arg => gtk_args.push(arg.to_string())
} }
} }
@ -210,7 +212,8 @@ fn main() -> anyhow::Result<()> {
// 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() {
// Create the app // Create the app
let app = RelmApp::new(APP_ID); let app = RelmApp::new(APP_ID)
.with_args(gtk_args);
// Set global css // Set global css
app.set_global_css(&GLOBAL_CSS); app.set_global_css(&GLOBAL_CSS);
@ -243,7 +246,8 @@ fn main() -> anyhow::Result<()> {
} }
// Create the app // Create the app
let app = RelmApp::new(APP_ID); let app = RelmApp::new(APP_ID)
.with_args(gtk_args);
// Set global css // Set global css
app.set_global_css(&GLOBAL_CSS); app.set_global_css(&GLOBAL_CSS);