Repository: tauri-apps/tauri (language: rust)

Issue:
[bug] tauri dev watcher exits on tauri.conf/capability changes
### Describe the bug

tauri dev watcher exits with code 1 on tauri.conf.json and capability changes. rust code changes are picked up fine though.

Edit: Tested the wrong version, capability changes also crash which makes more sense to me than it working in this context.

### Reproduction

_No response_

### Expected behavior

_No response_

### Full `tauri info` output

```text
Don't take me as an example and ALWAYS include the tauri info output for us :)
```


### Stack trace

_No response_

### Additional context

_No response_


Discussion / hints:
If I make any changes to src-tauri files it exits and I have to start manually (including rust files).

```bash
[✔] Environment
    - OS: Mac OS 15.1.1 arm64 (X64)
    ✔ Xcode Command Line Tools: installed
    ✔ rustc: 1.81.0 (eeb90cda1 2024-09-04)
    ✔ cargo: 1.81.0 (2dbb1af80 2024-08-20)
    ✔ rustup: 1.27.1 (2024-04-24)
    ✔ Rust toolchain: stable-aarch64-apple-darwin (default)
    - node: 22.12.0
    - pnpm: 9.6.0
    - npm: 10.9.0
    - bun: 1.0.25
    - deno: deno 1.46.3

[-] Packages
    - tauri 🦀: 2.1.1
    - tauri-build 🦀: 2.0.3
    - wry 🦀: 0.47.2
    - tao 🦀: 0.30.8
    - @tauri-apps/api : 2.2.0
    - @tauri-apps/cli : 2.2.1

[-] Plugins
    - tauri-plugin-dialog 🦀: 2.2.0
    - @tauri-apps/plugin-dialog : 2.2.0
    - tauri-plugin-fs 🦀: 2.2.0
    - @tauri-apps/plugin-fs : 2.2.0

[-] App
    - build-type: bundle
    - CSP: default-src 'self' ipc: http://ipc.localhost; img-src 'self' asset: http://asset.localhost
    - frontendDist: ../dist
    - devUrl: http://localhost:1420/
    - framework: React
    - bundler: Vite

hmm, maybe macos behaves differently than windows. can you share the exit messages if any?
@levivoelz Can you try this please?
```
cargo install tauri-cli --debug --git https://github.com/tauri-apps/tauri --branch fix/cli/file-watcher
cargo tauri dev
```

Fix patch:
diff --git a/.changes/cli-watcher-exit-on-change.md b/.changes/cli-watcher-exit-on-change.md
new file mode 100644
index 000000000000..db0b1c77b785
--- /dev/null
+++ b/.changes/cli-watcher-exit-on-change.md
@@ -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.
diff --git a/crates/tauri-cli/src/dev.rs b/crates/tauri-cli/src/dev.rs
index 09e7a4b67ad5..841b3b3d56da 100644
--- a/crates/tauri-cli/src/dev.rs
+++ b/crates/tauri-cli/src/dev.rs
@@ -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));
   }
diff --git a/crates/tauri-cli/src/interface/mod.rs b/crates/tauri-cli/src/interface/mod.rs
index 1b2ad7be8a56..841bb9c2e467 100644
--- a/crates/tauri-cli/src/interface/mod.rs
+++ b/crates/tauri-cli/src/interface/mod.rs
@@ -87,7 +87,7 @@ pub trait AppSettings {
 #[derive(Debug)]
 pub enum ExitReason {
   /// Killed manually.
-  // TriggeredKill,
+  TriggeredKill,
   /// App compilation failed.
   CompilationFailed,
   /// Regular exit.
diff --git a/crates/tauri-cli/src/interface/rust.rs b/crates/tauri-cli/src/interface/rust.rs
index 581a380720ec..7a9c733ebb33 100644
--- a/crates/tauri-cli/src/interface/rust.rs
+++ b/crates/tauri-cli/src/interface/rust.rs
@@ -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;
           }
diff --git a/crates/tauri-cli/src/interface/rust/desktop.rs b/crates/tauri-cli/src/interface/rust/desktop.rs
index 70fbbea511c6..b6318251092d 100644
--- a/crates/tauri-cli/src/interface/rust/desktop.rs
+++ b/crates/tauri-cli/src/interface/rust/desktop.rs
@@ -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,


Test patch: