diff --git a/Cargo.lock b/Cargo.lock index adf0f4e..7260058 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3906,6 +3906,16 @@ dependencies = [ "windows-targets 0.48.1", ] +[[package]] +name = "windows" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e48a53791691ab099e5e2ad123536d0fff50652600abaf43bbf952894110d0be" +dependencies = [ + "windows-core", + "windows-targets 0.52.0", +] + [[package]] name = "windows-bindgen" version = "0.39.0" @@ -3916,6 +3926,15 @@ dependencies = [ "windows-tokens", ] +[[package]] +name = "windows-core" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" +dependencies = [ + "windows-targets 0.52.0", +] + [[package]] name = "windows-implement" version = "0.39.0" @@ -4323,6 +4342,7 @@ dependencies = [ "tracing", "tracing-subscriber", "walkdir", + "windows 0.52.0", ] [[package]] diff --git a/client/src-tauri/Cargo.toml b/client/src-tauri/Cargo.toml index 324c78b..dd9afd3 100644 --- a/client/src-tauri/Cargo.toml +++ b/client/src-tauri/Cargo.toml @@ -44,3 +44,6 @@ clap = { version = "4.5.0", features = ["derive"] } # this feature is used for production builds or when `devPath` points to the filesystem # DO NOT REMOVE!! custom-protocol = ["tauri/custom-protocol"] + +[target."cfg(windows)".dependencies] +windows = { version = "0.52.0", features = ["Win32_System_Console", "Win32_Foundation"] } diff --git a/client/src-tauri/src/cli.rs b/client/src-tauri/src/cli.rs index 6ae38de..08233bf 100644 --- a/client/src-tauri/src/cli.rs +++ b/client/src-tauri/src/cli.rs @@ -28,19 +28,31 @@ enum Commands { }, } -pub fn check_cli() -> Result { +fn attach_console() { + #[cfg(windows)] + { + use windows::Win32::System::Console::{AttachConsole, ATTACH_PARENT_PROCESS}; + let _ = unsafe { AttachConsole(ATTACH_PARENT_PROCESS) }; + } +} + +pub fn check_cli() { + if std::env::args_os().len() > 1 { + // Ensure a console is attached on Windows + attach_console(); + } + let args = Args::parse(); if let Some(command) = args.command { match command { Commands::ExportDats { project_dir } => { - export_all_dats(project_dir)?; + export_all_dats(project_dir).unwrap(); } } - return Ok(true); - } - return Ok(false); + std::process::exit(0); + } } pub fn export_all_dats(project_dir: String) -> Result<()> { diff --git a/client/src-tauri/src/main.rs b/client/src-tauri/src/main.rs index 918f1e8..5c6376f 100644 --- a/client/src-tauri/src/main.rs +++ b/client/src-tauri/src/main.rs @@ -25,9 +25,7 @@ pub const DAT_GENERATION_DIR: &'static str = "generated_dats"; pub const ZONE_MAPPING_FILE: &'static str = "zones.yml"; fn main() { - if check_cli().unwrap() { - return; - } + check_cli(); #[cfg(debug_assertions)] ts::export(