Kill spawned processes on App close from Javascript Code #5870
-
Hi! I am using Tauri for a while to write production apps. I am not being able to close spawned processes when the app is closed. How do I do it? Note I tried listening to Also, I tried using this code to listen to all events but it seems like the code cannot detect some events like import { writeTextFile } from "@tauri-apps/api/fs";
import { listen, TauriEvent } from "@tauri-apps/api/event";
Object.entries(TauriEvent).forEach(([key, value]) => {
listen<string>(value, async (event) => {
console.log("Closing App..");
writeTextFile(key, `${key} on ${new Date().toLocaleString()}\n${JSON.stringify(event, null, 2)}`);
});
}); Only these 4 events were logged after much testing: Can anyone tell me the correct way to do it? EDIT: |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 2 replies
-
hmm, maybe try the window specific
It depends. If it's spawned as a sidecar then Tauri should handle it itself. The problem is that some (sidecar) apps spawn multiple processes without cleaning up after themselves. This is currently only solvable in Rust, see #3273 for example. |
Beta Was this translation helpful? Give feedback.
-
@FabianLars I don't know Rust. I am a FullStack JS/TS developer. I am using the What do you recommend me to do in this situation? |
Beta Was this translation helpful? Give feedback.
-
tried that also in the dev mode but got the following error: |
Beta Was this translation helpful? Give feedback.
hmm, maybe try the window specific
listen
methods (likeappWindow.listen
), which also has a helper function: https://tauri.app/v1/api/js/window#oncloserequestedIt depends. If it's spawned as a sidecar then Tauri should handle it itself. The problem is that some (sidecar) apps spawn multiple processes without cleaning up after themselves. This is currently only solvable in Rust, see #3273 for example.
If we're talking about "normal" Commands (not sidecars) then you need to handle it yourself.