fix(macros): change invoke binding in generate handler (#1804)

This commit is contained in:
chip 2021-05-12 08:22:05 -07:00 committed by GitHub
parent 144d6b9d4d
commit 7862ec562f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 5 deletions

View File

@ -0,0 +1,5 @@
---
"tauri-macros": patch
---
Fixes a name collision when the command function is named `invoke`.

View File

@ -51,12 +51,12 @@ impl From<Handler> 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__))
},
}
})

View File

@ -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);

View File

@ -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,