Skip to content

Commit

Permalink
fix(cli): Re-add TriggeredKill in dev watcher logic (#12178)
Browse files Browse the repository at this point in the history
  • Loading branch information
FabianLars authored Jan 3, 2025
1 parent 90dc7b1 commit 26fc955
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 6 deletions.
6 changes: 6 additions & 0 deletions .changes/cli-watcher-exit-on-change.md
Original file line number Diff line number Diff line change
@@ -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.
5 changes: 4 additions & 1 deletion crates/tauri-cli/src/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
2 changes: 1 addition & 1 deletion crates/tauri-cli/src/interface/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ pub trait AppSettings {
#[derive(Debug)]
pub enum ExitReason {
/// Killed manually.
// TriggeredKill,
TriggeredKill,
/// App compilation failed.
CompilationFailed,
/// Regular exit.
Expand Down
1 change: 0 additions & 1 deletion crates/tauri-cli/src/interface/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
8 changes: 5 additions & 3 deletions crates/tauri-cli/src/interface/rust/desktop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down Expand Up @@ -128,16 +131,15 @@ 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
},
);
}
});

// 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,
Expand Down

0 comments on commit 26fc955

Please sign in to comment.