فهرست منبع

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
Amr Bashir 1 سال پیش
والد
کامیت
e48157da2f
3فایلهای تغییر یافته به همراه21 افزوده شده و 2 حذف شده
  1. 5 0
      .changes/shell-command-lost-events.md
  2. 1 1
      core/tauri/Cargo.toml
  3. 15 1
      core/tauri/src/endpoints/shell.rs

+ 5 - 0
.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`.

+ 1 - 1
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" }

+ 15 - 1
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<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;
+        }
       }
     });