From 7862ec562fa70e3733263ce1f690d6cd2943c0b4 Mon Sep 17 00:00:00 2001 From: chip Date: Wed, 12 May 2021 08:22:05 -0700 Subject: [PATCH] fix(macros): change invoke binding in generate handler (#1804) --- .changes/cmd-invoke-binding.md | 5 +++++ core/tauri-macros/src/command/handler.rs | 8 ++++---- examples/commands/src-tauri/src/commands.rs | 3 +++ examples/commands/src-tauri/src/main.rs | 3 ++- 4 files changed, 14 insertions(+), 5 deletions(-) create mode 100644 .changes/cmd-invoke-binding.md diff --git a/.changes/cmd-invoke-binding.md b/.changes/cmd-invoke-binding.md new file mode 100644 index 000000000..216b66138 --- /dev/null +++ b/.changes/cmd-invoke-binding.md @@ -0,0 +1,5 @@ +--- +"tauri-macros": patch +--- + +Fixes a name collision when the command function is named `invoke`. diff --git a/core/tauri-macros/src/command/handler.rs b/core/tauri-macros/src/command/handler.rs index ac52a5ad2..6c97ae4d7 100644 --- a/core/tauri-macros/src/command/handler.rs +++ b/core/tauri-macros/src/command/handler.rs @@ -51,12 +51,12 @@ impl From for proc_macro::TokenStream { wrappers, }: Handler, ) -> Self { - quote::quote!(move |invoke| { - let __tauri_cmd__ = invoke.message.command(); + quote::quote!(move |__tauri_invoke__| { + let __tauri_cmd__ = __tauri_invoke__.message.command(); match __tauri_cmd__ { - #(stringify!(#commands) => #wrappers!(#paths, invoke),)* + #(stringify!(#commands) => #wrappers!(#paths, __tauri_invoke__),)* _ => { - invoke.resolver.reject(format!("command {} not found", __tauri_cmd__)) + __tauri_invoke__.resolver.reject(format!("command {} not found", __tauri_cmd__)) }, } }) diff --git a/examples/commands/src-tauri/src/commands.rs b/examples/commands/src-tauri/src/commands.rs index a80f0a970..59ba81ad7 100644 --- a/examples/commands/src-tauri/src/commands.rs +++ b/examples/commands/src-tauri/src/commands.rs @@ -7,6 +7,9 @@ use tauri::{command, State}; #[command] pub fn cmd(_argument: String) {} +#[command] +pub fn invoke(_argument: String) {} + #[command] pub fn simple_command(argument: String) { println!("{}", argument); diff --git a/examples/commands/src-tauri/src/main.rs b/examples/commands/src-tauri/src/main.rs index 3108bdc73..89dc4a74f 100644 --- a/examples/commands/src-tauri/src/main.rs +++ b/examples/commands/src-tauri/src/main.rs @@ -9,7 +9,7 @@ // we move some basic commands to a separate module just to show it works mod commands; -use commands::cmd; +use commands::{cmd, invoke}; use serde::Deserialize; use tauri::{command, Params, State, Window}; @@ -169,6 +169,7 @@ fn main() { commands::simple_command, commands::stateful_command, cmd, + invoke, async_simple_command, future_simple_command, async_stateful_command,