Skip to content

Commit 655c714

Browse files
authored
fix(cli): do not panic on Ctrl+C on ios dev (#7240)
1 parent 1542ad1 commit 655c714

File tree

5 files changed

+26
-16
lines changed

5 files changed

+26
-16
lines changed

.changes/fix-ios-cli-panic.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"tauri-cli": patch:bug
3+
"@tauri-apps/cli": patch:bug
4+
---
5+
6+
Fixes panic when exiting the `ios dev` command with Ctrl + C.

tooling/cli/src/dev.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use shared_child::SharedChild;
2222
use std::{
2323
env::set_current_dir,
2424
net::{IpAddr, Ipv4Addr},
25-
process::{exit, Command, ExitStatus, Stdio},
25+
process::{exit, Command, Stdio},
2626
sync::{
2727
atomic::{AtomicBool, Ordering},
2828
Arc, Mutex,
@@ -393,15 +393,19 @@ pub fn setup(options: &mut Options, mobile: bool) -> Result<AppInterface> {
393393

394394
pub fn wait_dev_process<
395395
C: DevProcess + Send + 'static,
396-
F: Fn(ExitStatus, ExitReason) + Send + Sync + 'static,
396+
F: Fn(Option<i32>, ExitReason) + Send + Sync + 'static,
397397
>(
398398
child: C,
399399
on_exit: F,
400400
) {
401401
std::thread::spawn(move || {
402-
let status = child.wait().expect("failed to wait on app");
402+
let code = child
403+
.wait()
404+
.ok()
405+
.and_then(|status| status.code())
406+
.or(Some(1));
403407
on_exit(
404-
status,
408+
code,
405409
if child.manually_killed_process() {
406410
ExitReason::TriggeredKill
407411
} else {
@@ -411,15 +415,15 @@ pub fn wait_dev_process<
411415
});
412416
}
413417

414-
pub fn on_app_exit(status: ExitStatus, reason: ExitReason, exit_on_panic: bool, no_watch: bool) {
418+
pub fn on_app_exit(code: Option<i32>, reason: ExitReason, exit_on_panic: bool, no_watch: bool) {
415419
if no_watch
416420
|| (!matches!(reason, ExitReason::TriggeredKill)
417421
&& (exit_on_panic || matches!(reason, ExitReason::NormalExit)))
418422
{
419423
kill_before_dev_process();
420424
#[cfg(not(debug_assertions))]
421425
let _ = check_for_updates();
422-
exit(status.code().unwrap_or(0));
426+
exit(code.unwrap_or(0));
423427
}
424428
}
425429

tooling/cli/src/interface/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ pub trait Interface: Sized {
9090
fn app_settings(&self) -> &Self::AppSettings;
9191
fn env(&self) -> HashMap<&str, String>;
9292
fn build(&mut self, options: Options) -> crate::Result<()>;
93-
fn dev<F: Fn(ExitStatus, ExitReason) + Send + Sync + 'static>(
93+
fn dev<F: Fn(Option<i32>, ExitReason) + Send + Sync + 'static>(
9494
&mut self,
9595
options: Options,
9696
on_exit: F,

tooling/cli/src/interface/rust.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::{
88
fs::{File, FileType},
99
io::{BufRead, Read, Write},
1010
path::{Path, PathBuf},
11-
process::{Command, ExitStatus},
11+
process::Command,
1212
str::FromStr,
1313
sync::{mpsc::sync_channel, Arc, Mutex},
1414
time::{Duration, Instant},
@@ -160,7 +160,7 @@ impl Interface for Rust {
160160
Ok(())
161161
}
162162

163-
fn dev<F: Fn(ExitStatus, ExitReason) + Send + Sync + 'static>(
163+
fn dev<F: Fn(Option<i32>, ExitReason) + Send + Sync + 'static>(
164164
&mut self,
165165
mut options: Options,
166166
on_exit: F,
@@ -426,7 +426,7 @@ impl Rust {
426426
shared_options(mobile, args, features, &self.app_settings);
427427
}
428428

429-
fn run_dev<F: Fn(ExitStatus, ExitReason) + Send + Sync + 'static>(
429+
fn run_dev<F: Fn(Option<i32>, ExitReason) + Send + Sync + 'static>(
430430
&mut self,
431431
options: Options,
432432
run_args: Vec<String>,

tooling/cli/src/interface/rust/desktop.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ impl DevProcess for DevChild {
6666
}
6767
}
6868

69-
pub fn run_dev<F: Fn(ExitStatus, ExitReason) + Send + Sync + 'static>(
69+
pub fn run_dev<F: Fn(Option<i32>, ExitReason) + Send + Sync + 'static>(
7070
options: Options,
7171
run_args: Vec<String>,
7272
available_targets: &mut Option<Vec<Target>>,
@@ -93,7 +93,7 @@ pub fn run_dev<F: Fn(ExitStatus, ExitReason) + Send + Sync + 'static>(
9393
available_targets,
9494
config_features,
9595
move |status, reason| {
96-
if status.success() {
96+
if status == Some(0) {
9797
let bin_path =
9898
rename_app(target_os, &bin_path, product_name.as_deref()).expect("failed to rename app");
9999
let mut app = Command::new(bin_path);
@@ -192,7 +192,7 @@ pub fn build(
192192
Ok(())
193193
}
194194

195-
fn build_dev_app<F: FnOnce(ExitStatus, ExitReason) + Send + 'static>(
195+
fn build_dev_app<F: FnOnce(Option<i32>, ExitReason) + Send + 'static>(
196196
options: Options,
197197
available_targets: &mut Option<Vec<Target>>,
198198
config_features: Vec<String>,
@@ -259,10 +259,10 @@ fn build_dev_app<F: FnOnce(ExitStatus, ExitReason) + Send + 'static>(
259259

260260
let build_child_ = build_child.clone();
261261
std::thread::spawn(move || {
262-
let status = build_child_.wait().expect("failed to wait on build");
262+
let status = build_child_.wait().expect("failed to build app");
263263

264264
if status.success() {
265-
on_exit(status, ExitReason::NormalExit);
265+
on_exit(status.code(), ExitReason::NormalExit);
266266
} else {
267267
let is_cargo_compile_error = stderr_lines
268268
.lock()
@@ -273,7 +273,7 @@ fn build_dev_app<F: FnOnce(ExitStatus, ExitReason) + Send + 'static>(
273273
stderr_lines.lock().unwrap().clear();
274274

275275
on_exit(
276-
status,
276+
status.code(),
277277
if status.code() == Some(101) && is_cargo_compile_error {
278278
ExitReason::CompilationFailed
279279
} else {

0 commit comments

Comments
 (0)