Describe the bug
AppHandle::restart may exit process without waiting for RunEvent::Exit event emit to plugins / app.
This is upstream / super issue for:
Reproduction
Add log on RunEvent::Exit, make do something a little slow (like file system operation, or just sleep), and button to call restart().
mini app based on npx tauri init. (removing lib crate)
main.rs
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
fn main() {
tauri::Builder::default()
.invoke_handler(tauri::generate_handler![restart])
.build(tauri::generate_context!())
.expect("error while running tauri application")
.run(|_, event| match event {
tauri::RunEvent::ExitRequested { .. } => {
println!("Exit requested...");
std::thread::sleep(std::time::Duration::from_millis(1));
}
tauri::RunEvent::Exit => {
println!("Exiting...");
}
_ => {}
});
}
#[tauri::command]
async fn restart(app: tauri::AppHandle) -> () {
app.restart();
}
index.html
<!doctype html>
<script>
var restart = async () => {
try {
await __TAURI_INTERNALS__.invoke("restart")
} catch (e) {
console.error(e);
}
}
</script>
<button onclick="restart()">restart</button>
tauri.conf.json
{
"$schema": "https://schema.tauri.app/config/2.0.0-rc",
"productName": "Tauri App",
"version": "0.1.0",
"identifier": "com.tauri.dev",
"build": {
"frontendDist": "."
},
"app": {
"windows": [
{
"title": "Tauri",
"width": 800,
"height": 600,
"resizable": true,
"fullscreen": false
}
]
}
}
Expected behavior
tauri::RunEvent::Exit should always be called
Full tauri info output
[✔] Environment
- OS: Mac OS 15.0.1 arm64 (X64)
✔ Xcode Command Line Tools: installed
✔ rustc: 1.83.0 (90b35a623 2024-11-26)
✔ cargo: 1.83.0 (5ffbef321 2024-10-29)
✔ rustup: 1.27.1 (54dd3d00f 2024-04-24)
✔ Rust toolchain: stable-aarch64-apple-darwin (default)
- node: 22.6.0
- pnpm: 8.15.4
- npm: 10.8.2
- deno: deno 1.45.5
[-] Packages
- tauri 🦀: 2.1.1
- tauri-build 🦀: 2.0.3
- wry 🦀: 0.47.2
- tao 🦀: 0.30.8
- tauri-cli 🦀: 2.0.0-rc.3
- @tauri-apps/api : 2.1.1 (outdated, latest: 2.2.0)
- @tauri-apps/cli : 2.1.0 (outdated, latest: 2.2.2)
[-] Plugins
- tauri-plugin-dialog 🦀: 2.2.0
- @tauri-apps/plugin-dialog : not installed!
- tauri-plugin-single-instance 🦀: 2.2.0
- @tauri-apps/plugin-single-instance : not installed!
- tauri-plugin-updater 🦀: 2.3.0
- @tauri-apps/plugin-updater : not installed!
- tauri-plugin-fs 🦀: 2.2.0
- @tauri-apps/plugin-fs : not installed!
[-] App
- build-type: bundle
- CSP: unset
- frontendDist: out
- devUrl: http://localhost:3030/
- framework: React (Next.js)
- bundler: Webpack
Stack trace
No response
Additional context
I'm looking for fix this issue with waiting for exit event in restart.
Describe the bug
AppHandle::restartmay exit process without waiting forRunEvent::Exitevent emit to plugins / app.This is upstream / super issue for:
app_handle.restart()plugins-workspace#2256Reproduction
Add log on
RunEvent::Exit, make do something a little slow (like file system operation, or just sleep), and button to callrestart().mini app based on npx tauri init. (removing lib crate)
main.rs
index.html
tauri.conf.json
{ "$schema": "https://schema.tauri.app/config/2.0.0-rc", "productName": "Tauri App", "version": "0.1.0", "identifier": "com.tauri.dev", "build": { "frontendDist": "." }, "app": { "windows": [ { "title": "Tauri", "width": 800, "height": 600, "resizable": true, "fullscreen": false } ] } }Expected behavior
tauri::RunEvent::Exitshould always be calledFull
tauri infooutputStack trace
No response
Additional context
I'm looking for fix this issue with waiting for exit event in restart.