Repository: tauri
Issue: [bug] `AppHandle::restart` may exit process without waiting for `RunEvent::Exit` event emit to plugins / app.
Labels: type: bug,status: needs triage

### Describe the bug

`AppHandle::restart` may exit process without waiting for `RunEvent::Exit` event emit to plugins / app.

This is upstream / super issue for:
- #11392
- tauri-apps/plugins-workspace#1692
- tauri-apps/plugins-workspace#2256


### 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

```rust
// 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

```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
```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

```text
[✔] 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.