Skip to content

Commit 3108ebd

Browse files
committed
Refactor process handling in lib.rs for improved clarity
- Simplified the process handling logic in the `run` function by restructuring the conditional statements for better readability. - Enhanced the cleanup logic during app exit to ensure consistent handling of the backend process termination. These changes improve the maintainability and clarity of the code in the Tauri application.
1 parent 2d7f682 commit 3108ebd

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

frontend/src-tauri/src/lib.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1626,10 +1626,10 @@ pub fn run() {
16261626
} else {
16271627
// If lock is held, wait briefly then try again
16281628
std::thread::sleep(std::time::Duration::from_millis(50));
1629-
if let Ok(mut process) = state.lock()
1630-
&& let Some(mut child) = process.take()
1631-
{
1632-
kill_backend_process(&mut child);
1629+
if let Ok(mut process) = state.lock() {
1630+
if let Some(mut child) = process.take() {
1631+
kill_backend_process(&mut child);
1632+
}
16331633
}
16341634
}
16351635
}
@@ -1646,13 +1646,14 @@ pub fn run() {
16461646
if let tauri::RunEvent::ExitRequested { .. } = event {
16471647
info!("App exit requested, cleaning up backend process...");
16481648
// Cleanup backend process synchronously on app exit to ensure it completes
1649-
if let Some(state) = app.try_state::<Mutex<Option<Child>>>()
1650-
&& let Ok(mut process) = state.lock()
1651-
&& let Some(mut child) = process.take()
1652-
{
1653-
kill_backend_process(&mut child);
1654-
// Wait a moment to ensure process is killed
1655-
std::thread::sleep(std::time::Duration::from_millis(200));
1649+
if let Some(state) = app.try_state::<Mutex<Option<Child>>>() {
1650+
if let Ok(mut process) = state.lock() {
1651+
if let Some(mut child) = process.take() {
1652+
kill_backend_process(&mut child);
1653+
// Wait a moment to ensure process is killed
1654+
std::thread::sleep(std::time::Duration::from_millis(200));
1655+
}
1656+
}
16561657
}
16571658
// Also kill any process on port 8000 as a fallback
16581659
kill_process_on_port(8000);

0 commit comments

Comments
 (0)