-
I am rewriting a .net app in tauri for compatibility issues and cross platform problems. Program starts an adb server at start and i want to kill the server at the end of the session(when the app is closed) but I couldn't find something related to this in google and tauri guides (or I missed it). |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
If you spawn the program in your frontend, tauri is supposed to clean it up automatically. If you spawn it in Rust, you can use the RunEvent::ExitRequested or Exit events to kill it. There are also window close events but it's more likely that they don't trigger than for the Exit events to not trigger (in case the user stops the app itself and doesn't close the window normally). Here's an example on how to handle RunEvents https://github.com/tauri-apps/tauri/blob/dev/examples/api/src-tauri/src/lib.rs#L152 |
Beta Was this translation helpful? Give feedback.
Process created gets quickly terminated because adb server and the command i am using to start it are different processes, but after searching for like what felt like an eternity i found how to attach events to the default function.
Here is the solution of running functions upon exit:
tauri::Builder::default().on_window_event(|event| match event.event() { tauri::WindowEvent::CloseRequested { api, .. } => { // CODE HERE } _ => {} });
you can merge this part with your invoke_handler, setup, run and expect in
tauri::Builder::default()
for full functionality.Also as far as i tested it still works when user kills the process via terminal etc.