Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
May 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changes/cmd-invoke-binding.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri-macros": patch
---

Fixes a name collision when the command function is named `invoke`.
8 changes: 4 additions & 4 deletions core/tauri-macros/src/command/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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__))
},
}
})
Expand Down
3 changes: 3 additions & 0 deletions examples/commands/src-tauri/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion examples/commands/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -169,6 +169,7 @@ fn main() {
commands::simple_command,
commands::stateful_command,
cmd,
invoke,
async_simple_command,
future_simple_command,
async_stateful_command,
Expand Down