Skip to content

Commit

Permalink
fix(core/shell/command): retry sending events when it fails, closes #…
Browse files Browse the repository at this point in the history
…7684 (#9698)

* fix(core/shell/command): retry sending events when it fails, closes #7684

* try normally first

* sleep first
  • Loading branch information
amrbashir authored May 28, 2024
1 parent 44e3335 commit e48157d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changes/shell-command-lost-events.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri": "patch:bug"
---

Fix the JS `Command` API from `shell` module, losing events for `stdout`.
2 changes: 1 addition & 1 deletion core/tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
16 changes: 15 additions & 1 deletion core/tauri/src/endpoints/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<R>,
js: &'a str,
) -> Pin<Box<dyn Future<Output = ()> + 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;
}
}
});

Expand Down

0 comments on commit e48157d

Please sign in to comment.