Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] AppHandle::restart may exit process without waiting for RunEvent::Exit event emit to plugins / app. #12310

Open
anatawa12 opened this issue Jan 8, 2025 · 0 comments · May be fixed by #12313
Labels
status: needs triage This issue needs to triage, applied to new issues type: bug

Comments

@anatawa12
Copy link
Contributor

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.

@anatawa12 anatawa12 added status: needs triage This issue needs to triage, applied to new issues type: bug labels Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs triage This issue needs to triage, applied to new issues type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant