mirror of
https://github.com/tauri-apps/tauri.git
synced 2024-11-28 20:48:52 +03:00
fix(cli): do not panic on Ctrl+C on ios dev
(#7240)
This commit is contained in:
parent
1542ad17d6
commit
655c714e41
6
.changes/fix-ios-cli-panic.md
Normal file
6
.changes/fix-ios-cli-panic.md
Normal file
@ -0,0 +1,6 @@
|
||||
---
|
||||
"tauri-cli": patch:bug
|
||||
"@tauri-apps/cli": patch:bug
|
||||
---
|
||||
|
||||
Fixes panic when exiting the `ios dev` command with Ctrl + C.
|
@ -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<AppInterface> {
|
||||
|
||||
pub fn wait_dev_process<
|
||||
C: DevProcess + Send + 'static,
|
||||
F: Fn(ExitStatus, ExitReason) + Send + Sync + 'static,
|
||||
F: Fn(Option<i32>, 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<i32>, 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));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<F: Fn(ExitStatus, ExitReason) + Send + Sync + 'static>(
|
||||
fn dev<F: Fn(Option<i32>, ExitReason) + Send + Sync + 'static>(
|
||||
&mut self,
|
||||
options: Options,
|
||||
on_exit: F,
|
||||
|
@ -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<F: Fn(ExitStatus, ExitReason) + Send + Sync + 'static>(
|
||||
fn dev<F: Fn(Option<i32>, 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<F: Fn(ExitStatus, ExitReason) + Send + Sync + 'static>(
|
||||
fn run_dev<F: Fn(Option<i32>, ExitReason) + Send + Sync + 'static>(
|
||||
&mut self,
|
||||
options: Options,
|
||||
run_args: Vec<String>,
|
||||
|
@ -66,7 +66,7 @@ impl DevProcess for DevChild {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn run_dev<F: Fn(ExitStatus, ExitReason) + Send + Sync + 'static>(
|
||||
pub fn run_dev<F: Fn(Option<i32>, ExitReason) + Send + Sync + 'static>(
|
||||
options: Options,
|
||||
run_args: Vec<String>,
|
||||
available_targets: &mut Option<Vec<Target>>,
|
||||
@ -93,7 +93,7 @@ pub fn run_dev<F: Fn(ExitStatus, ExitReason) + Send + Sync + 'static>(
|
||||
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<F: FnOnce(ExitStatus, ExitReason) + Send + 'static>(
|
||||
fn build_dev_app<F: FnOnce(Option<i32>, ExitReason) + Send + 'static>(
|
||||
options: Options,
|
||||
available_targets: &mut Option<Vec<Target>>,
|
||||
config_features: Vec<String>,
|
||||
@ -259,10 +259,10 @@ fn build_dev_app<F: FnOnce(ExitStatus, ExitReason) + Send + 'static>(
|
||||
|
||||
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<F: FnOnce(ExitStatus, ExitReason) + Send + 'static>(
|
||||
stderr_lines.lock().unwrap().clear();
|
||||
|
||||
on_exit(
|
||||
status,
|
||||
status.code(),
|
||||
if status.code() == Some(101) && is_cargo_compile_error {
|
||||
ExitReason::CompilationFailed
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user