Skip to content

Commit 7862ec5

Browse files
authored
fix(macros): change invoke binding in generate handler (#1804)
1 parent 144d6b9 commit 7862ec5

4 files changed

Lines changed: 14 additions & 5 deletions

File tree

‎.changes/cmd-invoke-binding.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri-macros": patch
3+
---
4+
5+
Fixes a name collision when the command function is named `invoke`.

‎core/tauri-macros/src/command/handler.rs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ impl From<Handler> for proc_macro::TokenStream {
5151
wrappers,
5252
}: Handler,
5353
) -> Self {
54-
quote::quote!(move |invoke| {
55-
let __tauri_cmd__ = invoke.message.command();
54+
quote::quote!(move |__tauri_invoke__| {
55+
let __tauri_cmd__ = __tauri_invoke__.message.command();
5656
match __tauri_cmd__ {
57-
#(stringify!(#commands) => #wrappers!(#paths, invoke),)*
57+
#(stringify!(#commands) => #wrappers!(#paths, __tauri_invoke__),)*
5858
_ => {
59-
invoke.resolver.reject(format!("command {} not found", __tauri_cmd__))
59+
__tauri_invoke__.resolver.reject(format!("command {} not found", __tauri_cmd__))
6060
},
6161
}
6262
})

‎examples/commands/src-tauri/src/commands.rs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ use tauri::{command, State};
77
#[command]
88
pub fn cmd(_argument: String) {}
99

10+
#[command]
11+
pub fn invoke(_argument: String) {}
12+
1013
#[command]
1114
pub fn simple_command(argument: String) {
1215
println!("{}", argument);

‎examples/commands/src-tauri/src/main.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
// we move some basic commands to a separate module just to show it works
1111
mod commands;
12-
use commands::cmd;
12+
use commands::{cmd, invoke};
1313

1414
use serde::Deserialize;
1515
use tauri::{command, Params, State, Window};
@@ -169,6 +169,7 @@ fn main() {
169169
commands::simple_command,
170170
commands::stateful_command,
171171
cmd,
172+
invoke,
172173
async_simple_command,
173174
future_simple_command,
174175
async_stateful_command,

0 commit comments

Comments
 (0)