From e48157da2f0b88d8c5df13f3287705172a684525 Mon Sep 17 00:00:00 2001 From: Amr Bashir Date: Tue, 28 May 2024 17:48:57 +0300 Subject: [PATCH] fix(core/shell/command): retry sending events when it fails, closes #7684 (#9698) * fix(core/shell/command): retry sending events when it fails, closes #7684 * try normally first * sleep first --- .changes/shell-command-lost-events.md | 5 +++++ core/tauri/Cargo.toml | 2 +- core/tauri/src/endpoints/shell.rs | 16 +++++++++++++++- 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 .changes/shell-command-lost-events.md diff --git a/.changes/shell-command-lost-events.md b/.changes/shell-command-lost-events.md new file mode 100644 index 000000000000..d2d71d568f96 --- /dev/null +++ b/.changes/shell-command-lost-events.md @@ -0,0 +1,5 @@ +--- +"tauri": "patch:bug" +--- + +Fix the JS `Command` API from `shell` module, losing events for `stdout`. diff --git a/core/tauri/Cargo.toml b/core/tauri/Cargo.toml index e86783bbd7c5..9e3566bafbb8 100644 --- a/core/tauri/Cargo.toml +++ b/core/tauri/Cargo.toml @@ -51,7 +51,7 @@ normal = [ "reqwest", "nix" ] [dependencies] serde_json = { version = "1.0", features = [ "raw_value", "preserve_order" ] } serde = { version = "1.0", features = [ "derive" ] } -tokio = { version = "1", features = [ "rt", "rt-multi-thread", "sync", "fs", "io-util" ] } +tokio = { version = "1", features = ["time", "rt", "rt-multi-thread", "sync", "fs", "io-util" ] } futures-util = "0.3" uuid = { version = "1", features = [ "v4" ] } url = { version = "2.3" } diff --git a/core/tauri/src/endpoints/shell.rs b/core/tauri/src/endpoints/shell.rs index 90d8db63e444..d40689f8f5a9 100644 --- a/core/tauri/src/endpoints/shell.rs +++ b/core/tauri/src/endpoints/shell.rs @@ -167,7 +167,21 @@ impl Cmd { let js = crate::api::ipc::format_callback(on_event_fn, &event) .expect("unable to serialize CommandEvent"); - let _ = context.window.eval(js.as_str()); + if context.window.eval(js.as_str()).is_err() { + fn eval<'a, R: Runtime>( + window: &'a crate::Window, + js: &'a str, + ) -> Pin + Send + 'a>> { + Box::pin(async move { + tokio::time::sleep(std::time::Duration::from_millis(15)).await; + if window.eval(js).is_err() { + eval(window, js).await; + } + }) + } + + eval(&context.window, js.as_str()).await; + } } });