fix(cli): Re-add TriggeredKill in dev watcher logic (#12178)

This commit is contained in:
Fabian-Lars
2025-01-04 00:39:07 +01:00
committed by GitHub
parent 90dc7b19fc
commit 26fc9558fe
5 changed files with 16 additions and 6 deletions

View File

@@ -0,0 +1,6 @@
---
'tauri-cli': 'patch:bug'
'@tauri-apps/cli': 'patch:bug'
---
Fixed an issue that caused the `tauri dev` file watcher to exit after detecting file changes.

View File

@@ -339,7 +339,10 @@ pub fn setup(interface: &AppInterface, options: &mut Options, config: ConfigHand
}
pub fn on_app_exit(code: Option<i32>, reason: ExitReason, exit_on_panic: bool, no_watch: bool) {
if no_watch || exit_on_panic || matches!(reason, ExitReason::NormalExit) {
if no_watch
|| (!matches!(reason, ExitReason::TriggeredKill)
&& (exit_on_panic || matches!(reason, ExitReason::NormalExit)))
{
kill_before_dev_process();
exit(code.unwrap_or(0));
}

View File

@@ -87,7 +87,7 @@ pub trait AppSettings {
#[derive(Debug)]
pub enum ExitReason {
/// Killed manually.
// TriggeredKill,
TriggeredKill,
/// App compilation failed.
CompilationFailed,
/// Regular exit.

View File

@@ -553,7 +553,6 @@ impl Rust {
loop {
if let Ok(events) = rx.recv() {
for event in events {
#[cfg(target_os = "linux")]
if event.kind.is_access() {
continue;
}

View File

@@ -78,6 +78,9 @@ pub fn run_dev<F: Fn(Option<i32>, ExitReason) + Send + Sync + 'static>(
dev_cmd.arg("--");
dev_cmd.args(run_args);
let manually_killed_app = Arc::new(AtomicBool::default());
let manually_killed_app_ = manually_killed_app.clone();
let dev_child = match SharedChild::spawn(&mut dev_cmd) {
Ok(c) => Ok(c),
Err(e) if e.kind() == ErrorKind::NotFound => Err(anyhow::anyhow!(
@@ -128,6 +131,8 @@ pub fn run_dev<F: Fn(Option<i32>, ExitReason) + Send + Sync + 'static>(
status.code(),
if status.code() == Some(101) && is_cargo_compile_error {
ExitReason::CompilationFailed
} else if manually_killed_app_.load(Ordering::Relaxed) {
ExitReason::TriggeredKill
} else {
ExitReason::NormalExit
},
@@ -135,9 +140,6 @@ pub fn run_dev<F: Fn(Option<i32>, ExitReason) + Send + Sync + 'static>(
}
});
// TODO: remove this and DevChild (requires refactor for code shared between mobile and desktop)
let manually_killed_app = Arc::new(AtomicBool::default());
Ok(DevChild {
manually_killed_app,
dev_child,