From 0cb8b30424a79508c2d4014af90dd4e49d0f2241 Mon Sep 17 00:00:00 2001 From: Lucas Nogueira Date: Sat, 17 Jun 2023 12:23:27 -0300 Subject: [PATCH 1/2] fix(cli): do not panic on Ctrl+C on `ios dev` --- .changes/fix-ios-cli-panic.md | 6 ++++++ tooling/cli/src/dev.rs | 16 ++++++++++------ tooling/cli/src/interface/mod.rs | 2 +- tooling/cli/src/interface/rust.rs | 6 +++--- tooling/cli/src/interface/rust/desktop.rs | 12 ++++++------ 5 files changed, 26 insertions(+), 16 deletions(-) create mode 100644 .changes/fix-ios-cli-panic.md diff --git a/.changes/fix-ios-cli-panic.md b/.changes/fix-ios-cli-panic.md new file mode 100644 index 000000000000..d58767178b5e --- /dev/null +++ b/.changes/fix-ios-cli-panic.md @@ -0,0 +1,6 @@ +--- +"tauri-cli": patch +"@tauri-apps/cli": patch +--- + +Fixes panic when exiting the `ios dev` command with Ctrl + C. diff --git a/tooling/cli/src/dev.rs b/tooling/cli/src/dev.rs index ef51fdd52f33..8d0d99dbded6 100644 --- a/tooling/cli/src/dev.rs +++ b/tooling/cli/src/dev.rs @@ -22,7 +22,7 @@ use shared_child::SharedChild; use std::{ env::set_current_dir, net::{IpAddr, Ipv4Addr}, - process::{exit, Command, ExitStatus, Stdio}, + process::{exit, Command, Stdio}, sync::{ atomic::{AtomicBool, Ordering}, Arc, Mutex, @@ -393,15 +393,19 @@ pub fn setup(options: &mut Options, mobile: bool) -> Result { pub fn wait_dev_process< C: DevProcess + Send + 'static, - F: Fn(ExitStatus, ExitReason) + Send + Sync + 'static, + F: Fn(Option, ExitReason) + Send + Sync + 'static, >( child: C, on_exit: F, ) { std::thread::spawn(move || { - let status = child.wait().expect("failed to wait on app"); + let code = child + .wait() + .ok() + .and_then(|status| status.code()) + .or(Some(1)); on_exit( - status, + code, if child.manually_killed_process() { ExitReason::TriggeredKill } else { @@ -411,7 +415,7 @@ pub fn wait_dev_process< }); } -pub fn on_app_exit(status: ExitStatus, reason: ExitReason, exit_on_panic: bool, no_watch: bool) { +pub fn on_app_exit(code: Option, reason: ExitReason, exit_on_panic: bool, no_watch: bool) { if no_watch || (!matches!(reason, ExitReason::TriggeredKill) && (exit_on_panic || matches!(reason, ExitReason::NormalExit))) @@ -419,7 +423,7 @@ pub fn on_app_exit(status: ExitStatus, reason: ExitReason, exit_on_panic: bool, kill_before_dev_process(); #[cfg(not(debug_assertions))] let _ = check_for_updates(); - exit(status.code().unwrap_or(0)); + exit(code.unwrap_or(0)); } } diff --git a/tooling/cli/src/interface/mod.rs b/tooling/cli/src/interface/mod.rs index 9cb4cda5561f..c5805cbac0a8 100644 --- a/tooling/cli/src/interface/mod.rs +++ b/tooling/cli/src/interface/mod.rs @@ -90,7 +90,7 @@ pub trait Interface: Sized { fn app_settings(&self) -> &Self::AppSettings; fn env(&self) -> HashMap<&str, String>; fn build(&mut self, options: Options) -> crate::Result<()>; - fn dev( + fn dev, ExitReason) + Send + Sync + 'static>( &mut self, options: Options, on_exit: F, diff --git a/tooling/cli/src/interface/rust.rs b/tooling/cli/src/interface/rust.rs index 1350374ea937..b2d816bc3729 100644 --- a/tooling/cli/src/interface/rust.rs +++ b/tooling/cli/src/interface/rust.rs @@ -8,7 +8,7 @@ use std::{ fs::{File, FileType}, io::{BufRead, Read, Write}, path::{Path, PathBuf}, - process::{Command, ExitStatus}, + process::Command, str::FromStr, sync::{mpsc::sync_channel, Arc, Mutex}, time::{Duration, Instant}, @@ -160,7 +160,7 @@ impl Interface for Rust { Ok(()) } - fn dev( + fn dev, ExitReason) + Send + Sync + 'static>( &mut self, mut options: Options, on_exit: F, @@ -426,7 +426,7 @@ impl Rust { shared_options(mobile, args, features, &self.app_settings); } - fn run_dev( + fn run_dev, ExitReason) + Send + Sync + 'static>( &mut self, options: Options, run_args: Vec, diff --git a/tooling/cli/src/interface/rust/desktop.rs b/tooling/cli/src/interface/rust/desktop.rs index aedcfba71071..fd84d351a48c 100644 --- a/tooling/cli/src/interface/rust/desktop.rs +++ b/tooling/cli/src/interface/rust/desktop.rs @@ -66,7 +66,7 @@ impl DevProcess for DevChild { } } -pub fn run_dev( +pub fn run_dev, ExitReason) + Send + Sync + 'static>( options: Options, run_args: Vec, available_targets: &mut Option>, @@ -93,7 +93,7 @@ pub fn run_dev( available_targets, config_features, move |status, reason| { - if status.success() { + if status == Some(0) { let bin_path = rename_app(target_os, &bin_path, product_name.as_deref()).expect("failed to rename app"); let mut app = Command::new(bin_path); @@ -192,7 +192,7 @@ pub fn build( Ok(()) } -fn build_dev_app( +fn build_dev_app, ExitReason) + Send + 'static>( options: Options, available_targets: &mut Option>, config_features: Vec, @@ -259,10 +259,10 @@ fn build_dev_app( let build_child_ = build_child.clone(); std::thread::spawn(move || { - let status = build_child_.wait().expect("failed to wait on build"); + let status = build_child_.wait().expect("failed to build app"); if status.success() { - on_exit(status, ExitReason::NormalExit); + on_exit(status.code(), ExitReason::NormalExit); } else { let is_cargo_compile_error = stderr_lines .lock() @@ -273,7 +273,7 @@ fn build_dev_app( stderr_lines.lock().unwrap().clear(); on_exit( - status, + status.code(), if status.code() == Some(101) && is_cargo_compile_error { ExitReason::CompilationFailed } else { From 8bd8fd2113f0a5d3102606dc33a70f4c9023e099 Mon Sep 17 00:00:00 2001 From: Lucas Nogueira Date: Sat, 17 Jun 2023 12:38:41 -0300 Subject: [PATCH 2/2] change tag [skip ci] --- .changes/fix-ios-cli-panic.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.changes/fix-ios-cli-panic.md b/.changes/fix-ios-cli-panic.md index d58767178b5e..451e7a300294 100644 --- a/.changes/fix-ios-cli-panic.md +++ b/.changes/fix-ios-cli-panic.md @@ -1,6 +1,6 @@ --- -"tauri-cli": patch -"@tauri-apps/cli": patch +"tauri-cli": patch:bug +"@tauri-apps/cli": patch:bug --- Fixes panic when exiting the `ios dev` command with Ctrl + C.