From 509a45bd1ee8c0d251c9cb1c0e6d0598f372fb7d Mon Sep 17 00:00:00 2001 From: Tunglies <77394545+Tunglies@users.noreply.github.com> Date: Thu, 25 Dec 2025 16:53:47 +0800 Subject: [PATCH] fix(server): spawn embedded server commands using AsyncHandler on Linux to prevent new app instance creation --- src-tauri/src/utils/server.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src-tauri/src/utils/server.rs b/src-tauri/src/utils/server.rs index b6f96dbec..3fcdc03d3 100644 --- a/src-tauri/src/utils/server.rs +++ b/src-tauri/src/utils/server.rs @@ -101,6 +101,17 @@ pub fn embed_server() { let commands = visible.or(scheme).or(pac); + #[cfg(target_os = "linux")] + { + // On Linux, spawing through a new tokio runtime cause to create a new app instance + // So we have to spawn through AsyncHandler(tauri::async_runtime) to avoid that + // See relate comments in https://github.com/clash-verge-rev/clash-verge-rev/pull/5908#issuecomment-3678727040 + AsyncHandler::spawn(move || async move { + run(commands, port, shutdown_rx).await; + }); + } + + #[cfg(not(target_os = "linux"))] if let Ok(rt) = tokio::runtime::Builder::new_current_thread() .thread_name("clash-verge-rev-embed-server") .worker_threads(1)