Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading