浏览代码

fix(core): avoid conflict with user-defined `cmd` arg in invoke, closes #4875 (#4892)

Amr Bashir 3 年之前
父节点
当前提交
5109c27501

+ 6 - 0
.changes/invoke-cmd-arg-conflict.md

@@ -0,0 +1,6 @@
+---
+"tauri": "patch"
+"api": "patch"
+---
+
+Fix error when `invoke()` arguments contained a `cmd` field.

文件差异内容过多而无法显示
+ 0 - 0
core/tauri/scripts/bundle.js


+ 1 - 1
core/tauri/scripts/core.js

@@ -60,7 +60,7 @@
       }, true)
 
       if (typeof cmd === 'string') {
-        args.cmd = cmd
+        args.__cmd = cmd
       } else if (typeof cmd === 'object') {
         args = cmd
       } else {

+ 1 - 0
core/tauri/src/hooks.rs

@@ -61,6 +61,7 @@ impl PageLoadPayload {
 #[derive(Debug, Deserialize)]
 pub struct InvokePayload {
   /// The invoke command.
+  #[serde(rename = "__cmd")]
   pub cmd: String,
   #[serde(rename = "__tauriModule")]
   #[doc(hidden)]

+ 2 - 2
examples/api/src-tauri/Cargo.lock

@@ -133,9 +133,9 @@ dependencies = [
 
 [[package]]
 name = "attohttpc"
-version = "0.19.1"
+version = "0.20.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "262c3f7f5d61249d8c00e5546e2685cd15ebeeb1bc0f3cc5449350a1cb07319e"
+checksum = "6ca359af0239b00307656f0d6520fab5997a068cdfcfdb424e5466a3ea7958c5"
 dependencies = [
  "flate2",
  "http",

+ 1 - 1
tooling/api/src/tauri.ts

@@ -82,7 +82,7 @@ async function invoke<T>(cmd: string, args: InvokeArgs = {}): Promise<T> {
     }, true)
 
     window.__TAURI_IPC__({
-      cmd,
+      __cmd: cmd,
       callback,
       error,
       ...args

部分文件因为文件数量过多而无法显示