mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-10-18 23:07:27 +02:00
fix(opener): avoid blocking-runtime panic in reveal_item_in_dir (#3565)
* fix(opener): avoid blocking-runtime panic in reveal_item_in_dir * fix(opener): run zbus reveal on a dedicated thread for all callers Move the runtime-panic fix into the Linux/BSD implementation so the public Rust APIs are covered too, not just the JS command, and propagate the spawn_blocking join error via the existing Tauri error variant. --------- Co-authored-by: Lucas Nogueira <lucas@tauri.app>
This commit is contained in:
1 parent
0e17675653
commit
1ab930465f
3 files changed
+19
-1
No files matched your search
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"opener": "patch"
|
||||
"opener-js": "patch"
|
||||
---
|
||||
|
||||
Fixed `revealItemInDir` and the `reveal_item_in_dir` / `reveal_items_in_dir` Rust APIs panicking on Linux and the BSDs with `Cannot start a runtime from within a runtime` when zbus is built with its `tokio` feature and the call happens inside an async runtime. The blocking D-Bus calls now run on a dedicated thread.
|
||||
@@ -72,5 +72,6 @@ pub async fn open_path<R: Runtime>(
|
||||
/// TODO: in the next major version, rename to `reveal_items_in_dir`
|
||||
#[tauri::command]
|
||||
pub async fn reveal_item_in_dir(paths: Vec<PathBuf>) -> crate::Result<()> {
|
||||
crate::reveal_items_in_dir(&paths)
|
||||
// `reveal_items_in_dir` blocks on D-Bus / shell calls, so keep it off the async runtime workers.
|
||||
tauri::async_runtime::spawn_blocking(move || crate::reveal_items_in_dir(&paths)).await?
|
||||
}
|
||||
@@ -213,6 +213,17 @@ mod imp {
|
||||
use std::path::PathBuf;
|
||||
|
||||
pub fn reveal_items_in_dir(paths: &[PathBuf]) -> crate::Result<()> {
|
||||
// `zbus::blocking` starts its own tokio runtime when zbus is built with the `tokio` feature,
|
||||
// which panics with "Cannot start a runtime from within a runtime" if the caller is already
|
||||
// inside one (e.g. an async command), so always run it on a dedicated thread.
|
||||
std::thread::scope(|s| {
|
||||
s.spawn(|| reveal_items_in_dir_blocking(paths))
|
||||
.join()
|
||||
.unwrap_or_else(|e| std::panic::resume_unwind(e))
|
||||
})
|
||||
}
|
||||
|
||||
fn reveal_items_in_dir_blocking(paths: &[PathBuf]) -> crate::Result<()> {
|
||||
let connection = zbus::blocking::Connection::session()?;
|
||||
|
||||
reveal_with_filemanager1(paths, &connection).or_else(|e| {
|
||||
|
||||
Reference in new issue
Block a user