diff --git a/crates/yabg3nml/src/autostart.rs b/crates/yabg3nml/src/autostart.rs index 6e4788b..c236b54 100644 --- a/crates/yabg3nml/src/autostart.rs +++ b/crates/yabg3nml/src/autostart.rs @@ -1,8 +1,12 @@ use std::{ - collections::VecDeque, env, os::windows::process::CommandExt as _, path::Path, process::Command, + collections::VecDeque, + env, + os::windows::process::{CommandExt as _, ExitCodeExt as _}, + path::Path, + process::{Command, ExitCode}, }; -use eyre::Result; +use eyre::{eyre, Result}; use shared::popup::fatal_popup; use tracing::{error, trace}; @@ -19,7 +23,7 @@ use crate::{ single_instance::SingleInstance, }; -pub fn autostart() -> Result<()> { +pub fn autostart() -> Result { // This prohibits multiple app instances let _singleton = SingleInstance::new(); let _event = Event::new()?; @@ -63,7 +67,7 @@ pub fn autostart() -> Result<()> { .envs(env::vars()) .spawn(); - let child = match cmd { + let mut child = match cmd { Ok(v) => v, Err(e) => { fatal_popup( @@ -91,5 +95,21 @@ pub fn autostart() -> Result<()> { ); } - Ok(()) + match child.wait() { + Ok(status) => { + trace!(code = status.code(), "original child exit code"); + + let code = status + .code() + .map(|c| ExitCode::from_raw(c as u32)) + .unwrap_or(ExitCode::FAILURE); + + Ok(code) + } + + Err(error) => { + error!(%error, "failed to wait for child"); + Err(eyre!("{error}")) + } + } } diff --git a/crates/yabg3nml/src/bin/bg3_autostart.rs b/crates/yabg3nml/src/bin/bg3_autostart.rs index 3035394..3e147f8 100644 --- a/crates/yabg3nml/src/bin/bg3_autostart.rs +++ b/crates/yabg3nml/src/bin/bg3_autostart.rs @@ -1,9 +1,16 @@ #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] -use shared::popup::fatal_popup; +use std::process::ExitCode; -fn main() { - if let Err(e) = yabg3nml::autostart() { - fatal_popup("autostart failure", e.to_string()); +use shared::popup::{display_popup, MessageBoxIcon}; + +fn main() -> ExitCode { + match yabg3nml::autostart() { + Ok(c) => c, + Err(e) => { + display_popup("Autostart Failure", e.to_string(), MessageBoxIcon::Error); + // DO NOT signal failure for the crash handler + ExitCode::SUCCESS + } } } diff --git a/crates/yabg3nml/src/lib.rs b/crates/yabg3nml/src/lib.rs index 1c2aeb3..d6bfc51 100644 --- a/crates/yabg3nml/src/lib.rs +++ b/crates/yabg3nml/src/lib.rs @@ -1,3 +1,5 @@ +#![feature(windows_process_exit_code_from)] + mod autostart; mod cli; mod console; diff --git a/rust-toolchain.toml b/rust-toolchain.toml index f0ae4e6..fe9ad88 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,4 +1,4 @@ [toolchain] -channel = "1.82" +channel = "nightly-2024-11-17" components = ["rustfmt", "clippy"] profile = "minimal"