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
  • Loading branch information
amrbashir committed May 7, 2024
1 parent 07b6f9f commit c5b3751
Show file tree
Hide file tree
Showing 3 changed files with 22 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
17 changes: 16 additions & 1 deletion core/tauri/src/endpoints/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ impl Cmd {
on_event_fn: CallbackFn,
options: CommandOptions,
) -> super::Result<ChildId> {
use std::future::Future;
use std::pin::Pin;

let mut command = if options.sidecar {
#[cfg(not(shell_sidecar))]
return Err(crate::Error::ApiNotAllowlisted("shell > sidecar".to_string()).into_anyhow());
Expand Down Expand Up @@ -170,7 +173,19 @@ 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());
fn eval<'a, R: Runtime>(
window: &'a crate::Window<R>,
js: &'a str,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'a>> {
Box::pin(async move {
if window.eval(js).is_err() {
tokio::time::sleep(std::time::Duration::from_millis(15)).await;
eval(window, js).await;
}
})
}

eval(&context.window, js.as_str()).await;
}
});

Expand Down

0 comments on commit c5b3751

Please sign in to comment.