From 8b6f3de0ad47684e72a2ae5f884d8675acfaeeac Mon Sep 17 00:00:00 2001 From: Lucas Fernandes Nogueira Date: Sun, 2 May 2021 15:34:15 -0300 Subject: [PATCH] feat(core): add state management, closes #1655 (#1665) * feat(core): add state management, closes #1655 * fix(tests): ignore doc example * use a trait to manage #[command] parameters * add docs [skip ci] * finish command before moving into respond_async * Revert "finish command before moving into respond_async" This reverts commit 4651bed5bf2bb91dbab9fce4807578ed67cf0468. * refactor: split InvokeMessage into InvokeResolver, add InvokeResponse * feat: add managed state to the plugin interface * feat: add commands example * add change file [skip ci] * cleanup clones Co-authored-by: chip reed --- .changes/app-state.md | 5 + .changes/command-state.md | 5 + .changes/plugin-refactor.md | 7 + .changes/remove-with-window.md | 5 + Cargo.toml | 1 + core/tauri-macros/src/command.rs | 141 ++++---- core/tauri-macros/src/lib.rs | 7 +- core/tauri/Cargo.toml | 1 + core/tauri/src/command.rs | 300 ++++++++++++++++++ core/tauri/src/endpoints.rs | 75 +++-- core/tauri/src/hooks.rs | 270 +++++++++------- core/tauri/src/lib.rs | 54 +++- core/tauri/src/plugin.rs | 21 +- core/tauri/src/runtime/app.rs | 71 ++++- core/tauri/src/runtime/manager.rs | 44 ++- core/tauri/src/runtime/webview.rs | 13 + core/tauri/src/runtime/window.rs | 38 ++- core/tauri/src/state.rs | 63 ++++ examples/api/src-tauri/src/cmd.rs | 8 +- examples/commands/package.json | 7 + examples/commands/public/index.html | 55 ++++ examples/commands/src-tauri/.gitignore | 10 + examples/commands/src-tauri/.license_template | 1 + examples/commands/src-tauri/Cargo.toml | 17 + examples/commands/src-tauri/build.rs | 7 + examples/commands/src-tauri/icons/128x128.png | Bin 0 -> 15920 bytes .../commands/src-tauri/icons/128x128@2x.png | Bin 0 -> 37546 bytes examples/commands/src-tauri/icons/32x32.png | Bin 0 -> 2400 bytes .../src-tauri/icons/Square107x107Logo.png | Bin 0 -> 12659 bytes .../src-tauri/icons/Square142x142Logo.png | Bin 0 -> 18057 bytes .../src-tauri/icons/Square150x150Logo.png | Bin 0 -> 19312 bytes .../src-tauri/icons/Square284x284Logo.png | Bin 0 -> 41714 bytes .../src-tauri/icons/Square30x30Logo.png | Bin 0 -> 2132 bytes .../src-tauri/icons/Square310x310Logo.png | Bin 0 -> 45901 bytes .../src-tauri/icons/Square44x44Logo.png | Bin 0 -> 3763 bytes .../src-tauri/icons/Square71x71Logo.png | Bin 0 -> 7380 bytes .../src-tauri/icons/Square89x89Logo.png | Bin 0 -> 9831 bytes .../commands/src-tauri/icons/StoreLogo.png | Bin 0 -> 4552 bytes examples/commands/src-tauri/icons/icon.icns | Bin 0 -> 512919 bytes examples/commands/src-tauri/icons/icon.ico | Bin 0 -> 57594 bytes examples/commands/src-tauri/icons/icon.png | Bin 0 -> 90074 bytes examples/commands/src-tauri/src/main.rs | 92 ++++++ examples/commands/src-tauri/tauri.conf.json | 56 ++++ 43 files changed, 1111 insertions(+), 263 deletions(-) create mode 100644 .changes/app-state.md create mode 100644 .changes/command-state.md create mode 100644 .changes/plugin-refactor.md create mode 100644 .changes/remove-with-window.md create mode 100644 core/tauri/src/command.rs create mode 100644 core/tauri/src/state.rs create mode 100644 examples/commands/package.json create mode 100644 examples/commands/public/index.html create mode 100644 examples/commands/src-tauri/.gitignore create mode 100644 examples/commands/src-tauri/.license_template create mode 100644 examples/commands/src-tauri/Cargo.toml create mode 100644 examples/commands/src-tauri/build.rs create mode 100644 examples/commands/src-tauri/icons/128x128.png create mode 100644 examples/commands/src-tauri/icons/128x128@2x.png create mode 100644 examples/commands/src-tauri/icons/32x32.png create mode 100644 examples/commands/src-tauri/icons/Square107x107Logo.png create mode 100644 examples/commands/src-tauri/icons/Square142x142Logo.png create mode 100644 examples/commands/src-tauri/icons/Square150x150Logo.png create mode 100644 examples/commands/src-tauri/icons/Square284x284Logo.png create mode 100644 examples/commands/src-tauri/icons/Square30x30Logo.png create mode 100644 examples/commands/src-tauri/icons/Square310x310Logo.png create mode 100644 examples/commands/src-tauri/icons/Square44x44Logo.png create mode 100644 examples/commands/src-tauri/icons/Square71x71Logo.png create mode 100644 examples/commands/src-tauri/icons/Square89x89Logo.png create mode 100644 examples/commands/src-tauri/icons/StoreLogo.png create mode 100644 examples/commands/src-tauri/icons/icon.icns create mode 100644 examples/commands/src-tauri/icons/icon.ico create mode 100644 examples/commands/src-tauri/icons/icon.png create mode 100644 examples/commands/src-tauri/src/main.rs create mode 100644 examples/commands/src-tauri/tauri.conf.json diff --git a/.changes/app-state.md b/.changes/app-state.md new file mode 100644 index 000000000..cee7282c1 --- /dev/null +++ b/.changes/app-state.md @@ -0,0 +1,5 @@ +--- +"tauri": patch +--- + +Adds `manage` API to the `Builder` struct, which manages app state. diff --git a/.changes/command-state.md b/.changes/command-state.md new file mode 100644 index 000000000..9ed0ae453 --- /dev/null +++ b/.changes/command-state.md @@ -0,0 +1,5 @@ +--- +"tauri-macros": patch +--- + +Adds support to command state, triggered when a command argument is `arg: State<'_, StateType>`. diff --git a/.changes/plugin-refactor.md b/.changes/plugin-refactor.md new file mode 100644 index 000000000..8b7f88927 --- /dev/null +++ b/.changes/plugin-refactor.md @@ -0,0 +1,7 @@ +--- +"tauri": patch +--- + +Refactored the `Plugin` trait `initialize` and `extend_api` signatures. +`initialize` now takes the `App` as first argument, and `extend_api` takes a `InvokeResolver` as last argument. +This adds support to managed state on plugins. diff --git a/.changes/remove-with-window.md b/.changes/remove-with-window.md new file mode 100644 index 000000000..2aff7c756 --- /dev/null +++ b/.changes/remove-with-window.md @@ -0,0 +1,5 @@ +--- +"tauri": patch +--- + +Removes the `with_window` attribute on the `command` macro. Tauri now infers it using the `FromCommand` trait. diff --git a/Cargo.toml b/Cargo.toml index 9b852ff21..9dc3e7bd9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,6 +11,7 @@ members = [ "examples/api/src-tauri", "examples/helloworld/src-tauri", "examples/multiwindow/src-tauri", + "examples/commands/src-tauri", # used to build updater artifacts "examples/updater/src-tauri", ] diff --git a/core/tauri-macros/src/command.rs b/core/tauri-macros/src/command.rs index 903d34dab..bdc6a138a 100644 --- a/core/tauri-macros/src/command.rs +++ b/core/tauri-macros/src/command.rs @@ -3,28 +3,35 @@ // SPDX-License-Identifier: MIT use proc_macro2::TokenStream; -use quote::{format_ident, quote}; +use quote::{format_ident, quote, TokenStreamExt}; use syn::{ - parse::Parser, punctuated::Punctuated, FnArg, Ident, ItemFn, Meta, NestedMeta, Pat, Path, - ReturnType, Token, Type, + parse::Parser, punctuated::Punctuated, FnArg, Ident, ItemFn, Pat, Path, ReturnType, Token, Type, + Visibility, }; -pub fn generate_command(attrs: Vec, function: ItemFn) -> TokenStream { - // Check if "with_window" attr was passed to macro - let with_window = attrs.iter().any(|a| { - if let NestedMeta::Meta(Meta::Path(path)) = a { - path - .get_ident() - .map(|i| *i == "with_window") - .unwrap_or(false) - } else { - false - } - }); +fn fn_wrapper(function: &ItemFn) -> (&Visibility, Ident) { + ( + &function.vis, + format_ident!("{}_wrapper", function.sig.ident), + ) +} +fn err(function: ItemFn, error_message: &str) -> TokenStream { + let (vis, wrap) = fn_wrapper(&function); + quote! { + #function + + #vis fn #wrap(_message: ::tauri::InvokeMessage

) { + compile_error!(#error_message); + unimplemented!() + } + } +} + +pub fn generate_command(function: ItemFn) -> TokenStream { let fn_name = function.sig.ident.clone(); let fn_name_str = fn_name.to_string(); - let fn_wrapper = format_ident!("{}_wrapper", fn_name); + let (vis, fn_wrapper) = fn_wrapper(&function); let returns_result = match function.sig.output { ReturnType::Type(_, ref ty) => match &**ty { Type::Path(type_path) => { @@ -40,40 +47,45 @@ pub fn generate_command(attrs: Vec, function: ItemFn) -> TokenStream ReturnType::Default => false, }; - // Split function args into names and types - let (mut names, mut types): (Vec, Vec) = function - .sig - .inputs - .iter() - .map(|param| { - let mut arg_name = None; - let mut arg_type = None; - if let FnArg::Typed(arg) = param { - if let Pat::Ident(ident) = arg.pat.as_ref() { - arg_name = Some(ident.ident.clone()); - } - if let Type::Path(path) = arg.ty.as_ref() { - arg_type = Some(path.path.clone()); - } - } - ( - arg_name.clone().unwrap(), - arg_type.unwrap_or_else(|| panic!("Invalid type for arg \"{}\"", arg_name.unwrap())), - ) - }) - .unzip(); + let mut invoke_arg_names: Vec = Default::default(); + let mut invoke_arg_types: Vec = Default::default(); + let mut invoke_args: TokenStream = Default::default(); - let window_arg_maybe = match types.first() { - Some(_) if with_window => { - // Remove window arg from list so it isn't expected as arg from JS - types.drain(0..1); - names.drain(0..1); - // Tell wrapper to pass `window` to original function - quote!(_window,) + for param in &function.sig.inputs { + let mut arg_name = None; + let mut arg_type = None; + if let FnArg::Typed(arg) = param { + if let Pat::Ident(ident) = arg.pat.as_ref() { + arg_name = Some(ident.ident.clone()); + } + if let Type::Path(path) = arg.ty.as_ref() { + arg_type = Some(path.path.clone()); + } } - // Tell wrapper not to pass `window` to original function - _ => quote!(), - }; + + let arg_name_ = arg_name.clone().unwrap(); + let arg_name_s = arg_name_.to_string(); + + let arg_type = match arg_type { + Some(arg_type) => arg_type, + None => { + return err( + function.clone(), + &format!("invalid type for arg: {}", arg_name_), + ) + } + }; + + invoke_args.append_all(quote! { + let #arg_name_ = match <#arg_type>::from_command(#fn_name_str, #arg_name_s, &message) { + Ok(value) => value, + Err(e) => return tauri::InvokeResponse::error(::tauri::Error::InvalidArgs(#fn_name_str, e).to_string()) + }; + }); + invoke_arg_names.push(arg_name_.clone()); + invoke_arg_types.push(arg_type); + } + let await_maybe = if function.sig.asyncness.is_some() { quote!(.await) } else { @@ -86,30 +98,23 @@ pub fn generate_command(attrs: Vec, function: ItemFn) -> TokenStream // note that all types must implement `serde::Serialize`. let return_value = if returns_result { quote! { - match #fn_name(#window_arg_maybe #(parsed_args.#names),*)#await_maybe { - Ok(value) => ::core::result::Result::Ok(value), - Err(e) => ::core::result::Result::Err(e), + match #fn_name(#(#invoke_arg_names),*)#await_maybe { + Ok(value) => ::core::result::Result::<_, ()>::Ok(value).into(), + Err(e) => ::core::result::Result::<(), _>::Err(e).into(), } } } else { - quote! { ::core::result::Result::<_, ()>::Ok(#fn_name(#window_arg_maybe #(parsed_args.#names),*)#await_maybe) } + quote! { ::core::result::Result::<_, ()>::Ok(#fn_name(#(#invoke_arg_names),*)#await_maybe).into() } }; quote! { #function - pub fn #fn_wrapper(message: ::tauri::InvokeMessage

) { - #[derive(::serde::Deserialize)] - #[serde(rename_all = "camelCase")] - struct ParsedArgs { - #(#names: #types),* - } - let _window = message.window(); - match ::serde_json::from_value::(message.payload()) { - Ok(parsed_args) => message.respond_async(async move { - #return_value - }), - Err(e) => message.reject(::tauri::Error::InvalidArgs(#fn_name_str, e).to_string()), - } + #vis fn #fn_wrapper(message: ::tauri::InvokeMessage

, resolver: ::tauri::InvokeResolver

) { + use ::tauri::command::FromCommand; + resolver.respond_async(async move { + #invoke_args + #return_value + }) } } } @@ -134,12 +139,12 @@ pub fn generate_handler(item: proc_macro::TokenStream) -> TokenStream { }); quote! { - move |message| { + move |message, resolver| { let cmd = message.command().to_string(); match cmd.as_str() { - #(stringify!(#fn_names) => #fn_wrappers(message),)* + #(stringify!(#fn_names) => #fn_wrappers(message, resolver),)* _ => { - message.reject(format!("command {} not found", cmd)) + resolver.reject(format!("command {} not found", cmd)) }, } } diff --git a/core/tauri-macros/src/lib.rs b/core/tauri-macros/src/lib.rs index f1cae1b6c..8893cc7a3 100644 --- a/core/tauri-macros/src/lib.rs +++ b/core/tauri-macros/src/lib.rs @@ -5,7 +5,7 @@ extern crate proc_macro; use crate::context::ContextItems; use proc_macro::TokenStream; -use syn::{parse_macro_input, AttributeArgs, ItemFn}; +use syn::{parse_macro_input, ItemFn}; mod command; @@ -13,10 +13,9 @@ mod command; mod context; #[proc_macro_attribute] -pub fn command(attrs: TokenStream, item: TokenStream) -> TokenStream { +pub fn command(_attrs: TokenStream, item: TokenStream) -> TokenStream { let function = parse_macro_input!(item as ItemFn); - let attrs = parse_macro_input!(attrs as AttributeArgs); - let gen = command::generate_command(attrs, function); + let gen = command::generate_command(function); gen.into() } diff --git a/core/tauri/Cargo.toml b/core/tauri/Cargo.toml index 9d954e890..fff24f8c9 100644 --- a/core/tauri/Cargo.toml +++ b/core/tauri/Cargo.toml @@ -48,6 +48,7 @@ shared_child = "0.3" os_pipe = "0.9" minisign-verify = "0.1.8" image = "0.23" +state = "0.4" [build-dependencies] cfg_aliases = "0.1.1" diff --git a/core/tauri/src/command.rs b/core/tauri/src/command.rs new file mode 100644 index 000000000..9550a1a1b --- /dev/null +++ b/core/tauri/src/command.rs @@ -0,0 +1,300 @@ +// Copyright 2019-2021 Tauri Programme within The Commons Conservancy +// SPDX-License-Identifier: Apache-2.0 +// SPDX-License-Identifier: MIT + +//! Useful items for custom commands. + +use crate::{InvokeMessage, Params}; +use serde::de::Visitor; +use serde::Deserializer; + +/// A [`Deserializer`] wrapper around [`Value::get`]. +/// +/// If the key doesn't exist, an error will be returned if the deserialized type is not expecting +/// an optional item. If the key does exist, the value will be called with [`Value`]'s +/// [`Deserializer`] implementation. +struct KeyedValue<'de> { + command: &'de str, + key: &'de str, + value: &'de serde_json::Value, +} + +macro_rules! kv_value { + ($s:ident) => {{ + use serde::de::Error; + + match $s.value.get($s.key) { + Some(value) => value, + None => { + return Err(serde_json::Error::custom(format!( + "command {} missing required key `{}`", + $s.command, $s.key + ))) + } + } + }}; +} + +impl<'de> Deserializer<'de> for KeyedValue<'de> { + type Error = serde_json::Error; + + fn deserialize_any(self, visitor: V) -> Result + where + V: Visitor<'de>, + { + kv_value!(self).deserialize_any(visitor) + } + + fn deserialize_bool(self, visitor: V) -> Result + where + V: Visitor<'de>, + { + kv_value!(self).deserialize_bool(visitor) + } + + fn deserialize_i8(self, visitor: V) -> Result + where + V: Visitor<'de>, + { + kv_value!(self).deserialize_i8(visitor) + } + + fn deserialize_i16(self, visitor: V) -> Result + where + V: Visitor<'de>, + { + kv_value!(self).deserialize_i16(visitor) + } + + fn deserialize_i32(self, visitor: V) -> Result + where + V: Visitor<'de>, + { + kv_value!(self).deserialize_i32(visitor) + } + + fn deserialize_i64(self, visitor: V) -> Result + where + V: Visitor<'de>, + { + kv_value!(self).deserialize_i64(visitor) + } + + fn deserialize_u8(self, visitor: V) -> Result + where + V: Visitor<'de>, + { + kv_value!(self).deserialize_u8(visitor) + } + + fn deserialize_u16(self, visitor: V) -> Result + where + V: Visitor<'de>, + { + kv_value!(self).deserialize_u16(visitor) + } + + fn deserialize_u32(self, visitor: V) -> Result + where + V: Visitor<'de>, + { + kv_value!(self).deserialize_u32(visitor) + } + + fn deserialize_u64(self, visitor: V) -> Result + where + V: Visitor<'de>, + { + kv_value!(self).deserialize_u64(visitor) + } + + fn deserialize_f32(self, visitor: V) -> Result + where + V: Visitor<'de>, + { + kv_value!(self).deserialize_f32(visitor) + } + + fn deserialize_f64(self, visitor: V) -> Result + where + V: Visitor<'de>, + { + kv_value!(self).deserialize_f64(visitor) + } + + fn deserialize_char(self, visitor: V) -> Result + where + V: Visitor<'de>, + { + kv_value!(self).deserialize_char(visitor) + } + + fn deserialize_str(self, visitor: V) -> Result + where + V: Visitor<'de>, + { + kv_value!(self).deserialize_str(visitor) + } + + fn deserialize_string(self, visitor: V) -> Result + where + V: Visitor<'de>, + { + kv_value!(self).deserialize_string(visitor) + } + + fn deserialize_bytes(self, visitor: V) -> Result + where + V: Visitor<'de>, + { + kv_value!(self).deserialize_bytes(visitor) + } + + fn deserialize_byte_buf(self, visitor: V) -> Result + where + V: Visitor<'de>, + { + kv_value!(self).deserialize_byte_buf(visitor) + } + + fn deserialize_option(self, visitor: V) -> Result + where + V: Visitor<'de>, + { + match self.value.get(self.key) { + Some(value) => value.deserialize_option(visitor), + None => visitor.visit_none(), + } + } + + fn deserialize_unit(self, visitor: V) -> Result + where + V: Visitor<'de>, + { + kv_value!(self).deserialize_unit(visitor) + } + + fn deserialize_unit_struct( + self, + name: &'static str, + visitor: V, + ) -> Result + where + V: Visitor<'de>, + { + kv_value!(self).deserialize_unit_struct(name, visitor) + } + + fn deserialize_newtype_struct( + self, + name: &'static str, + visitor: V, + ) -> Result + where + V: Visitor<'de>, + { + kv_value!(self).deserialize_newtype_struct(name, visitor) + } + + fn deserialize_seq(self, visitor: V) -> Result + where + V: Visitor<'de>, + { + kv_value!(self).deserialize_seq(visitor) + } + + fn deserialize_tuple(self, len: usize, visitor: V) -> Result + where + V: Visitor<'de>, + { + kv_value!(self).deserialize_tuple(len, visitor) + } + + fn deserialize_tuple_struct( + self, + name: &'static str, + len: usize, + visitor: V, + ) -> Result + where + V: Visitor<'de>, + { + kv_value!(self).deserialize_tuple_struct(name, len, visitor) + } + + fn deserialize_map(self, visitor: V) -> Result + where + V: Visitor<'de>, + { + kv_value!(self).deserialize_map(visitor) + } + + fn deserialize_struct( + self, + name: &'static str, + fields: &'static [&'static str], + visitor: V, + ) -> Result + where + V: Visitor<'de>, + { + kv_value!(self).deserialize_struct(name, fields, visitor) + } + + fn deserialize_enum( + self, + name: &'static str, + variants: &'static [&'static str], + visitor: V, + ) -> Result + where + V: Visitor<'de>, + { + kv_value!(self).deserialize_enum(name, variants, visitor) + } + + fn deserialize_identifier(self, visitor: V) -> Result + where + V: Visitor<'de>, + { + kv_value!(self).deserialize_identifier(visitor) + } + + fn deserialize_ignored_any(self, visitor: V) -> Result + where + V: Visitor<'de>, + { + kv_value!(self).deserialize_ignored_any(visitor) + } +} + +/// Trait implemented by command arguments to derive a value from a [`InvokeMessage`]. +/// [`tauri::Window`], [`tauri::State`] and types that implements [`Deserialize`] automatically implements this trait. +pub trait FromCommand<'de, P: Params>: Sized { + /// Derives an instance of `Self` from the [`InvokeMessage`]. + /// If the derivation fails, the corresponding message will be rejected using [`InvokeMessage#reject`]. + /// + /// # Arguments + /// - `command`: the command value passed to invoke, e.g. `initialize` on `invoke('initialize', {})`. + /// - `key`: The name of the variable in the command handler, e.g. `value` on `#[command] fn handler(value: u64)` + /// - `message`: The [`InvokeMessage`] instance. + fn from_command( + command: &'de str, + key: &'de str, + message: &'de InvokeMessage

, + ) -> ::core::result::Result; +} + +impl<'de, D: serde::Deserialize<'de>, P: Params> FromCommand<'de, P> for D { + fn from_command( + command: &'de str, + key: &'de str, + message: &'de InvokeMessage

, + ) -> ::core::result::Result { + D::deserialize(KeyedValue { + command, + key, + value: &message.payload, + }) + } +} diff --git a/core/tauri/src/endpoints.rs b/core/tauri/src/endpoints.rs index c0321f1a1..bd6cef097 100644 --- a/core/tauri/src/endpoints.rs +++ b/core/tauri/src/endpoints.rs @@ -4,8 +4,8 @@ use crate::{ api::{config::Config, PackageInfo}, - hooks::InvokeMessage, - Params, + hooks::{InvokeMessage, InvokeResolver}, + Params, Window, }; use serde::{Deserialize, Serialize}; use serde_json::Value as JsonValue; @@ -54,77 +54,106 @@ enum Module { } impl Module { - fn run(self, message: InvokeMessage, config: &Config, package_info: PackageInfo) { - let window = message.window(); + fn run( + self, + window: Window, + resolver: InvokeResolver, + config: &Config, + package_info: PackageInfo, + ) { match self { - Self::App(cmd) => message.respond_async(async move { + Self::App(cmd) => resolver.respond_async(async move { cmd .run(package_info) .and_then(|r| r.json) .map_err(|e| e.to_string()) + .into() }), - Self::Process(cmd) => message - .respond_async(async move { cmd.run().and_then(|r| r.json).map_err(|e| e.to_string()) }), - Self::Fs(cmd) => message - .respond_async(async move { cmd.run().and_then(|r| r.json).map_err(|e| e.to_string()) }), - Self::Window(cmd) => message.respond_async(async move { + Self::Process(cmd) => resolver.respond_async(async move { + cmd + .run() + .and_then(|r| r.json) + .map_err(|e| e.to_string()) + .into() + }), + Self::Fs(cmd) => resolver.respond_async(async move { + cmd + .run() + .and_then(|r| r.json) + .map_err(|e| e.to_string()) + .into() + }), + Self::Window(cmd) => resolver.respond_async(async move { cmd .run(window) .await .and_then(|r| r.json) .map_err(|e| e.to_string()) + .into() }), - Self::Shell(cmd) => message.respond_async(async move { + Self::Shell(cmd) => resolver.respond_async(async move { cmd .run(window) .and_then(|r| r.json) .map_err(|e| e.to_string()) + .into() }), - Self::Event(cmd) => message.respond_async(async move { + Self::Event(cmd) => resolver.respond_async(async move { cmd .run(window) .and_then(|r| r.json) .map_err(|e| e.to_string()) + .into() }), - Self::Internal(cmd) => message.respond_async(async move { + Self::Internal(cmd) => resolver.respond_async(async move { cmd .run(window) .and_then(|r| r.json) .map_err(|e| e.to_string()) + .into() + }), + Self::Dialog(cmd) => resolver.respond_async(async move { + cmd + .run() + .and_then(|r| r.json) + .map_err(|e| e.to_string()) + .into() }), - Self::Dialog(cmd) => message - .respond_async(async move { cmd.run().and_then(|r| r.json).map_err(|e| e.to_string()) }), Self::Cli(cmd) => { if let Some(cli_config) = config.tauri.cli.clone() { - message.respond_async(async move { + resolver.respond_async(async move { cmd .run(&cli_config) .and_then(|r| r.json) .map_err(|e| e.to_string()) + .into() }) } } Self::Notification(cmd) => { let identifier = config.tauri.bundle.identifier.clone(); - message.respond_async(async move { + resolver.respond_async(async move { cmd .run(identifier) .and_then(|r| r.json) .map_err(|e| e.to_string()) + .into() }) } - Self::Http(cmd) => message.respond_async(async move { + Self::Http(cmd) => resolver.respond_async(async move { cmd .run() .await .and_then(|r| r.json) .map_err(|e| e.to_string()) + .into() }), - Self::GlobalShortcut(cmd) => message.respond_async(async move { + Self::GlobalShortcut(cmd) => resolver.respond_async(async move { cmd .run(window) .and_then(|r| r.json) .map_err(|e| e.to_string()) + .into() }), } } @@ -133,15 +162,17 @@ impl Module { pub(crate) fn handle( module: String, message: InvokeMessage, + resolver: InvokeResolver, config: &Config, package_info: &PackageInfo, ) { - let mut payload = message.payload(); + let mut payload = message.payload; if let JsonValue::Object(ref mut obj) = payload { obj.insert("module".to_string(), JsonValue::String(module)); } + let window = message.window; match serde_json::from_value::(payload) { - Ok(module) => module.run(message, config, package_info.clone()), - Err(e) => message.reject(e.to_string()), + Ok(module) => module.run(window, resolver, config, package_info.clone()), + Err(e) => resolver.reject(e.to_string()), } } diff --git a/core/tauri/src/hooks.rs b/core/tauri/src/hooks.rs index 698f99af4..b3efcab57 100644 --- a/core/tauri/src/hooks.rs +++ b/core/tauri/src/hooks.rs @@ -5,16 +5,17 @@ use crate::{ api::rpc::{format_callback, format_callback_result}, runtime::app::App, - Params, Window, + Params, StateManager, Window, }; use serde::{Deserialize, Serialize}; -use std::future::Future; +use serde_json::Value as JsonValue; +use std::{future::Future, sync::Arc}; /// A closure that is run when the Tauri application is setting up. pub type SetupHook = Box) -> Result<(), Box> + Send>; /// A closure that is run everytime Tauri receives a message it doesn't explicitly handle. -pub type InvokeHandler = dyn Fn(InvokeMessage) + Send + Sync + 'static; +pub type InvokeHandler = dyn Fn(InvokeMessage, InvokeResolver) + Send + Sync + 'static; /// A closure that is run once every time a window is created and loaded. pub type OnPageLoad = dyn Fn(Window, PageLoadPayload) + Send + Sync + 'static; @@ -32,33 +33,174 @@ impl PageLoadPayload { } } -/// Payload from an invoke call. -#[derive(Debug, Deserialize)] -pub(crate) struct InvokePayload { - #[serde(rename = "__tauriModule")] - pub(crate) tauri_module: Option, +/// Response from a [`InvokeMessage`] passed to the [`InvokeResolver`]. +#[derive(Debug)] +pub enum InvokeResponse { + /// Resolve the promise. + Ok(JsonValue), + /// Reject the promise. + Err(JsonValue), +} + +impl From> for InvokeResponse { + fn from(result: Result) -> Self { + match result { + Result::Ok(t) => match serde_json::to_value(t) { + Ok(v) => Self::Ok(v), + Err(e) => Self::Err(JsonValue::String(e.to_string())), + }, + Result::Err(e) => Self::error(e), + } + } +} + +impl InvokeResponse { + #[doc(hidden)] + pub fn error(value: T) -> Self { + match serde_json::to_value(value) { + Ok(v) => Self::Err(v), + Err(e) => Self::Err(JsonValue::String(e.to_string())), + } + } +} + +/// Resolver of a invoke message. +pub struct InvokeResolver { + window: Window, + pub(crate) main_thread: bool, pub(crate) callback: String, pub(crate) error: String, - #[serde(rename = "mainThread", default)] - pub(crate) main_thread: bool, - #[serde(flatten)] - pub(crate) inner: serde_json::Value, +} + +/*impl Clone for InvokeResolver

{ + fn clone(&self) -> Self { + Self { + window: self.window.clone(), + main_thread: self.main_thread, + callback: self.callback.clone(), + error: self.error.clone(), + } + } +}*/ + +impl InvokeResolver { + pub(crate) fn new(window: Window, main_thread: bool, callback: String, error: String) -> Self { + Self { + window, + main_thread, + callback, + error, + } + } + + /// Reply to the invoke promise with an async task. + pub fn respond_async + Send + 'static>(self, task: F) { + if self.main_thread { + crate::async_runtime::block_on(async move { + Self::return_task(self.window, task, self.callback, self.error).await; + }); + } else { + crate::async_runtime::spawn(async move { + Self::return_task(self.window, task, self.callback, self.error).await; + }); + } + } + + /// Reply to the invoke promise running the given closure. + pub fn respond_closure InvokeResponse>(self, f: F) { + Self::return_closure(self.window, f, self.callback, self.error) + } + + /// Resolve the invoke promise with a value. + pub fn resolve(self, value: S) { + Self::return_result( + self.window, + Result::::Ok(value).into(), + self.callback, + self.error, + ) + } + + /// Reject the invoke promise with a value. + pub fn reject(self, value: S) { + Self::return_result( + self.window, + Result::<(), S>::Err(value).into(), + self.callback, + self.error, + ) + } + + /// Asynchronously executes the given task + /// and evaluates its Result to the JS promise described by the `success_callback` and `error_callback` function names. + /// + /// If the Result `is_ok()`, the callback will be the `success_callback` function name and the argument will be the Ok value. + /// If the Result `is_err()`, the callback will be the `error_callback` function name and the argument will be the Err value. + pub async fn return_task + Send + 'static>( + window: Window, + task: F, + success_callback: String, + error_callback: String, + ) { + let result = task.await; + Self::return_closure(window, || result, success_callback, error_callback) + } + + pub(crate) fn return_closure InvokeResponse>( + window: Window, + f: F, + success_callback: String, + error_callback: String, + ) { + Self::return_result(window, f(), success_callback, error_callback) + } + + pub(crate) fn return_result( + window: Window, + response: InvokeResponse, + success_callback: String, + error_callback: String, + ) { + let callback_string = match format_callback_result( + match response { + InvokeResponse::Ok(t) => std::result::Result::Ok(t), + InvokeResponse::Err(e) => std::result::Result::Err(e), + }, + success_callback, + error_callback.clone(), + ) { + Ok(callback_string) => callback_string, + Err(e) => format_callback(error_callback, &e.to_string()) + .expect("unable to serialize shortcut string to json"), + }; + + let _ = window.eval(&callback_string); + } } /// An invoke message. pub struct InvokeMessage { - window: Window, + /// The window that received the invoke message. + pub(crate) window: Window, + /// Application managed state. + pub(crate) state: Arc, + /// The RPC command. pub(crate) command: String, - - /// Allow our crate to access the payload without cloning it. - pub(crate) payload: InvokePayload, + /// The JSON argument passed on the invoke message. + pub(crate) payload: JsonValue, } impl InvokeMessage { /// Create an new [`InvokeMessage`] from a payload send to a window. - pub(crate) fn new(window: Window, command: String, payload: InvokePayload) -> Self { + pub(crate) fn new( + window: Window, + state: Arc, + command: String, + payload: JsonValue, + ) -> Self { Self { window, + state, command, payload, } @@ -69,102 +211,8 @@ impl InvokeMessage { &self.command } - /// The invoke payload. - pub fn payload(&self) -> serde_json::Value { - self.payload.inner.clone() - } - /// The window that received the invoke. pub fn window(&self) -> Window { self.window.clone() } - - /// Reply to the invoke promise with an async task. - pub fn respond_async< - T: Serialize, - Err: Serialize, - F: Future> + Send + 'static, - >( - self, - task: F, - ) { - if self.payload.main_thread { - crate::async_runtime::block_on(async move { - Self::return_task(self.window, task, self.payload.callback, self.payload.error).await; - }); - } else { - crate::async_runtime::spawn(async move { - Self::return_task(self.window, task, self.payload.callback, self.payload.error).await; - }); - } - } - - /// Reply to the invoke promise running the given closure. - pub fn respond_closure Result>(self, f: F) { - Self::return_closure(self.window, f, self.payload.callback, self.payload.error) - } - - /// Resolve the invoke promise with a value. - pub fn resolve(self, value: S) { - Self::return_result( - self.window, - Result::::Ok(value), - self.payload.callback, - self.payload.error, - ) - } - - /// Reject the invoke promise with a value. - pub fn reject(self, value: S) { - Self::return_result( - self.window, - Result::<(), S>::Err(value), - self.payload.callback, - self.payload.error, - ) - } - - /// Asynchronously executes the given task - /// and evaluates its Result to the JS promise described by the `success_callback` and `error_callback` function names. - /// - /// If the Result `is_ok()`, the callback will be the `success_callback` function name and the argument will be the Ok value. - /// If the Result `is_err()`, the callback will be the `error_callback` function name and the argument will be the Err value. - pub async fn return_task< - T: Serialize, - Err: Serialize, - F: std::future::Future> + Send + 'static, - >( - window: Window, - task: F, - success_callback: String, - error_callback: String, - ) { - let result = task.await; - Self::return_closure(window, || result, success_callback, error_callback) - } - - pub(crate) fn return_closure Result>( - window: Window, - f: F, - success_callback: String, - error_callback: String, - ) { - Self::return_result(window, f(), success_callback, error_callback) - } - - pub(crate) fn return_result( - window: Window, - result: Result, - success_callback: String, - error_callback: String, - ) { - let callback_string = - match format_callback_result(result, success_callback, error_callback.clone()) { - Ok(callback_string) => callback_string, - Err(e) => format_callback(error_callback, &e.to_string()) - .expect("unable to serialize shortcut string to json"), - }; - - let _ = window.eval(&callback_string); - } } diff --git a/core/tauri/src/lib.rs b/core/tauri/src/lib.rs index e40a6df6e..83ac2750f 100644 --- a/core/tauri/src/lib.rs +++ b/core/tauri/src/lib.rs @@ -18,6 +18,7 @@ pub use tauri_macros::{command, generate_handler}; pub mod api; /// Async runtime. pub mod async_runtime; +pub mod command; /// The Tauri API endpoints. mod endpoints; mod error; @@ -27,6 +28,7 @@ pub mod plugin; pub mod runtime; /// The Tauri-specific settings for your runtime e.g. notification permission status. pub mod settings; +mod state; #[cfg(feature = "updater")] pub mod updater; @@ -36,27 +38,32 @@ pub type Result = std::result::Result; /// A task to run on the main thread. pub type SyncTask = Box; -use crate::api::assets::Assets; -use crate::api::config::Config; -use crate::event::{Event, EventHandler}; -use crate::runtime::tag::{Tag, TagRef}; -use crate::runtime::window::PendingWindow; -use crate::runtime::{Dispatch, Runtime}; +use crate::{ + api::{assets::Assets, config::Config}, + event::{Event, EventHandler}, + runtime::{ + tag::{Tag, TagRef}, + window::PendingWindow, + Dispatch, Runtime, + }, +}; use serde::Serialize; -use std::collections::HashMap; -use std::path::PathBuf; +use std::{borrow::Borrow, collections::HashMap, path::PathBuf}; // Export types likely to be used by the application. pub use { - api::config::WindowUrl, - hooks::{InvokeHandler, InvokeMessage, OnPageLoad, PageLoadPayload, SetupHook}, - runtime::app::{App, Builder}, - runtime::flavors::wry::Wry, - runtime::webview::{WebviewAttributes, WindowBuilder}, - runtime::window::export::Window, + self::api::config::WindowUrl, + self::hooks::{ + InvokeHandler, InvokeMessage, InvokeResolver, InvokeResponse, OnPageLoad, PageLoadPayload, + SetupHook, + }, + self::runtime::app::{App, Builder}, + self::runtime::flavors::wry::Wry, + self::runtime::webview::{WebviewAttributes, WindowBuilder}, + self::runtime::window::export::Window, + self::state::{State, StateManager}, }; -use std::borrow::Borrow; /// Reads the config file at compile time and generates a [`Context`] based on its content. /// /// The default config file path is a `tauri.conf.json` file inside the Cargo manifest directory of @@ -223,6 +230,23 @@ pub trait Manager: sealed::ManagerBase

{ fn windows(&self) -> HashMap> { self.manager().windows() } + + /// Add `state` to the state managed by the application. + /// See [`tauri::Builder#manage`] for instructions. + fn manage(&self, state: T) + where + T: Send + Sync + 'static, + { + self.manager().state().set(state); + } + + /// Gets the managed state for the type `T`. + fn state(&self) -> State<'_, T> + where + T: Send + Sync + 'static, + { + self.manager().inner.state.get() + } } /// Prevent implementation details from leaking out of the [`Manager`] and [`Params`] traits. diff --git a/core/tauri/src/plugin.rs b/core/tauri/src/plugin.rs index 1999b9079..e8c27fee6 100644 --- a/core/tauri/src/plugin.rs +++ b/core/tauri/src/plugin.rs @@ -6,8 +6,8 @@ use crate::{ api::config::PluginConfig, - hooks::{InvokeMessage, PageLoadPayload}, - Params, Window, + hooks::{InvokeMessage, InvokeResolver, PageLoadPayload}, + App, Params, Window, }; use serde_json::Value as JsonValue; use std::collections::HashMap; @@ -22,7 +22,7 @@ pub trait Plugin: Send { /// Initialize the plugin. #[allow(unused_variables)] - fn initialize(&mut self, config: JsonValue) -> Result<()> { + fn initialize(&mut self, app: &App, config: JsonValue) -> Result<()> { Ok(()) } @@ -45,7 +45,7 @@ pub trait Plugin: Send { /// Add invoke_handler API extension commands. #[allow(unused_variables)] - fn extend_api(&mut self, message: InvokeMessage) {} + fn extend_api(&mut self, message: InvokeMessage, resolver: InvokeResolver) {} } /// Plugin collection type. @@ -70,10 +70,13 @@ impl PluginStore { } /// Initializes all plugins in the store. - pub(crate) fn initialize(&mut self, config: &PluginConfig) -> crate::Result<()> { + pub(crate) fn initialize(&mut self, app: &App, config: &PluginConfig) -> crate::Result<()> { self.store.values_mut().try_for_each(|plugin| { plugin - .initialize(config.0.get(plugin.name()).cloned().unwrap_or_default()) + .initialize( + &app, + config.0.get(plugin.name()).cloned().unwrap_or_default(), + ) .map_err(|e| crate::Error::PluginInitialization(plugin.name().to_string(), e.to_string())) }) } @@ -105,7 +108,7 @@ impl PluginStore { .for_each(|plugin| plugin.on_page_load(window.clone(), payload.clone())) } - pub(crate) fn extend_api(&mut self, mut message: InvokeMessage) { + pub(crate) fn extend_api(&mut self, mut message: InvokeMessage, resolver: InvokeResolver) { let command = message.command.replace("plugin:", ""); let mut tokens = command.split('|'); // safe to unwrap: split always has a least one item @@ -116,9 +119,9 @@ impl PluginStore { .next() .map(|c| c.to_string()) .unwrap_or_else(String::new); - plugin.extend_api(message); + plugin.extend_api(message, resolver); } else { - message.reject(format!("plugin {} not found", target)); + resolver.reject(format!("plugin {} not found", target)); } } } diff --git a/core/tauri/src/runtime/app.rs b/core/tauri/src/runtime/app.rs index 6619c26d4..ce0ecd979 100644 --- a/core/tauri/src/runtime/app.rs +++ b/core/tauri/src/runtime/app.rs @@ -4,7 +4,7 @@ use crate::{ api::{assets::Assets, config::WindowUrl}, - hooks::{InvokeHandler, InvokeMessage, OnPageLoad, PageLoadPayload, SetupHook}, + hooks::{InvokeHandler, InvokeMessage, InvokeResolver, OnPageLoad, PageLoadPayload, SetupHook}, plugin::{Plugin, PluginStore}, runtime::{ flavors::wry::Wry, @@ -15,7 +15,7 @@ use crate::{ Dispatch, Runtime, }, sealed::{ManagerBase, RuntimeOrDispatch}, - Context, Manager, Params, Window, + Context, Manager, Params, StateManager, Window, }; use std::{collections::HashMap, sync::Arc}; @@ -126,6 +126,9 @@ where /// The webview protocols available to all windows. uri_scheme_protocols: HashMap>, + + /// App state. + state: StateManager, } impl Builder @@ -139,18 +142,20 @@ where pub fn new() -> Self { Self { setup: Box::new(|_| Ok(())), - invoke_handler: Box::new(|_| ()), + invoke_handler: Box::new(|_, _| ()), on_page_load: Box::new(|_, _| ()), pending_windows: Default::default(), plugins: PluginStore::default(), uri_scheme_protocols: Default::default(), + state: StateManager::new(), } } /// Defines the JS message handler callback. pub fn invoke_handler(mut self, invoke_handler: F) -> Self where - F: Fn(InvokeMessage>) + Send + Sync + 'static, + F: + Fn(InvokeMessage>, InvokeResolver>) + Send + Sync + 'static, { self.invoke_handler = Box::new(invoke_handler); self @@ -180,6 +185,58 @@ where self } + /// Add `state` to the state managed by the application. + /// + /// This method can be called any number of times as long as each call + /// refers to a different `T`. + /// + /// Managed state can be retrieved by any request handler via the + /// [`State`](crate::State) request guard. In particular, if a value of type `T` + /// is managed by Tauri, adding `State` to the list of arguments in a + /// request handler instructs Tauri to retrieve the managed value. + /// + /// # Panics + /// + /// Panics if state of type `T` is already being managed. + /// + /// # Example + /// + /// ```rust,ignore + /// use tauri::State; + /// + /// struct MyInt(isize); + /// struct MyString(String); + /// + /// #[tauri::command] + /// fn int_command(state: State<'_, MyInt>) -> String { + /// format!("The stateful int is: {}", state.0) + /// } + /// + /// #[tauri::command] + /// fn string_command<'r>(state: State<'r, MyString>) { + /// println!("state: {}", state.inner().0); + /// } + /// + /// fn main() { + /// tauri::Builder::default() + /// .manage(MyInt(10)) + /// .manage(MyString("Hello, managed state!".to_string())) + /// .run(tauri::generate_context!()) + /// .expect("error while running tauri application"); + /// } + /// ``` + pub fn manage(self, state: T) -> Self + where + T: Send + Sync + 'static, + { + let type_name = std::any::type_name::(); + if !self.state.set(state) { + panic!("state for type '{}' is already being managed", type_name); + } + + self + } + /// Creates a new webview. pub fn create_window(mut self, label: L, url: WindowUrl, setup: F) -> Self where @@ -237,6 +294,7 @@ where self.invoke_handler, self.on_page_load, self.uri_scheme_protocols, + self.state, ); // set up all the windows defined in the config @@ -254,13 +312,13 @@ where )); } - manager.initialize_plugins()?; - let mut app = App { runtime: R::new()?, manager, }; + app.manager.initialize_plugins(&app)?; + let pending_labels = self .pending_windows .iter() @@ -284,6 +342,7 @@ where app.run_updater(main_window); (self.setup)(&mut app).map_err(|e| crate::Error::Setup(e.to_string()))?; + app.runtime.run(); Ok(()) } diff --git a/core/tauri/src/runtime/manager.rs b/core/tauri/src/runtime/manager.rs index 16acdff90..679ac9b4e 100644 --- a/core/tauri/src/runtime/manager.rs +++ b/core/tauri/src/runtime/manager.rs @@ -2,7 +2,6 @@ // SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: MIT -use crate::runtime::tag::TagRef; use crate::{ api::{ assets::Assets, @@ -11,16 +10,19 @@ use crate::{ PackageInfo, }, event::{Event, EventHandler, Listeners}, - hooks::{InvokeHandler, InvokeMessage, InvokePayload, OnPageLoad, PageLoadPayload}, + hooks::{InvokeHandler, InvokeMessage, InvokeResolver, OnPageLoad, PageLoadPayload}, plugin::PluginStore, runtime::{ - tag::{tags_to_javascript_array, Tag, ToJsString}, - webview::{CustomProtocol, FileDropEvent, FileDropHandler, WebviewRpcHandler, WindowBuilder}, + tag::{tags_to_javascript_array, Tag, TagRef, ToJsString}, + webview::{ + CustomProtocol, FileDropEvent, FileDropHandler, InvokePayload, WebviewRpcHandler, + WindowBuilder, + }, window::{DetachedWindow, PendingWindow}, Icon, Runtime, }, sealed::ParamsBase, - Context, Params, Window, + App, Context, Params, StateManager, Window, }; use serde::Serialize; use serde_json::Value as JsonValue; @@ -52,6 +54,7 @@ pub struct InnerWindowManager { windows: Mutex>>, plugins: Mutex>, listeners: Listeners, + pub(crate) state: Arc, /// The JS message handler. invoke_handler: Box>, @@ -67,7 +70,7 @@ pub struct InnerWindowManager { salts: Mutex>, package_info: PackageInfo, /// The webview protocols protocols available to all windows. - uri_scheme_protocols: HashMap>, + uri_scheme_protocols: HashMap>, } /// A [Zero Sized Type] marker representing a full [`Params`]. @@ -119,13 +122,15 @@ impl WindowManager

{ plugins: PluginStore

, invoke_handler: Box>, on_page_load: Box>, - uri_scheme_protocols: HashMap>, + uri_scheme_protocols: HashMap>, + state: StateManager, ) -> Self { Self { inner: Arc::new(InnerWindowManager { windows: Mutex::default(), plugins: Mutex::new(plugins), listeners: Listeners::default(), + state: Arc::new(state), invoke_handler, on_page_load, config: context.config, @@ -144,6 +149,11 @@ impl WindowManager

{ self.inner.windows.lock().expect("poisoned window manager") } + /// State managed by the application. + pub(crate) fn state(&self) -> Arc { + self.inner.state.clone() + } + // setup content for dev-server #[cfg(dev)] fn get_url(&self) -> String { @@ -383,7 +393,7 @@ impl WindowManager

{ #[cfg(test)] mod test { use super::{Args, WindowManager}; - use crate::{generate_context, plugin::PluginStore, runtime::flavors::wry::Wry}; + use crate::{generate_context, plugin::PluginStore, runtime::flavors::wry::Wry, StateManager}; #[test] fn check_get_url() { @@ -391,9 +401,10 @@ mod test { let manager: WindowManager> = WindowManager::with_handlers( context, PluginStore::default(), - Box::new(|_| ()), + Box::new(|_, _| ()), Box::new(|_, _| ()), Default::default(), + StateManager::new(), ); #[cfg(custom_protocol)] @@ -405,9 +416,10 @@ mod test { } impl WindowManager

{ - pub fn run_invoke_handler(&self, message: InvokeMessage

) { - (self.inner.invoke_handler)(message); + pub fn run_invoke_handler(&self, message: InvokeMessage

, resolver: InvokeResolver

) { + (self.inner.invoke_handler)(message, resolver); } + pub fn run_on_page_load(&self, window: Window

, payload: PageLoadPayload) { (self.inner.on_page_load)(window.clone(), payload.clone()); self @@ -417,21 +429,23 @@ impl WindowManager

{ .expect("poisoned plugin store") .on_page_load(window, payload); } - pub fn extend_api(&self, message: InvokeMessage

) { + + pub fn extend_api(&self, message: InvokeMessage

, resolver: InvokeResolver

) { self .inner .plugins .lock() .expect("poisoned plugin store") - .extend_api(message); + .extend_api(message, resolver); } - pub fn initialize_plugins(&self) -> crate::Result<()> { + + pub fn initialize_plugins(&self, app: &App

) -> crate::Result<()> { self .inner .plugins .lock() .expect("poisoned plugin store") - .initialize(&self.inner.config.plugins) + .initialize(&app, &self.inner.config.plugins) } pub fn prepare_window( diff --git a/core/tauri/src/runtime/webview.rs b/core/tauri/src/runtime/webview.rs index 885770c6a..d4096e0e6 100644 --- a/core/tauri/src/runtime/webview.rs +++ b/core/tauri/src/runtime/webview.rs @@ -9,6 +9,7 @@ use crate::{ api::config::{WindowConfig, WindowUrl}, runtime::window::DetachedWindow, }; +use serde::Deserialize; use serde_json::Value as JsonValue; use std::{collections::HashMap, path::PathBuf}; @@ -166,3 +167,15 @@ pub(crate) type WebviewRpcHandler = Box, RpcRequest) /// File drop handler callback /// Return `true` in the callback to block the OS' default behavior of handling a file drop. pub(crate) type FileDropHandler = Box) -> bool + Send>; + +#[derive(Deserialize)] +pub(crate) struct InvokePayload { + #[serde(rename = "__tauriModule")] + pub(crate) tauri_module: Option, + pub(crate) callback: String, + pub(crate) error: String, + #[serde(rename = "mainThread", default)] + pub(crate) main_thread: bool, + #[serde(flatten)] + pub(crate) inner: JsonValue, +} diff --git a/core/tauri/src/runtime/window.rs b/core/tauri/src/runtime/window.rs index abfda4ac4..d04bd611f 100644 --- a/core/tauri/src/runtime/window.rs +++ b/core/tauri/src/runtime/window.rs @@ -7,10 +7,10 @@ use crate::{ api::config::WindowConfig, event::{Event, EventHandler}, - hooks::{InvokeMessage, InvokePayload, PageLoadPayload}, + hooks::{InvokeMessage, InvokeResolver, PageLoadPayload}, runtime::{ tag::ToJsString, - webview::{FileDropHandler, WebviewAttributes, WebviewRpcHandler}, + webview::{FileDropHandler, InvokePayload, WebviewAttributes, WebviewRpcHandler}, Dispatch, Runtime, }, sealed::{ManagerBase, RuntimeOrDispatch}, @@ -114,6 +114,7 @@ impl PartialEq for DetachedWindow { /// We want to export the runtime related window at the crate root, but not look like a re-export. pub(crate) mod export { use super::*; + use crate::command::FromCommand; use crate::runtime::{manager::WindowManager, tag::TagRef}; use std::borrow::Borrow; @@ -166,6 +167,16 @@ pub(crate) mod export { } } + impl<'de, P: Params> FromCommand<'de, P> for Window

{ + fn from_command( + _: &'de str, + _: &'de str, + message: &'de InvokeMessage

, + ) -> Result { + Ok(message.window()) + } + } + impl Window

{ /// Create a new window that is attached to the manager. pub(crate) fn new(manager: WindowManager

, window: DetachedWindow

) -> Self { @@ -186,14 +197,27 @@ pub(crate) mod export { manager.run_on_page_load(self, payload); } _ => { - let message = InvokeMessage::new(self, command.to_string(), payload); - if let Some(module) = &message.payload.tauri_module { + let message = InvokeMessage::new( + self.clone(), + manager.state(), + command.to_string(), + payload.inner, + ); + let resolver = + InvokeResolver::new(self, payload.main_thread, payload.callback, payload.error); + if let Some(module) = &payload.tauri_module { let module = module.to_string(); - crate::endpoints::handle(module, message, manager.config(), manager.package_info()); + crate::endpoints::handle( + module, + message, + resolver, + manager.config(), + manager.package_info(), + ); } else if command.starts_with("plugin:") { - manager.extend_api(message); + manager.extend_api(message, resolver); } else { - manager.run_invoke_handler(message); + manager.run_invoke_handler(message, resolver); } } } diff --git a/core/tauri/src/state.rs b/core/tauri/src/state.rs new file mode 100644 index 000000000..57a471034 --- /dev/null +++ b/core/tauri/src/state.rs @@ -0,0 +1,63 @@ +// Copyright 2019-2021 Tauri Programme within The Commons Conservancy +// SPDX-License-Identifier: Apache-2.0 +// SPDX-License-Identifier: MIT + +use crate::command::FromCommand; +use crate::{InvokeMessage, Params}; +use state::Container; + +/// A guard for a state value. +pub struct State<'r, T: Send + Sync + 'static>(&'r T); + +impl<'r, T: Send + Sync + 'static> State<'r, T> { + /// Retrieve a borrow to the underlying value with a lifetime of `'r`. + /// Using this method is typically unnecessary as `State` implements + /// [`Deref`] with a [`Deref::Target`] of `T`. + #[inline(always)] + pub fn inner(&self) -> &'r T { + self.0 + } +} + +impl std::ops::Deref for State<'_, T> { + type Target = T; + + #[inline(always)] + fn deref(&self) -> &T { + self.0 + } +} + +impl Clone for State<'_, T> { + fn clone(&self) -> Self { + State(self.0) + } +} + +impl<'r, 'de: 'r, T: Send + Sync + 'static, P: Params> FromCommand<'de, P> for State<'r, T> { + fn from_command( + _: &'de str, + _: &'de str, + message: &'de InvokeMessage

, + ) -> Result { + Ok(message.state.get()) + } +} + +/// The Tauri state manager. +pub struct StateManager(pub(crate) Container); + +impl StateManager { + pub(crate) fn new() -> Self { + Self(Container::new()) + } + + pub(crate) fn set(&self, state: T) -> bool { + self.0.set(state) + } + + /// Gets the state associated with the specified type. + pub fn get(&self) -> State<'_, T> { + State(self.0.get()) + } +} diff --git a/examples/api/src-tauri/src/cmd.rs b/examples/api/src-tauri/src/cmd.rs index 8bb335102..8cad4d1dc 100644 --- a/examples/api/src-tauri/src/cmd.rs +++ b/examples/api/src-tauri/src/cmd.rs @@ -11,12 +11,8 @@ pub struct RequestBody { name: String, } -#[command(with_window)] -pub fn log_operation( - _window: tauri::Window, - event: String, - payload: Option, -) { +#[command] +pub fn log_operation(event: String, payload: Option) { println!("{} {:?}", event, payload); } diff --git a/examples/commands/package.json b/examples/commands/package.json new file mode 100644 index 000000000..358134667 --- /dev/null +++ b/examples/commands/package.json @@ -0,0 +1,7 @@ +{ + "name": "commands", + "version": "1.0.0", + "scripts": { + "tauri": "node ../../tooling/cli.js/bin/tauri" + } +} \ No newline at end of file diff --git a/examples/commands/public/index.html b/examples/commands/public/index.html new file mode 100644 index 000000000..7c018b348 --- /dev/null +++ b/examples/commands/public/index.html @@ -0,0 +1,55 @@ + + + + + + + + Tauri + + + +

Tauri Commands

+
Response:
+
+ + + + \ No newline at end of file diff --git a/examples/commands/src-tauri/.gitignore b/examples/commands/src-tauri/.gitignore new file mode 100644 index 000000000..270a92d27 --- /dev/null +++ b/examples/commands/src-tauri/.gitignore @@ -0,0 +1,10 @@ +# Generated by Cargo +# will have compiled files and executables +/target/ +WixTools + +# These are backup files generated by rustfmt +**/*.rs.bk + +config.json +bundle.json diff --git a/examples/commands/src-tauri/.license_template b/examples/commands/src-tauri/.license_template new file mode 100644 index 000000000..860f08256 --- /dev/null +++ b/examples/commands/src-tauri/.license_template @@ -0,0 +1 @@ +../../../.license_template \ No newline at end of file diff --git a/examples/commands/src-tauri/Cargo.toml b/examples/commands/src-tauri/Cargo.toml new file mode 100644 index 000000000..26b8f93a1 --- /dev/null +++ b/examples/commands/src-tauri/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "commands" +version = "0.1.0" +description = "A simple Tauri Application showcasing the commands API" +edition = "2018" + +[build-dependencies] +tauri-build = { path = "../../../core/tauri-build", features = [ "codegen" ]} + +[dependencies] +serde_json = "1.0" +serde = { version = "1.0", features = [ "derive" ] } +tauri = { path = "../../../core/tauri", features =["api-all"]} + +[features] +default = [ "custom-protocol" ] +custom-protocol = [ "tauri/custom-protocol" ] diff --git a/examples/commands/src-tauri/build.rs b/examples/commands/src-tauri/build.rs new file mode 100644 index 000000000..a9dd7264f --- /dev/null +++ b/examples/commands/src-tauri/build.rs @@ -0,0 +1,7 @@ +// Copyright 2019-2021 Tauri Programme within The Commons Conservancy +// SPDX-License-Identifier: Apache-2.0 +// SPDX-License-Identifier: MIT + +fn main() { + tauri_build::build(); +} diff --git a/examples/commands/src-tauri/icons/128x128.png b/examples/commands/src-tauri/icons/128x128.png new file mode 100644 index 0000000000000000000000000000000000000000..f8d9962cc21930b871430f46b7dca842cb6c6f6d GIT binary patch literal 15920 zcmW-oby$<{_s6#}#^_Okgba`lLApmH-Q7rccgKek0YOk2rMskIgwi1(9iu@&Kstoq zzP~^A?0T;KvFEw(bDeYEulIf8HPjUFaVT*B0090QMOiKMcliH4Pzd_kFJUhs}IA12OpA- z7a&mwUDuoP^#{_@re(O7YgDQyYe84n>w7u(7jFmEjtmU?R+_Kc^#h3mPx99PorFv* z25q^EiM*hBpR6#L`B)$rN!|3VrTxbz)vDeA)mKWnhjglsRT7dSOT%;m zS3WQmg0&x^1WVzy>(SLGTaj%JrYTt5t(II_+Epi81;_n6CyLx=hX-J=D_$qo?z38O z`+f$3xr=(=;=>b{c@OE$zHQ5=(jet9ESEp)o1XKok8F8wZjxrD3#POV*ruk59xshiCf!cQQQt;s@mKn;!(tEy?!(lsp~( zi7r3ca5k3|F*>tAhK`6dpigFNy==i^5B+~8R6(Ew_ zmi|Ru0R#ktmPG)d6k`$~I1~}iY`VO(<_vOXA$(`oj*SA1%k{?_>E1AO7@`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&VbKG)iJzcWWIyHG?>pO^ z*RMAC_NF!Ca(BeZkvGI~VcCRy!GwJ!77HkfZSM-otjs+DMx!_TER+}AvI?#&{hfbf zuOfL_KQYNz^#ReE!wLEki+Qu=+L|D;M*yVY7$c>;bhN70hr~<393NV8V^m}v)RY-| zoNdtm;!8AYwy4qv2Ag5`rc&-us`1qs4*{V)v6M;nW*lrD*HhJh(Q)a}ETL#_g|6+r zx3;-qM^m&{;^C(+01oc1=V?xasZK#8Z7qChW{R87qcR0QSwQw)480^RhS(w+(IZe1 zbTf0;pjZrdY=x6)5@!6sO%2XUDIUZEHot$(VZ`6T&*Vu;rp{f>VgHGyTWN5P_ek~S3)&#lpgU}Z&)v9RSe}(6lKouy5=j6Srl67;T;K)S~Aa~ z$jW*X;|RMUE!^ejH6vWKkLRZT?f!Ku_~a;dhCMQw@Kbx|Zm8~lYoie-Q+YF(`4xMZ z7DJqR5aM@0@zgtqqQudK5Eu7{8d@5cw}y+w9TD#OuvPjW!{hK)LsF0oAt~~B(P#^A z!EDPv*suBv7Kq;rM6eKXa$M$HZnMQkm>23wy`eSwJ!AT&F7q8N&GG)}4z06R8#L$B zTfx*#F;Ir-*EF@`@h{;n$309NKhO64y~RW%^0%Haq$`@qgE$o5q9?%tZ{*ZuYoskA F{||SSwqO7N literal 0 HcmV?d00001 diff --git a/examples/commands/src-tauri/icons/128x128@2x.png b/examples/commands/src-tauri/icons/128x128@2x.png new file mode 100644 index 0000000000000000000000000000000000000000..44d26d04b6f60f5cc6ead44f15d30f80fd348b28 GIT binary patch literal 37546 zcmaf4`9DXCp&*t{EZhk+qQj#!|fAfRgO}#j+ z4+pe9ygGOA!_fZxeIkEECce%lr^s)gi=(wP@k7r{;PQ+f7wyOOUA>Ob zq?hs?dqK{yklbA0dH`Q?K^JFb>J^_eDt;ZD;~UI`Bf>m8wX+vbo;{f(6{w7(d+inS zg6-Q&s%+yCDvd(<6z}dKl@x#=VoRL~6`K`Vid#>{BnCc`)<)mI(#w2F%T}L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