@@ -63,7 +63,7 @@ pub fn generate_command(function: ItemFn) -> TokenStream {
6363 }
6464 }
6565
66- let arg_name_ = arg_name. clone ( ) . unwrap ( ) ;
66+ let arg_name_ = arg_name. unwrap ( ) ;
6767 let arg_name_s = arg_name_. to_string ( ) ;
6868
6969 let arg_type = match arg_type {
@@ -76,13 +76,14 @@ pub fn generate_command(function: ItemFn) -> TokenStream {
7676 }
7777 } ;
7878
79- invoke_args. append_all ( quote ! {
80- let #arg_name_ = match <#arg_type>:: from_command( #fn_name_str, #arg_name_s, & message) {
81- Ok ( value) => value,
82- Err ( e) => return tauri:: InvokeResponse :: error( :: tauri:: Error :: InvalidArgs ( #fn_name_str, e) . to_string( ) )
83- } ;
79+ let item = quote ! ( :: tauri:: command:: CommandItem {
80+ name: #fn_name_str,
81+ key: #arg_name_s,
82+ message: & __message,
8483 } ) ;
85- invoke_arg_names. push ( arg_name_. clone ( ) ) ;
84+
85+ invoke_args. append_all ( quote ! ( let #arg_name_ = <#arg_type>:: from_command( #item) ?; ) ) ;
86+ invoke_arg_names. push ( arg_name_) ;
8687 invoke_arg_types. push ( arg_type) ;
8788 }
8889
@@ -97,21 +98,19 @@ pub fn generate_command(function: ItemFn) -> TokenStream {
9798 // otherwise we wrap it with an `Ok()`, converting the return value to tauri::InvokeResponse
9899 // note that all types must implement `serde::Serialize`.
99100 let return_value = if returns_result {
100- quote ! {
101- match #fn_name( #( #invoke_arg_names) , * ) #await_maybe {
102- Ok ( value) => :: core:: result:: Result :: <_, ( ) >:: Ok ( value) . into( ) ,
103- Err ( e) => :: core:: result:: Result :: <( ) , _>:: Err ( e) . into( ) ,
104- }
105- }
101+ quote ! ( :: core:: result:: Result :: Ok ( #fn_name( #( #invoke_arg_names) , * ) #await_maybe?) )
106102 } else {
107- quote ! { :: core:: result:: Result :: <_, ( ) >:: Ok ( #fn_name( #( #invoke_arg_names) , * ) #await_maybe) . into ( ) }
103+ quote ! { :: core:: result:: Result :: <_, :: tauri :: InvokeError >:: Ok ( #fn_name( #( #invoke_arg_names) , * ) #await_maybe) }
108104 } ;
109105
106+ // double underscore prefix temporary until underlying scoping issue is fixed (planned)
110107 quote ! {
111108 #function
112- #vis fn #fn_wrapper<P : :: tauri:: Params >( message: :: tauri:: InvokeMessage <P >, resolver: :: tauri:: InvokeResolver <P >) {
113- use :: tauri:: command:: FromCommand ;
114- resolver. respond_async( async move {
109+
110+ #vis fn #fn_wrapper<P : :: tauri:: Params >( invoke: :: tauri:: Invoke <P >) {
111+ use :: tauri:: command:: CommandArg ;
112+ let :: tauri:: Invoke { message: __message, resolver: __resolver } = invoke;
113+ __resolver. respond_async( async move {
115114 #invoke_args
116115 #return_value
117116 } )
@@ -139,12 +138,12 @@ pub fn generate_handler(item: proc_macro::TokenStream) -> TokenStream {
139138 } ) ;
140139
141140 quote ! {
142- move |message , resolver | {
143- let cmd = message. command( ) . to_string ( ) ;
144- match cmd. as_str ( ) {
145- #( stringify!( #fn_names) => #fn_wrappers( message , resolver ) , ) *
141+ move |invoke | {
142+ let cmd = invoke . message. command( ) ;
143+ match cmd {
144+ #( stringify!( #fn_names) => #fn_wrappers( invoke ) , ) *
146145 _ => {
147- resolver. reject( format!( "command {} not found" , cmd) )
146+ invoke . resolver. reject( format!( "command {} not found" , cmd) )
148147 } ,
149148 }
150149 }
0 commit comments