plugins-workspace icon indicating copy to clipboard operation
plugins-workspace copied to clipboard

Unstable relaunch with single instance plugin

Open Elendiar opened this issue 1 year ago • 2 comments

With tauri_plugin_single_instance, relaunch from tauri_plugin_process is not guaranteed. Sometimes the application just closes without restarting.

Elendiar avatar Aug 27 '24 07:08 Elendiar

Could you explain a bit more and add a reproducible example?

amrbashir avatar Aug 27 '24 13:08 amrbashir

Could you explain a bit more and add a reproducible example?

Reproducible example with fresh project:

cargo create-tauri-app --rc
cargo tauri add process
cargo tauri add single-instance
// Learn more about Tauri commands at https://tauri.app/v1/guides/features/command
#[tauri::command]
fn greet(name: &str) -> String {
    format!("Hello, {}! You've been greeted from Rust!", name)
}

#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
    tauri::Builder::default()
        .plugin(tauri_plugin_single_instance::init(|_, _, _| {}))
        .plugin(tauri_plugin_process::init())
        .plugin(tauri_plugin_shell::init())
        .invoke_handler(tauri::generate_handler![greet])
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
}

add button to App.tsx

import { relaunch } from "@tauri-apps/plugin-process";
...
<button onClick={relaunch}>Relaunch</button>
...

Build app, install and press Relaunch button. Result, after few (2/3/5/10) successfull relaunches, next relaunch doesn't work. With a ready-made application that takes longer to launch, restarting does not work more often.

Elendiar avatar Aug 29 '24 07:08 Elendiar

I found this will always happens on macOS with tauri-plugin-updater.

anatawa12 avatar Dec 29 '24 11:12 anatawa12

I think muwoo's way to solve the issue is not good I feel. Automatically appending command line arguments may break some apps that works both cli and gui.

I want to suggest destory lock and window handle (on windows), remove socket (on macos), release dbus channel (on linux) just before relaunching app.

It looks current event system is completely asynchronous and no gurantee to ExitRequested and Exit event are sent to main thread before launching new process so this will require new way to share it's being restarted or exiting. (this no gurantee might be the root cause of this issue.)

anatawa12 avatar Dec 29 '24 13:12 anatawa12