ソースを参照

remove `generate_context!()`

Chip Reed 2 年 前
コミット
0ff7832f19
71 ファイル変更625 行追加557 行削除
  1. 14 1
      Cargo.toml
  2. 2 0
      core/tauri-build/Cargo.toml
  3. 3 3
      core/tauri-codegen/src/context.rs
  4. 1 1
      core/tauri-codegen/src/embedded_assets.rs
  5. 0 87
      core/tauri-macros/src/context.rs
  6. 0 17
      core/tauri-macros/src/lib.rs
  7. 2 11
      core/tauri-runtime/src/lib.rs
  8. 10 1
      core/tauri-utils/Cargo.toml
  9. 27 25
      core/tauri-utils/src/config.rs
  10. 257 1
      core/tauri-utils/src/lib.rs
  11. 50 0
      core/tauri-utils/src/pattern/mod.rs
  12. 3 41
      core/tauri/Cargo.toml
  13. 54 14
      core/tauri/src/app.rs
  14. 3 0
      core/tauri/src/error.rs
  15. 14 253
      core/tauri/src/lib.rs
  16. 2 2
      core/tauri/src/manager.rs
  17. 1 49
      core/tauri/src/pattern.rs
  18. 8 2
      core/tauri/src/updater/mod.rs
  19. 0 1
      core/tauri/test/fixture/config.json
  20. BIN
      core/tauri/test/fixture/src-tauri/icons/icon.ico~dev
  21. 0 0
      core/tauri/test/fixture/test.txt
  22. 1 0
      core/tests/app-updater/Cargo.toml
  23. 1 1
      core/tests/app-updater/src/main.rs
  24. 11 0
      core/tests/tauri-codegen-test/Cargo.toml
  25. 3 0
      core/tests/tauri-codegen-test/build.rs
  26. 0 0
      core/tests/tauri-codegen-test/dist/index.html
  27. 0 0
      core/tests/tauri-codegen-test/icons/icon.ico
  28. 0 0
      core/tests/tauri-codegen-test/icons/icon.png
  29. 5 0
      core/tests/tauri-codegen-test/src/lib.rs
  30. 3 3
      core/tests/tauri-codegen-test/tauri.conf.json
  31. 12 0
      examples/commands/Cargo.toml
  32. 3 0
      examples/commands/build.rs
  33. 0 0
      examples/commands/src/commands.rs
  34. 1 3
      examples/commands/src/main.rs
  35. 11 0
      examples/helloworld/Cargo.toml
  36. 3 0
      examples/helloworld/build.rs
  37. 1 3
      examples/helloworld/src/main.rs
  38. 11 0
      examples/isolation/Cargo.toml
  39. 3 0
      examples/isolation/build.rs
  40. 1 9
      examples/isolation/src/main.rs
  41. 11 0
      examples/multiwindow/Cargo.toml
  42. 3 0
      examples/multiwindow/build.rs
  43. 1 3
      examples/multiwindow/src/main.rs
  44. 11 0
      examples/navigation/Cargo.toml
  45. 3 0
      examples/navigation/build.rs
  46. 1 3
      examples/navigation/src/main.rs
  47. 11 0
      examples/parent-window/Cargo.toml
  48. 3 0
      examples/parent-window/build.rs
  49. 1 3
      examples/parent-window/src/main.rs
  50. 1 1
      examples/resources/src-tauri/src/main.rs
  51. 1 1
      examples/sidecar/src-tauri/src/main.rs
  52. 11 0
      examples/splashscreen/Cargo.toml
  53. 3 0
      examples/splashscreen/build.rs
  54. 1 1
      examples/splashscreen/src/main.rs
  55. 11 0
      examples/state/Cargo.toml
  56. 3 0
      examples/state/build.rs
  57. 1 3
      examples/state/src/main.rs
  58. 12 0
      examples/streaming/Cargo.toml
  59. 3 0
      examples/streaming/build.rs
  60. 1 3
      examples/streaming/src/main.rs
  61. 1 1
      examples/tauri-dynamic-lib/src-tauri/src/lib.rs
  62. 1 1
      examples/updater/src-tauri/src/main.rs
  63. 1 1
      examples/web/core/tauri/src/main.rs
  64. 1 1
      examples/workspace/src-tauri/src/main.rs
  65. 1 1
      tooling/bench/tests/cpu_intensive/src-tauri/src/main.rs
  66. 1 1
      tooling/bench/tests/files_transfer/src-tauri/src/main.rs
  67. 1 1
      tooling/bench/tests/helloworld/src-tauri/src/main.rs
  68. 1 1
      tooling/cli/node/test/jest/fixtures/app/src-tauri/src/main.rs
  69. 1 1
      tooling/cli/templates/app/src-tauri/src/lib.rs
  70. 1 1
      tooling/cli/templates/plugin/__example-api/tauri-app/src-tauri/src/main.rs
  71. 1 1
      tooling/cli/templates/plugin/__example-basic/vanilla/src-tauri/src/main.rs

+ 14 - 1
Cargo.toml

@@ -13,10 +13,23 @@ members = [
   # integration tests
   "core/tests/restart",
   "core/tests/app-updater",
+  "core/tests/tauri-codegen-test",
+
+  # examples that only require Cargo
+  "examples/commands",
+  "examples/helloworld",
+  "examples/isolation",
+  "examples/multiwindow",
+  "examples/navigation",
+  "examples/parent-window",
+  "examples/splashscreen",
+  "examples/state",
+  "examples/streaming",
+  #"examples/tauri-dynamic-lib",
 ]
 
 exclude = [
-  # examples that can be compiled with the tauri CLI
+  # examples that require NodeJS and/or NPM
   "examples/api/src-tauri",
   "examples/updater/src-tauri",
   "examples/resources/src-tauri",

+ 2 - 0
core/tauri-build/Cargo.toml

@@ -30,6 +30,8 @@ walkdir = "2"
 filetime = "0.2"
 tauri-winres = "0.1"
 semver = "1"
+syn = "2"
+prettyplease = "0.2"
 
 [target."cfg(target_os = \"macos\")".dependencies]
 swift-rs = { version = "1.0.4", features = [ "build" ] }

+ 3 - 3
core/tauri-codegen/src/context.rs

@@ -371,7 +371,7 @@ pub fn context_codegen(data: ContextData) -> Result<TokenStream, EmbeddedAssetsE
       .expect("failed to write Info.plist");
 
     let info_plist_path = out_path.display().to_string();
-    quote!(::tauri::embed_plist::embed_info_plist!(#info_plist_path))
+    quote!(::tauri_utils::embed_plist::embed_info_plist!(#info_plist_path);)
   } else {
     quote!()
   };
@@ -414,13 +414,13 @@ pub fn context_codegen(data: ContextData) -> Result<TokenStream, EmbeddedAssetsE
         assets: ::std::sync::Arc::new(#assets),
         schema: #schema.into(),
         key: #key.into(),
-        crypto_keys: std::boxed::Box::new(::tauri::utils::pattern::isolation::Keys::new().expect("unable to generate cryptographically secure keys for Tauri \"Isolation\" Pattern")),
+        crypto_keys: std::boxed::Box::new(::tauri_utils::pattern::isolation::Keys::new().expect("unable to generate cryptographically secure keys for Tauri \"Isolation\" Pattern")),
       })
     }
   };
 
   Ok(quote!({
-    #info_plist;
+    #info_plist
     #[allow(unused_mut, clippy::let_and_return)]
     let mut context = #root::Context::new(
       #config,

+ 1 - 1
core/tauri-codegen/src/embedded_assets.rs

@@ -434,7 +434,7 @@ impl ToTokens for EmbeddedAssets {
     // we expect phf related items to be in path when generating the path code
     tokens.append_all(quote! {{
         #[allow(unused_imports)]
-        use ::tauri::utils::assets::{CspHash, EmbeddedAssets, phf, phf::phf_map};
+        use ::tauri_utils::assets::{CspHash, EmbeddedAssets, phf, phf::phf_map};
         EmbeddedAssets::new(phf_map! { #assets }, &[#global_hashes], phf_map! { #html_hashes })
     }});
   }

+ 0 - 87
core/tauri-macros/src/context.rs

@@ -1,87 +0,0 @@
-// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
-// SPDX-License-Identifier: Apache-2.0
-// SPDX-License-Identifier: MIT
-
-use proc_macro2::{Ident, Span, TokenStream};
-use quote::{quote, ToTokens};
-use std::{env::VarError, path::PathBuf};
-use syn::{
-  parse::{Parse, ParseBuffer},
-  punctuated::Punctuated,
-  LitStr, PathArguments, PathSegment, Token,
-};
-use tauri_codegen::{context_codegen, get_config, ContextData};
-use tauri_utils::config::parse::does_supported_file_name_exist;
-
-pub(crate) struct ContextItems {
-  config_file: PathBuf,
-  root: syn::Path,
-}
-
-impl Parse for ContextItems {
-  fn parse(input: &ParseBuffer<'_>) -> syn::parse::Result<Self> {
-    let config_file = if input.is_empty() {
-      std::env::var("CARGO_MANIFEST_DIR").map(|m| PathBuf::from(m).join("tauri.conf.json"))
-    } else {
-      let raw: LitStr = input.parse()?;
-      let path = PathBuf::from(raw.value());
-      if path.is_relative() {
-        std::env::var("CARGO_MANIFEST_DIR").map(|m| PathBuf::from(m).join(path))
-      } else {
-        Ok(path)
-      }
-    }
-    .map_err(|error| match error {
-      VarError::NotPresent => "no CARGO_MANIFEST_DIR env var, this should be set by cargo".into(),
-      VarError::NotUnicode(_) => "CARGO_MANIFEST_DIR env var contained invalid utf8".into(),
-    })
-    .and_then(|path| {
-      if does_supported_file_name_exist(&path) {
-        Ok(path)
-      } else {
-        Err(format!(
-          "no file at path {} exists, expected tauri config file",
-          path.display()
-        ))
-      }
-    })
-    .map_err(|e| input.error(e))?;
-
-    let context_path = if input.is_empty() {
-      let mut segments = Punctuated::new();
-      segments.push(PathSegment {
-        ident: Ident::new("tauri", Span::call_site()),
-        arguments: PathArguments::None,
-      });
-      syn::Path {
-        leading_colon: Some(Token![::](Span::call_site())),
-        segments,
-      }
-    } else {
-      let _: Token![,] = input.parse()?;
-      input.call(syn::Path::parse_mod_style)?
-    };
-
-    Ok(Self {
-      config_file,
-      root: context_path,
-    })
-  }
-}
-
-pub(crate) fn generate_context(context: ContextItems) -> TokenStream {
-  let context = get_config(&context.config_file)
-    .map_err(|e| e.to_string())
-    .map(|(config, config_parent)| ContextData {
-      dev: cfg!(not(feature = "custom-protocol")),
-      config,
-      config_parent,
-      root: context.root.to_token_stream(),
-    })
-    .and_then(|data| context_codegen(data).map_err(|e| e.to_string()));
-
-  match context {
-    Ok(code) => code,
-    Err(error) => quote!(compile_error!(#error)),
-  }
-}

+ 0 - 17
core/tauri-macros/src/lib.rs

@@ -2,7 +2,6 @@
 // SPDX-License-Identifier: Apache-2.0
 // SPDX-License-Identifier: MIT
 
-use crate::context::ContextItems;
 use proc_macro::TokenStream;
 use syn::{parse_macro_input, DeriveInput, ItemFn};
 
@@ -11,9 +10,6 @@ mod command_module;
 mod mobile;
 mod runtime;
 
-#[macro_use]
-mod context;
-
 /// Mark a function as a command handler. It creates a wrapper function with the necessary glue code.
 ///
 /// # Stability
@@ -56,19 +52,6 @@ pub fn generate_handler(item: TokenStream) -> TokenStream {
   parse_macro_input!(item as command::Handler).into()
 }
 
-/// Reads a Tauri config file and generates a `::tauri::Context` based on the content.
-///
-/// # Stability
-/// The output of this macro is managed internally by Tauri,
-/// and should not be accessed directly on normal applications.
-/// It may have breaking changes in the future.
-#[proc_macro]
-pub fn generate_context(items: TokenStream) -> TokenStream {
-  // this macro is exported from the context module
-  let path = parse_macro_input!(items as ContextItems);
-  context::generate_context(path).into()
-}
-
 /// Adds the default type for the last parameter (assumed to be runtime) for a specific feature.
 ///
 /// e.g. To default the runtime generic to type `crate::Wry` when the `wry` feature is enabled, the

+ 2 - 11
core/tauri-runtime/src/lib.rs

@@ -35,6 +35,8 @@ use crate::http::{
   InvalidUri,
 };
 
+pub use tauri_utils::RawIcon as Icon;
+
 #[cfg(all(desktop, feature = "system-tray"))]
 use std::fmt;
 
@@ -267,17 +269,6 @@ pub enum Error {
 /// Result type.
 pub type Result<T> = std::result::Result<T, Error>;
 
-/// Window icon.
-#[derive(Debug, Clone)]
-pub struct Icon {
-  /// RGBA bytes of the icon.
-  pub rgba: Vec<u8>,
-  /// Icon width.
-  pub width: u32,
-  /// Icon height.
-  pub height: u32,
-}
-
 /// A type that can be used as an user event.
 pub trait UserEvent: Debug + Clone + Send + 'static {}
 

+ 10 - 1
core/tauri-utils/Cargo.toml

@@ -35,11 +35,16 @@ glob = { version = "0.3", optional = true }
 walkdir = { version = "2", optional = true }
 memchr = "2"
 semver = "1"
-infer = "0.12"
+infer = "0.13"
+png = { version = "0.17", optional = true }
+ico = { version = "0.2.0", optional = true }
 
 [target."cfg(target_os = \"linux\")".dependencies]
 heck = "0.4"
 
+[target."cfg(target_os = \"macos\")".dependencies]
+embed_plist = "1.2"
+
 [target."cfg(windows)".dependencies.windows]
 version = "0.44.0"
 features = [
@@ -51,6 +56,7 @@ features = [
 ]
 
 [features]
+default = ["icon-ico", "icon-png"]
 build = [ "proc-macro2", "quote" ]
 compression = [ "brotli" ]
 schema = [ "schemars" ]
@@ -59,3 +65,6 @@ process-relaunch-dangerous-allow-symlink-macos = [ ]
 config-json5 = [ "json5" ]
 config-toml = [ "toml" ]
 resources = [ "glob", "walkdir" ]
+icon-ico = [ "ico" ]
+icon-png = [ "png" ]
+

+ 27 - 25
core/tauri-utils/src/config.rs

@@ -2987,7 +2987,7 @@ mod build {
   macro_rules! literal_struct {
     ($tokens:ident, $struct:ident, $($field:ident),+) => {
       $tokens.append_all(quote! {
-        ::tauri::utils::config::$struct {
+        ::tauri_utils::config::$struct {
           $($field: #$field),+
         }
       });
@@ -2996,7 +2996,7 @@ mod build {
 
   impl ToTokens for WindowUrl {
     fn to_tokens(&self, tokens: &mut TokenStream) {
-      let prefix = quote! { ::tauri::utils::config::WindowUrl };
+      let prefix = quote! { ::tauri_utils::config::WindowUrl };
 
       tokens.append_all(match self {
         Self::App(path) => {
@@ -3013,7 +3013,7 @@ mod build {
 
   impl ToTokens for crate::Theme {
     fn to_tokens(&self, tokens: &mut TokenStream) {
-      let prefix = quote! { ::tauri::utils::Theme };
+      let prefix = quote! { ::tauri_utils::Theme };
 
       tokens.append_all(match self {
         Self::Light => quote! { #prefix::Light },
@@ -3024,7 +3024,7 @@ mod build {
 
   impl ToTokens for crate::TitleBarStyle {
     fn to_tokens(&self, tokens: &mut TokenStream) {
-      let prefix = quote! { ::tauri::utils::TitleBarStyle };
+      let prefix = quote! { ::tauri_utils::TitleBarStyle };
 
       tokens.append_all(match self {
         Self::Visible => quote! { #prefix::Visible },
@@ -3108,7 +3108,7 @@ mod build {
 
   impl ToTokens for PatternKind {
     fn to_tokens(&self, tokens: &mut TokenStream) {
-      let prefix = quote! { ::tauri::utils::config::PatternKind };
+      let prefix = quote! { ::tauri_utils::config::PatternKind };
 
       tokens.append_all(match self {
         Self::Brownfield => quote! { #prefix::Brownfield },
@@ -3125,7 +3125,7 @@ mod build {
 
   impl ToTokens for WebviewInstallMode {
     fn to_tokens(&self, tokens: &mut TokenStream) {
-      let prefix = quote! { ::tauri::utils::config::WebviewInstallMode };
+      let prefix = quote! { ::tauri_utils::config::WebviewInstallMode };
 
       tokens.append_all(match self {
         Self::Skip => quote! { #prefix::Skip },
@@ -3156,7 +3156,7 @@ mod build {
       } else {
         self.webview_install_mode.clone()
       };
-      tokens.append_all(quote! { ::tauri::utils::config::WindowsConfig {
+      tokens.append_all(quote! { ::tauri_utils::config::WindowsConfig {
         webview_install_mode: #webview_install_mode,
         ..Default::default()
       }})
@@ -3209,7 +3209,7 @@ mod build {
 
   impl ToTokens for AppUrl {
     fn to_tokens(&self, tokens: &mut TokenStream) {
-      let prefix = quote! { ::tauri::utils::config::AppUrl };
+      let prefix = quote! { ::tauri_utils::config::AppUrl };
 
       tokens.append_all(match self {
         Self::Url(url) => {
@@ -3251,7 +3251,7 @@ mod build {
 
   impl ToTokens for WindowsUpdateInstallMode {
     fn to_tokens(&self, tokens: &mut TokenStream) {
-      let prefix = quote! { ::tauri::utils::config::WindowsUpdateInstallMode };
+      let prefix = quote! { ::tauri_utils::config::WindowsUpdateInstallMode };
 
       tokens.append_all(match self {
         Self::BasicUi => quote! { #prefix::BasicUi },
@@ -3280,7 +3280,7 @@ mod build {
           .map(|list| {
             vec_lit(list, |url| {
               let url = url.0.as_str();
-              quote! { ::tauri::utils::config::UpdaterEndpoint(#url.parse().unwrap()) }
+              quote! { ::tauri_utils::config::UpdaterEndpoint(#url.parse().unwrap()) }
             })
           })
           .as_ref(),
@@ -3293,7 +3293,7 @@ mod build {
 
   impl ToTokens for CspDirectiveSources {
     fn to_tokens(&self, tokens: &mut TokenStream) {
-      let prefix = quote! { ::tauri::utils::config::CspDirectiveSources };
+      let prefix = quote! { ::tauri_utils::config::CspDirectiveSources };
 
       tokens.append_all(match self {
         Self::Inline(sources) => {
@@ -3310,7 +3310,7 @@ mod build {
 
   impl ToTokens for Csp {
     fn to_tokens(&self, tokens: &mut TokenStream) {
-      let prefix = quote! { ::tauri::utils::config::Csp };
+      let prefix = quote! { ::tauri_utils::config::Csp };
 
       tokens.append_all(match self {
         Self::Policy(policy) => {
@@ -3332,7 +3332,7 @@ mod build {
 
   impl ToTokens for DisabledCspModificationKind {
     fn to_tokens(&self, tokens: &mut TokenStream) {
-      let prefix = quote! { ::tauri::utils::config::DisabledCspModificationKind };
+      let prefix = quote! { ::tauri_utils::config::DisabledCspModificationKind };
 
       tokens.append_all(match self {
         Self::Flag(flag) => {
@@ -3406,7 +3406,7 @@ mod build {
 
   impl ToTokens for FsAllowlistScope {
     fn to_tokens(&self, tokens: &mut TokenStream) {
-      let prefix = quote! { ::tauri::utils::config::FsAllowlistScope };
+      let prefix = quote! { ::tauri_utils::config::FsAllowlistScope };
 
       tokens.append_all(match self {
         Self::AllowedPaths(allow) => {
@@ -3425,28 +3425,30 @@ mod build {
   impl ToTokens for FsAllowlistConfig {
     fn to_tokens(&self, tokens: &mut TokenStream) {
       let scope = &self.scope;
-      tokens.append_all(quote! { ::tauri::utils::config::FsAllowlistConfig { scope: #scope, ..Default::default() } })
+      tokens.append_all(
+        quote! { ::tauri_utils::config::FsAllowlistConfig { scope: #scope, ..Default::default() } },
+      )
     }
   }
 
   impl ToTokens for ProtocolAllowlistConfig {
     fn to_tokens(&self, tokens: &mut TokenStream) {
       let asset_scope = &self.asset_scope;
-      tokens.append_all(quote! { ::tauri::utils::config::ProtocolAllowlistConfig { asset_scope: #asset_scope, ..Default::default() } })
+      tokens.append_all(quote! { ::tauri_utils::config::ProtocolAllowlistConfig { asset_scope: #asset_scope, ..Default::default() } })
     }
   }
 
   impl ToTokens for HttpAllowlistScope {
     fn to_tokens(&self, tokens: &mut TokenStream) {
       let allowed_urls = vec_lit(&self.0, url_lit);
-      tokens.append_all(quote! { ::tauri::utils::config::HttpAllowlistScope(#allowed_urls) })
+      tokens.append_all(quote! { ::tauri_utils::config::HttpAllowlistScope(#allowed_urls) })
     }
   }
 
   impl ToTokens for HttpAllowlistConfig {
     fn to_tokens(&self, tokens: &mut TokenStream) {
       let scope = &self.scope;
-      tokens.append_all(quote! { ::tauri::utils::config::HttpAllowlistConfig { scope: #scope, ..Default::default() } })
+      tokens.append_all(quote! { ::tauri_utils::config::HttpAllowlistConfig { scope: #scope, ..Default::default() } })
     }
   }
 
@@ -3463,7 +3465,7 @@ mod build {
 
   impl ToTokens for ShellAllowedArgs {
     fn to_tokens(&self, tokens: &mut TokenStream) {
-      let prefix = quote! { ::tauri::utils::config::ShellAllowedArgs };
+      let prefix = quote! { ::tauri_utils::config::ShellAllowedArgs };
 
       tokens.append_all(match self {
         Self::Flag(flag) => quote!(#prefix::Flag(#flag)),
@@ -3477,7 +3479,7 @@ mod build {
 
   impl ToTokens for ShellAllowedArg {
     fn to_tokens(&self, tokens: &mut TokenStream) {
-      let prefix = quote! { ::tauri::utils::config::ShellAllowedArg };
+      let prefix = quote! { ::tauri_utils::config::ShellAllowedArg };
 
       tokens.append_all(match self {
         Self::Fixed(fixed) => {
@@ -3494,7 +3496,7 @@ mod build {
 
   impl ToTokens for ShellAllowlistOpen {
     fn to_tokens(&self, tokens: &mut TokenStream) {
-      let prefix = quote! { ::tauri::utils::config::ShellAllowlistOpen };
+      let prefix = quote! { ::tauri_utils::config::ShellAllowlistOpen };
 
       tokens.append_all(match self {
         Self::Flag(flag) => quote!(#prefix::Flag(#flag)),
@@ -3506,14 +3508,14 @@ mod build {
   impl ToTokens for ShellAllowlistScope {
     fn to_tokens(&self, tokens: &mut TokenStream) {
       let allowed_commands = vec_lit(&self.0, identity);
-      tokens.append_all(quote! { ::tauri::utils::config::ShellAllowlistScope(#allowed_commands) })
+      tokens.append_all(quote! { ::tauri_utils::config::ShellAllowlistScope(#allowed_commands) })
     }
   }
 
   impl ToTokens for ShellAllowlistConfig {
     fn to_tokens(&self, tokens: &mut TokenStream) {
       let scope = &self.scope;
-      tokens.append_all(quote! { ::tauri::utils::config::ShellAllowlistConfig { scope: #scope, ..Default::default() } })
+      tokens.append_all(quote! { ::tauri_utils::config::ShellAllowlistConfig { scope: #scope, ..Default::default() } })
     }
   }
 
@@ -3524,7 +3526,7 @@ mod build {
       let http = &self.http;
       let shell = &self.shell;
       tokens.append_all(
-        quote! { ::tauri::utils::config::AllowlistConfig { fs: #fs, protocol: #protocol, http: #http, shell: #shell, ..Default::default() } },
+        quote! { ::tauri_utils::config::AllowlistConfig { fs: #fs, protocol: #protocol, http: #http, shell: #shell, ..Default::default() } },
       )
     }
   }
@@ -3563,7 +3565,7 @@ mod build {
         str_lit,
         json_value_lit,
       );
-      tokens.append_all(quote! { ::tauri::utils::config::PluginConfig(#config) })
+      tokens.append_all(quote! { ::tauri_utils::config::PluginConfig(#config) })
     }
   }
 

+ 257 - 1
core/tauri-utils/src/lib.rs

@@ -6,10 +6,14 @@
 #![warn(missing_docs, rust_2018_idioms)]
 
 use std::{
-  fmt::Display,
+  fmt::{self, Display},
   path::{Path, PathBuf},
+  sync::Arc,
 };
 
+use assets::Assets;
+use config::Config;
+use pattern::Pattern;
 use semver::Version;
 use serde::{Deserialize, Deserializer, Serialize, Serializer};
 
@@ -26,6 +30,10 @@ pub mod resources;
 /// Application pattern.
 pub mod pattern;
 
+#[cfg(target_os = "macos")]
+#[doc(hidden)]
+pub use embed_plist;
+
 /// `tauri::App` package information.
 #[derive(Debug, Clone)]
 pub struct PackageInfo {
@@ -308,3 +316,251 @@ pub fn display_path<P: AsRef<Path>>(p: P) -> String {
     .display()
     .to_string()
 }
+
+/// Window icon.
+#[derive(Debug, Clone)]
+pub struct RawIcon {
+  /// RGBA bytes of the icon.
+  pub rgba: Vec<u8>,
+  /// Icon width.
+  pub width: u32,
+  /// Icon height.
+  pub height: u32,
+}
+
+/// A icon definition.
+#[derive(Debug, Clone)]
+#[non_exhaustive]
+pub enum Icon {
+  /// Icon from file path.
+  #[cfg(any(feature = "icon-ico", feature = "icon-png"))]
+  #[cfg_attr(doc_cfg, doc(cfg(any(feature = "icon-ico", feature = "icon-png"))))]
+  File(std::path::PathBuf),
+  /// Icon from raw RGBA bytes. Width and height is parsed at runtime.
+  #[cfg(any(feature = "icon-ico", feature = "icon-png"))]
+  #[cfg_attr(doc_cfg, doc(cfg(any(feature = "icon-ico", feature = "icon-png"))))]
+  Raw(Vec<u8>),
+  /// Icon from raw RGBA bytes.
+  Rgba {
+    /// RGBA bytes of the icon image.
+    rgba: Vec<u8>,
+    /// Icon width.
+    width: u32,
+    /// Icon height.
+    height: u32,
+  },
+}
+
+/// Errors that can happen while loading an Icon.
+#[derive(Debug, thiserror::Error)]
+pub enum IconError {
+  /// Any IO error.
+  #[error(transparent)]
+  Io(#[from] std::io::Error),
+
+  /// Invalid PNG.
+  #[cfg(feature = "icon-png")]
+  #[error(transparent)]
+  Png(#[from] png::DecodingError),
+}
+
+impl TryFrom<Icon> for RawIcon {
+  type Error = IconError;
+
+  fn try_from(icon: Icon) -> ::std::result::Result<Self, Self::Error> {
+    #[allow(irrefutable_let_patterns)]
+    if let Icon::Rgba {
+      rgba,
+      width,
+      height,
+    } = icon
+    {
+      Ok(Self {
+        rgba,
+        width,
+        height,
+      })
+    } else {
+      #[cfg(not(any(feature = "icon-ico", feature = "icon-png")))]
+      panic!("unexpected Icon variant");
+      #[cfg(any(feature = "icon-ico", feature = "icon-png"))]
+      {
+        let bytes = match icon {
+          Icon::File(p) => std::fs::read(p)?,
+          Icon::Raw(r) => r,
+          Icon::Rgba { .. } => unreachable!(),
+        };
+        let extension = infer::get(&bytes)
+          .expect("could not determine icon extension")
+          .extension();
+        match extension {
+        #[cfg(feature = "icon-ico")]
+        "ico" => {
+          let icon_dir = ico::IconDir::read(std::io::Cursor::new(bytes))?;
+          let entry = &icon_dir.entries()[0];
+          Ok(Self {
+            rgba: entry.decode()?.rgba_data().to_vec(),
+            width: entry.width(),
+            height: entry.height(),
+          })
+        }
+        #[cfg(feature = "icon-png")]
+        "png" => {
+          let decoder = png::Decoder::new(std::io::Cursor::new(bytes));
+          let mut reader = decoder.read_info()?;
+          let mut buffer = Vec::new();
+          while let Ok(Some(row)) = reader.next_row() {
+            buffer.extend(row.data());
+          }
+          Ok(Self {
+            rgba: buffer,
+            width: reader.info().width,
+            height: reader.info().height,
+          })
+        }
+        _ => panic!(
+          "image `{extension}` extension not supported; please file a Tauri feature request. `png` or `ico` icons are supported with the `icon-png` and `icon-ico` feature flags"
+        ),
+      }
+      }
+    }
+  }
+}
+
+/// User supplied data required inside of a Tauri application.
+///
+/// # Stability
+///
+/// This is the output of Tauri codegen, and is not considered part of the stable API.
+/// Unless you know what you are doing and are prepared for this type to have breaking changes, do not create it yourself.
+pub struct Context<A: Assets> {
+  #[doc(hidden)]
+  pub config: Config,
+
+  #[doc(hidden)]
+  pub assets: Arc<A>,
+
+  #[doc(hidden)]
+  pub default_window_icon: Option<Icon>,
+
+  #[doc(hidden)]
+  pub app_icon: Option<Vec<u8>>,
+
+  #[doc(hidden)]
+  pub system_tray_icon: Option<Icon>,
+
+  #[doc(hidden)]
+  pub package_info: PackageInfo,
+
+  #[doc(hidden)]
+  pub pattern: Pattern,
+}
+
+impl<A: Assets> fmt::Debug for Context<A> {
+  fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+    f.debug_struct("Context")
+      .field("config", &self.config)
+      .field("default_window_icon", &self.default_window_icon)
+      .field("app_icon", &self.app_icon)
+      .field("package_info", &self.package_info)
+      .field("pattern", &self.pattern)
+      .field("system_tray_icon", &self.system_tray_icon)
+      .finish()
+  }
+}
+
+impl<A: Assets> Context<A> {
+  /// The config the application was prepared with.
+  #[inline(always)]
+  pub fn config(&self) -> &Config {
+    &self.config
+  }
+
+  /// A mutable reference to the config the application was prepared with.
+  #[inline(always)]
+  pub fn config_mut(&mut self) -> &mut Config {
+    &mut self.config
+  }
+
+  /// The assets to be served directly by Tauri.
+  #[inline(always)]
+  pub fn assets(&self) -> Arc<A> {
+    self.assets.clone()
+  }
+
+  /// A mutable reference to the assets to be served directly by Tauri.
+  #[inline(always)]
+  pub fn assets_mut(&mut self) -> &mut Arc<A> {
+    &mut self.assets
+  }
+
+  /// The default window icon Tauri should use when creating windows.
+  #[inline(always)]
+  pub fn default_window_icon(&self) -> Option<&Icon> {
+    self.default_window_icon.as_ref()
+  }
+
+  /// A mutable reference to the default window icon Tauri should use when creating windows.
+  #[inline(always)]
+  pub fn default_window_icon_mut(&mut self) -> &mut Option<Icon> {
+    &mut self.default_window_icon
+  }
+
+  /// The icon to use on the system tray UI.
+  #[inline(always)]
+  pub fn system_tray_icon(&self) -> Option<&Icon> {
+    self.system_tray_icon.as_ref()
+  }
+
+  /// A mutable reference to the icon to use on the system tray UI.
+  #[inline(always)]
+  pub fn system_tray_icon_mut(&mut self) -> &mut Option<Icon> {
+    &mut self.system_tray_icon
+  }
+
+  /// Package information.
+  #[inline(always)]
+  pub fn package_info(&self) -> &PackageInfo {
+    &self.package_info
+  }
+
+  /// A mutable reference to the package information.
+  #[inline(always)]
+  pub fn package_info_mut(&mut self) -> &mut PackageInfo {
+    &mut self.package_info
+  }
+
+  /// The application pattern.
+  #[inline(always)]
+  pub fn pattern(&self) -> &Pattern {
+    &self.pattern
+  }
+
+  /// Create a new [`Context`] from the minimal required items.
+  #[inline(always)]
+  #[allow(clippy::too_many_arguments)]
+  pub fn new(
+    config: Config,
+    assets: Arc<A>,
+    default_window_icon: Option<Icon>,
+    app_icon: Option<Vec<u8>>,
+    package_info: PackageInfo,
+    pattern: Pattern,
+  ) -> Self {
+    Self {
+      config,
+      assets,
+      default_window_icon,
+      app_icon,
+      system_tray_icon: None,
+      package_info,
+      pattern,
+    }
+  }
+
+  /// Sets the app tray icon.
+  #[inline(always)]
+  pub fn set_system_tray_icon(&mut self, icon: Icon) {
+    self.system_tray_icon.replace(icon);
+  }
+}

+ 50 - 0
core/tauri-utils/src/pattern/mod.rs

@@ -2,6 +2,56 @@
 // SPDX-License-Identifier: Apache-2.0
 // SPDX-License-Identifier: MIT
 
+use std::{marker::PhantomData, sync::Arc};
+
+use crate::assets::{Assets, EmbeddedAssets};
+
+use self::isolation::Keys;
+
 /// Handling the Tauri "Isolation" Pattern.
 #[cfg(feature = "isolation")]
 pub mod isolation;
+
+/// An application pattern.
+#[derive(Debug)]
+pub enum Pattern<A: Assets = EmbeddedAssets> {
+  /// The brownfield pattern.
+  Brownfield(PhantomData<A>),
+  /// Isolation pattern. Recommended for security purposes.
+  #[cfg(feature = "isolation")]
+  Isolation {
+    /// The HTML served on `isolation://index.html`.
+    assets: Arc<A>,
+
+    /// The schema used for the isolation frames.
+    schema: String,
+
+    /// A random string used to ensure that the message went through the isolation frame.
+    ///
+    /// This should be regenerated at runtime.
+    key: String,
+
+    /// Cryptographically secure keys
+    crypto_keys: Box<Keys>,
+  },
+}
+
+impl<A: Assets> Clone for Pattern<A> {
+  fn clone(&self) -> Self {
+    match self {
+      Self::Brownfield(a) => Self::Brownfield(*a),
+      #[cfg(feature = "isolation")]
+      Self::Isolation {
+        assets,
+        schema,
+        key,
+        crypto_keys,
+      } => Self::Isolation {
+        assets: assets.clone(),
+        schema: schema.clone(),
+        key: key.clone(),
+        crypto_keys: crypto_keys.clone(),
+      },
+    }
+  }
+}

+ 3 - 41
core/tauri/Cargo.toml

@@ -121,6 +121,7 @@ tokio-test = "0.4.2"
 tokio = { version = "1", features = [ "full" ] }
 cargo_toml = "0.11"
 winnow = "=0.4.1"
+tauri-codegen-test = { path = "../tests/tauri-codegen-test" }
 
 [features]
 default = [ "wry", "compression", "objc-exception" ]
@@ -278,44 +279,5 @@ app-show = [ ]
 app-hide = [ ]
 config-json5 = [ "tauri-macros/config-json5" ]
 config-toml = [ "tauri-macros/config-toml" ]
-icon-ico = [ "infer", "ico" ]
-icon-png = [ "infer", "png" ]
-
-[[example]]
-name = "commands"
-path = "../../examples/commands/main.rs"
-
-[[example]]
-name = "helloworld"
-path = "../../examples/helloworld/main.rs"
-
-[[example]]
-name = "multiwindow"
-path = "../../examples/multiwindow/main.rs"
-required-features = [ "window-create" ]
-
-[[example]]
-name = "parent-window"
-path = "../../examples/parent-window/main.rs"
-
-[[example]]
-name = "navigation"
-path = "../../examples/navigation/main.rs"
-required-features = [ "window-create" ]
-
-[[example]]
-name = "splashscreen"
-path = "../../examples/splashscreen/main.rs"
-
-[[example]]
-name = "state"
-path = "../../examples/state/main.rs"
-
-[[example]]
-name = "streaming"
-path = "../../examples/streaming/main.rs"
-
-[[example]]
-name = "isolation"
-path = "../../examples/isolation/main.rs"
-required-features = [ "isolation" ]
+icon-ico = [ "infer", "ico", "tauri-utils/icon-ico" ]
+icon-png = [ "infer", "png", "tauri-utils/icon-png" ]

+ 54 - 14
core/tauri/src/app.rs

@@ -661,10 +661,16 @@ impl<R: Runtime> App<R> {
   /// Sets the activation policy for the application. It is set to `NSApplicationActivationPolicyRegular` by default.
   ///
   /// # Examples
-  /// ```,no_run
+  ///
+  /// ```ignore
+  /// let context = tauri::tauri_build_context!();
+  /// ```
+  ///
+  /// ```rust,no_run
+  /// # let context = tauri_codegen_test::context();
   /// let mut app = tauri::Builder::default()
   ///   // on an actual app, remove the string argument
-  ///   .build(tauri::generate_context!("test/fixture/src-tauri/tauri.conf.json"))
+  ///   .build(context)
   ///   .expect("error while building tauri application");
   /// #[cfg(target_os = "macos")]
   /// app.set_activation_policy(tauri::ActivationPolicy::Accessory);
@@ -691,10 +697,16 @@ impl<R: Runtime> App<R> {
   /// - ** Linux / macOS / iOS / Android**: Unsupported.
   ///
   /// # Examples
-  /// ```,no_run
+  ///
+  /// ```ignore
+  /// let context = tauri::tauri_build_context!();
+  /// ```
+  ///
+  /// ```rust,no_run
+  /// # let context = tauri_codegen_test::context();
   /// let mut app = tauri::Builder::default()
   ///   // on an actual app, remove the string argument
-  ///   .build(tauri::generate_context!("test/fixture/src-tauri/tauri.conf.json"))
+  ///   .build(context)
   ///   .expect("error while building tauri application");
   /// app.set_device_event_filter(tauri::DeviceEventFilter::Always);
   /// app.run(|_app_handle, _event| {});
@@ -712,10 +724,16 @@ impl<R: Runtime> App<R> {
   /// Runs the application.
   ///
   /// # Examples
-  /// ```,no_run
+  ///
+  /// ```ignore
+  /// let context = tauri::tauri_build_context!();
+  /// ```
+  ///
+  /// ```rust,no_run
+  /// # let context = tauri_codegen_test::context();
   /// let app = tauri::Builder::default()
   ///   // on an actual app, remove the string argument
-  ///   .build(tauri::generate_context!("test/fixture/src-tauri/tauri.conf.json"))
+  ///   .build(context)
   ///   .expect("error while building tauri application");
   /// app.run(|_app_handle, event| match event {
   ///   tauri::RunEvent::ExitRequested { api, .. } => {
@@ -761,10 +779,16 @@ impl<R: Runtime> App<R> {
   /// Additionally, the cleanup calls [AppHandle#remove_system_tray](`AppHandle#method.remove_system_tray`) (Windows only).
   ///
   /// # Examples
-  /// ```no_run
+  ///
+  /// ```ignore
+  /// let context = tauri::tauri_build_context!();
+  /// ```
+  ///
+  /// ```rust,no_run
+  /// # let context = tauri_codegen_test::context();
   /// let mut app = tauri::Builder::default()
   ///   // on an actual app, remove the string argument
-  ///   .build(tauri::generate_context!("test/fixture/src-tauri/tauri.conf.json"))
+  ///   .build(context)
   ///   .expect("error while building tauri application");
   /// loop {
   ///   let iteration = app.run_iteration();
@@ -806,10 +830,16 @@ impl<R: Runtime> App<R> {
 /// Builds a Tauri application.
 ///
 /// # Examples
-/// ```,no_run
+///
+/// ```ignore
+/// let context = tauri::tauri_build_context!();
+/// ```
+///
+/// ```rust,no_run
+/// # let context = tauri_codegen_test::context();
 /// tauri::Builder::default()
 ///   // on an actual app, remove the string argument
-///   .run(tauri::generate_context!("test/fixture/src-tauri/tauri.conf.json"))
+///   .run(context)
 ///  .expect("error while running tauri application");
 /// ```
 #[allow(clippy::type_complexity)]
@@ -1052,7 +1082,11 @@ impl<R: Runtime> Builder<R> {
   ///
   /// Since the managed state is global and must be [`Send`] + [`Sync`], mutations can only happen through interior mutability:
   ///
-  /// ```,no_run
+  /// ```ignore
+  /// let context = tauri::tauri_build_context!();
+  /// ```
+  ///
+  /// ```rust,no_run
   /// use std::{collections::HashMap, sync::Mutex};
   /// use tauri::State;
   /// // here we use Mutex to achieve interior mutability
@@ -1076,18 +1110,23 @@ impl<R: Runtime> Builder<R> {
   ///   storage.store.lock().unwrap().insert(key, value);
   /// }
   ///
+  /// # let context = tauri_codegen_test::context();
   /// tauri::Builder::default()
   ///   .manage(Storage { store: Default::default() })
   ///   .manage(DbConnection { db: Default::default() })
   ///   .invoke_handler(tauri::generate_handler![connect, storage_insert])
   ///   // on an actual app, remove the string argument
-  ///   .run(tauri::generate_context!("test/fixture/src-tauri/tauri.conf.json"))
+  ///   .run(context)
   ///   .expect("error while running tauri application");
   /// ```
   ///
   /// # Examples
   ///
-  /// ```,no_run
+  /// ```ignore
+  /// let context = tauri::tauri_build_context!();
+  /// ```
+  ///
+  /// ```rust,no_run
   /// use tauri::State;
   ///
   /// struct MyInt(isize);
@@ -1103,12 +1142,13 @@ impl<R: Runtime> Builder<R> {
   ///     println!("state: {}", state.inner().0);
   /// }
   ///
+  /// # let context = tauri_codegen_test::context();
   /// tauri::Builder::default()
   ///   .manage(MyInt(10))
   ///   .manage(MyString("Hello, managed state!".to_string()))
   ///   .invoke_handler(tauri::generate_handler![int_command, string_command])
   ///   // on an actual app, remove the string argument
-  ///   .run(tauri::generate_context!("test/fixture/src-tauri/tauri.conf.json"))
+  ///   .run(context)
   ///   .expect("error while running tauri application");
   /// ```
   #[must_use]

+ 3 - 0
core/tauri/src/error.rs

@@ -113,6 +113,9 @@ pub enum Error {
   #[cfg(target_os = "android")]
   #[error("jni error: {0}")]
   Jni(#[from] jni::errors::Error),
+  /// An error happened while loading the Icon.
+  #[error(transparent)]
+  Icon(#[from] tauri_utils::IconError),
 }
 
 pub(crate) fn into_anyhow<T: std::fmt::Display>(err: T) -> anyhow::Error {

+ 14 - 253
core/tauri/src/lib.rs

@@ -252,7 +252,7 @@ pub type Result<T> = std::result::Result<T, Error>;
 pub type SyncTask = Box<dyn FnOnce() + Send>;
 
 use serde::Serialize;
-use std::{collections::HashMap, fmt, sync::Arc};
+use std::{collections::HashMap, sync::Arc};
 
 // Export types likely to be used by the application.
 pub use runtime::http;
@@ -405,32 +405,8 @@ pub trait Runtime: runtime::Runtime<EventLoopMessage> {}
 
 impl<W: runtime::Runtime<EventLoopMessage>> Runtime for W {}
 
-/// 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
-/// the crate being built.
-///
-/// # Custom Config Path
-///
-/// You may pass a string literal to this macro to specify a custom path for the Tauri config file.
-/// If the path is relative, it will be search for relative to the Cargo manifest of the compiling
-/// crate.
-///
-/// # Note
-///
-/// This macro should not be called if you are using [`tauri-build`] to generate the context from
-/// inside your build script as it will just cause excess computations that will be discarded. Use
-/// either the [`tauri-build`] method or this macro - not both.
-///
-/// [`tauri-build`]: https://docs.rs/tauri-build
-pub use tauri_macros::generate_context;
-
 /// Include a [`Context`] that was generated by [`tauri-build`] inside your build script.
 ///
-/// You should either use [`tauri-build`] and this macro to include the compile time generated code,
-/// or [`generate_context!`]. Do not use both at the same time, as they generate the same code and
-/// will cause excess computations that will be discarded.
-///
 /// [`tauri-build`]: https://docs.rs/tauri-build
 #[macro_export]
 macro_rules! build_script_context {
@@ -439,232 +415,7 @@ macro_rules! build_script_context {
   };
 }
 
-pub use pattern::Pattern;
-
-/// A icon definition.
-#[derive(Debug, Clone)]
-#[non_exhaustive]
-pub enum Icon {
-  /// Icon from file path.
-  #[cfg(any(feature = "icon-ico", feature = "icon-png"))]
-  #[cfg_attr(doc_cfg, doc(cfg(any(feature = "icon-ico", feature = "icon-png"))))]
-  File(std::path::PathBuf),
-  /// Icon from raw RGBA bytes. Width and height is parsed at runtime.
-  #[cfg(any(feature = "icon-ico", feature = "icon-png"))]
-  #[cfg_attr(doc_cfg, doc(cfg(any(feature = "icon-ico", feature = "icon-png"))))]
-  Raw(Vec<u8>),
-  /// Icon from raw RGBA bytes.
-  Rgba {
-    /// RGBA bytes of the icon image.
-    rgba: Vec<u8>,
-    /// Icon width.
-    width: u32,
-    /// Icon height.
-    height: u32,
-  },
-}
-
-impl TryFrom<Icon> for runtime::Icon {
-  type Error = Error;
-
-  fn try_from(icon: Icon) -> Result<Self> {
-    #[allow(irrefutable_let_patterns)]
-    if let Icon::Rgba {
-      rgba,
-      width,
-      height,
-    } = icon
-    {
-      Ok(Self {
-        rgba,
-        width,
-        height,
-      })
-    } else {
-      #[cfg(not(any(feature = "icon-ico", feature = "icon-png")))]
-      panic!("unexpected Icon variant");
-      #[cfg(any(feature = "icon-ico", feature = "icon-png"))]
-      {
-        let bytes = match icon {
-          Icon::File(p) => std::fs::read(p)?,
-          Icon::Raw(r) => r,
-          Icon::Rgba { .. } => unreachable!(),
-        };
-        let extension = infer::get(&bytes)
-          .expect("could not determine icon extension")
-          .extension();
-        match extension {
-        #[cfg(feature = "icon-ico")]
-        "ico" => {
-          let icon_dir = ico::IconDir::read(std::io::Cursor::new(bytes))?;
-          let entry = &icon_dir.entries()[0];
-          Ok(Self {
-            rgba: entry.decode()?.rgba_data().to_vec(),
-            width: entry.width(),
-            height: entry.height(),
-          })
-        }
-        #[cfg(feature = "icon-png")]
-        "png" => {
-          let decoder = png::Decoder::new(std::io::Cursor::new(bytes));
-          let mut reader = decoder.read_info()?;
-          let mut buffer = Vec::new();
-          while let Ok(Some(row)) = reader.next_row() {
-            buffer.extend(row.data());
-          }
-          Ok(Self {
-            rgba: buffer,
-            width: reader.info().width,
-            height: reader.info().height,
-          })
-        }
-        _ => panic!(
-          "image `{extension}` extension not supported; please file a Tauri feature request. `png` or `ico` icons are supported with the `icon-png` and `icon-ico` feature flags"
-        ),
-      }
-      }
-    }
-  }
-}
-
-/// User supplied data required inside of a Tauri application.
-///
-/// # Stability
-/// This is the output of the [`generate_context`] macro, and is not considered part of the stable API.
-/// Unless you know what you are doing and are prepared for this type to have breaking changes, do not create it yourself.
-pub struct Context<A: Assets> {
-  pub(crate) config: Config,
-  pub(crate) assets: Arc<A>,
-  pub(crate) default_window_icon: Option<Icon>,
-  pub(crate) app_icon: Option<Vec<u8>>,
-  #[cfg(desktop)]
-  pub(crate) system_tray_icon: Option<Icon>,
-  pub(crate) package_info: PackageInfo,
-  pub(crate) pattern: Pattern,
-}
-
-impl<A: Assets> fmt::Debug for Context<A> {
-  fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
-    let mut d = f.debug_struct("Context");
-    d.field("config", &self.config)
-      .field("default_window_icon", &self.default_window_icon)
-      .field("app_icon", &self.app_icon)
-      .field("package_info", &self.package_info)
-      .field("pattern", &self.pattern);
-
-    #[cfg(desktop)]
-    d.field("system_tray_icon", &self.system_tray_icon);
-
-    d.finish()
-  }
-}
-
-impl<A: Assets> Context<A> {
-  /// The config the application was prepared with.
-  #[inline(always)]
-  pub fn config(&self) -> &Config {
-    &self.config
-  }
-
-  /// A mutable reference to the config the application was prepared with.
-  #[inline(always)]
-  pub fn config_mut(&mut self) -> &mut Config {
-    &mut self.config
-  }
-
-  /// The assets to be served directly by Tauri.
-  #[inline(always)]
-  pub fn assets(&self) -> Arc<A> {
-    self.assets.clone()
-  }
-
-  /// A mutable reference to the assets to be served directly by Tauri.
-  #[inline(always)]
-  pub fn assets_mut(&mut self) -> &mut Arc<A> {
-    &mut self.assets
-  }
-
-  /// The default window icon Tauri should use when creating windows.
-  #[inline(always)]
-  pub fn default_window_icon(&self) -> Option<&Icon> {
-    self.default_window_icon.as_ref()
-  }
-
-  /// A mutable reference to the default window icon Tauri should use when creating windows.
-  #[inline(always)]
-  pub fn default_window_icon_mut(&mut self) -> &mut Option<Icon> {
-    &mut self.default_window_icon
-  }
-
-  /// The icon to use on the system tray UI.
-  #[cfg(desktop)]
-  #[inline(always)]
-  pub fn system_tray_icon(&self) -> Option<&Icon> {
-    self.system_tray_icon.as_ref()
-  }
-
-  /// A mutable reference to the icon to use on the system tray UI.
-  #[cfg(desktop)]
-  #[inline(always)]
-  pub fn system_tray_icon_mut(&mut self) -> &mut Option<Icon> {
-    &mut self.system_tray_icon
-  }
-
-  /// Package information.
-  #[inline(always)]
-  pub fn package_info(&self) -> &PackageInfo {
-    &self.package_info
-  }
-
-  /// A mutable reference to the package information.
-  #[inline(always)]
-  pub fn package_info_mut(&mut self) -> &mut PackageInfo {
-    &mut self.package_info
-  }
-
-  /// The application pattern.
-  #[inline(always)]
-  pub fn pattern(&self) -> &Pattern {
-    &self.pattern
-  }
-
-  /// Create a new [`Context`] from the minimal required items.
-  #[inline(always)]
-  #[allow(clippy::too_many_arguments)]
-  pub fn new(
-    config: Config,
-    assets: Arc<A>,
-    default_window_icon: Option<Icon>,
-    app_icon: Option<Vec<u8>>,
-    package_info: PackageInfo,
-    pattern: Pattern,
-  ) -> Self {
-    Self {
-      config,
-      assets,
-      default_window_icon,
-      app_icon,
-      #[cfg(desktop)]
-      system_tray_icon: None,
-      package_info,
-      pattern,
-    }
-  }
-
-  /// Sets the app tray icon.
-  #[cfg(desktop)]
-  #[inline(always)]
-  pub fn set_system_tray_icon(&mut self, icon: Icon) {
-    self.system_tray_icon.replace(icon);
-  }
-
-  /// Sets the app shell scope.
-  #[cfg(shell_scope)]
-  #[inline(always)]
-  pub fn set_shell_scope(&mut self, scope: scope::ShellScopeConfig) {
-    self.shell_scope = scope;
-  }
-}
+pub use tauri_utils::{pattern::Pattern, Context, Icon};
 
 // TODO: expand these docs
 /// Manages a running application.
@@ -751,6 +502,10 @@ pub trait Manager<R: Runtime>: sealed::ManagerBase<R> {
   ///
   /// Since the managed state is global and must be [`Send`] + [`Sync`], mutations can only happen through interior mutability:
   ///
+  /// ```ignore
+  /// let context = tauri::tauri_build_context!();
+  /// ```
+  ///
   /// ```rust,no_run
   /// use std::{collections::HashMap, sync::Mutex};
   /// use tauri::State;
@@ -775,17 +530,22 @@ pub trait Manager<R: Runtime>: sealed::ManagerBase<R> {
   ///   storage.store.lock().unwrap().insert(key, value);
   /// }
   ///
+  /// # let context = tauri_codegen_test::context();
   /// tauri::Builder::default()
   ///   .manage(Storage { store: Default::default() })
   ///   .manage(DbConnection { db: Default::default() })
   ///   .invoke_handler(tauri::generate_handler![connect, storage_insert])
   ///   // on an actual app, remove the string argument
-  ///   .run(tauri::generate_context!("test/fixture/src-tauri/tauri.conf.json"))
+  ///   .run(context)
   ///   .expect("error while running tauri application");
   /// ```
   ///
   /// # Examples
   ///
+  /// ```ignore
+  /// let context = tauri::tauri_build_context!();
+  /// ```
+  ///
   /// ```rust,no_run
   /// use tauri::{Manager, State};
   ///
@@ -802,6 +562,7 @@ pub trait Manager<R: Runtime>: sealed::ManagerBase<R> {
   ///     println!("state: {}", state.inner().0);
   /// }
   ///
+  /// # let context = tauri_codegen_test::context();
   /// tauri::Builder::default()
   ///   .setup(|app| {
   ///     app.manage(MyInt(0));
@@ -818,7 +579,7 @@ pub trait Manager<R: Runtime>: sealed::ManagerBase<R> {
   ///   })
   ///   .invoke_handler(tauri::generate_handler![int_command, string_command])
   ///   // on an actual app, remove the string argument
-  ///   .run(tauri::generate_context!("test/fixture/src-tauri/tauri.conf.json"))
+  ///   .run(context)
   ///   .expect("error while running tauri application");
   /// ```
   fn manage<T>(&self, state: T) -> bool

+ 2 - 2
core/tauri/src/manager.rs

@@ -1144,13 +1144,13 @@ impl<R: Runtime> WindowManager<R> {
 
 #[cfg(test)]
 mod test {
-  use crate::{generate_context, plugin::PluginStore, StateManager, Wry};
+  use crate::{plugin::PluginStore, StateManager, Wry};
 
   use super::WindowManager;
 
   #[test]
   fn check_get_url() {
-    let context = generate_context!("test/fixture/src-tauri/tauri.conf.json", crate);
+    let context = tauri_codegen_test::context();
     let manager: WindowManager<Wry> = WindowManager::with_handlers(
       context,
       PluginStore::default(),

+ 1 - 49
core/tauri/src/pattern.rs

@@ -2,62 +2,14 @@
 // SPDX-License-Identifier: Apache-2.0
 // SPDX-License-Identifier: MIT
 
-use std::marker::PhantomData;
-#[cfg(feature = "isolation")]
-use std::sync::Arc;
-
 use serde::Serialize;
 use serialize_to_javascript::{default_template, Template};
 
-use tauri_utils::assets::{Assets, EmbeddedAssets};
+use tauri_utils::pattern::Pattern;
 
 /// The domain of the isolation iframe source.
 pub const ISOLATION_IFRAME_SRC_DOMAIN: &str = "localhost";
 
-/// An application pattern.
-#[derive(Debug)]
-pub enum Pattern<A: Assets = EmbeddedAssets> {
-  /// The brownfield pattern.
-  Brownfield(PhantomData<A>),
-  /// Isolation pattern. Recommended for security purposes.
-  #[cfg(feature = "isolation")]
-  Isolation {
-    /// The HTML served on `isolation://index.html`.
-    assets: Arc<A>,
-
-    /// The schema used for the isolation frames.
-    schema: String,
-
-    /// A random string used to ensure that the message went through the isolation frame.
-    ///
-    /// This should be regenerated at runtime.
-    key: String,
-
-    /// Cryptographically secure keys
-    crypto_keys: Box<tauri_utils::pattern::isolation::Keys>,
-  },
-}
-
-impl<A: Assets> Clone for Pattern<A> {
-  fn clone(&self) -> Self {
-    match self {
-      Self::Brownfield(a) => Self::Brownfield(*a),
-      #[cfg(feature = "isolation")]
-      Self::Isolation {
-        assets,
-        schema,
-        key,
-        crypto_keys,
-      } => Self::Isolation {
-        assets: assets.clone(),
-        schema: schema.clone(),
-        key: key.clone(),
-        crypto_keys: crypto_keys.clone(),
-      },
-    }
-  }
-}
-
 /// The shape of the JavaScript Pattern config
 #[derive(Debug, Serialize)]
 #[serde(rename_all = "lowercase", tag = "pattern")]

+ 8 - 2
core/tauri/src/updater/mod.rs

@@ -14,11 +14,17 @@
 //!
 //! To listen to the updater events, for example to check for error messages, you need to use [`RunEvent::Updater`](crate::RunEvent) in [`App::run`](crate::App#method.run).
 //!
-//! ```no_run
+//! ```ignore
+//! let context = tauri::tauri_build_context!();
+//! ```
+//!
+//! ```rust,no_run
+//! # let context = tauri_codegen_test::context();
 //! let app = tauri::Builder::default()
 //!   // on an actual app, remove the string argument
-//!   .build(tauri::generate_context!("test/fixture/src-tauri/tauri.conf.json"))
+//!   .build(context)
 //!   .expect("error while building tauri application");
+//!
 //! app.run(|_app_handle, event| match event {
 //!   tauri::RunEvent::Updater(updater_event) => {
 //!     match updater_event {

+ 0 - 1
core/tauri/test/fixture/config.json

@@ -1 +0,0 @@
-{ "devPath": "http://localhost" }

BIN
core/tauri/test/fixture/src-tauri/icons/icon.ico~dev


+ 0 - 0
core/tauri/test/fixture/test.txt


+ 1 - 0
core/tests/app-updater/Cargo.toml

@@ -11,6 +11,7 @@ serde = { version = "1", features = ["derive"] }
 serde_json = "1"
 tiny_http = "0.11"
 tauri = { path = "../../tauri", features = ["updater"] }
+tauri-utils = { path = "../../tauri-utils" }
 time = { version = "0.3", features = ["formatting"] }
 
 [features]

+ 1 - 1
core/tests/app-updater/src/main.rs

@@ -5,7 +5,7 @@
 #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
 
 fn main() {
-  let mut context = tauri::generate_context!();
+  let mut context = tauri::build_script_context!();
   if std::env::var("TARGET").unwrap_or_default() == "nsis" {
     // /D sets the default installation directory ($INSTDIR),
     // overriding InstallDir and InstallDirRegKey.

+ 11 - 0
core/tests/tauri-codegen-test/Cargo.toml

@@ -0,0 +1,11 @@
+[package]
+name = "tauri-codegen-test"
+version = "0.1.0"
+edition = "2021"
+
+[build-dependencies]
+tauri-build = { path = "../../tauri-build" }
+
+[dependencies]
+tauri = { path = "../../tauri", features = [ "api-all" ] }
+tauri-utils = { path = "../../tauri-utils" }

+ 3 - 0
core/tests/tauri-codegen-test/build.rs

@@ -0,0 +1,3 @@
+fn main() {
+  tauri_build::build();
+}

+ 0 - 0
core/tauri/test/fixture/dist/index.html → core/tests/tauri-codegen-test/dist/index.html


+ 0 - 0
core/tauri/test/fixture/src-tauri/icons/icon.ico → core/tests/tauri-codegen-test/icons/icon.ico


+ 0 - 0
core/tauri/test/fixture/src-tauri/icons/icon.png → core/tests/tauri-codegen-test/icons/icon.png


+ 5 - 0
core/tests/tauri-codegen-test/src/lib.rs

@@ -0,0 +1,5 @@
+pub use tauri_utils::{assets::EmbeddedAssets, Context};
+
+pub fn context() -> Context<EmbeddedAssets> {
+  tauri::build_script_context!()
+}

+ 3 - 3
core/tauri/test/fixture/src-tauri/tauri.conf.json → core/tests/tauri-codegen-test/tauri.conf.json

@@ -1,12 +1,12 @@
 {
-  "$schema": "../../../../../core/tauri-config-schema/schema.json",
+  "$schema": "../../tauri-config-schema/schema.json",
   "build": {
     "distDir": "../dist",
     "devPath": "http://localhost:4000"
   },
   "tauri": {
     "bundle": {
-      "identifier": "studio.tauri.example",
+      "identifier": "app.tauri.tauri-codegen-test",
       "active": true
     },
     "allowlist": {
@@ -14,7 +14,7 @@
     },
     "windows": [
       {
-        "title": "Tauri App"
+        "title": "Tauri Codegen Test"
       }
     ],
     "security": {

+ 12 - 0
examples/commands/Cargo.toml

@@ -0,0 +1,12 @@
+[package]
+name = "commands"
+version = "0.1.0"
+edition = "2021"
+
+[build-dependencies]
+tauri-build = { path = "../../core/tauri-build" }
+
+[dependencies]
+serde = { version = "1", features = ["derive"] }
+tauri = { path = "../../core/tauri" }
+tauri-utils = { path = "../../core/tauri-utils" }

+ 3 - 0
examples/commands/build.rs

@@ -0,0 +1,3 @@
+fn main() {
+  tauri_build::build();
+}

+ 0 - 0
examples/commands/commands.rs → examples/commands/src/commands.rs


+ 1 - 3
examples/commands/main.rs → examples/commands/src/main.rs

@@ -252,8 +252,6 @@ fn main() {
       future_simple_command_with_result,
       async_stateful_command_with_result,
     ])
-    .run(tauri::generate_context!(
-      "../../examples/commands/tauri.conf.json"
-    ))
+    .run(tauri::build_script_context!())
     .expect("error while running tauri application");
 }

+ 11 - 0
examples/helloworld/Cargo.toml

@@ -0,0 +1,11 @@
+[package]
+name = "helloworld"
+version = "0.1.0"
+edition = "2021"
+
+[build-dependencies]
+tauri-build = { path = "../../core/tauri-build" }
+
+[dependencies]
+tauri = { path = "../../core/tauri" }
+tauri-utils = { path = "../../core/tauri-utils" }

+ 3 - 0
examples/helloworld/build.rs

@@ -0,0 +1,3 @@
+fn main() {
+  tauri_build::build();
+}

+ 1 - 3
examples/navigation/main.rs → examples/helloworld/src/main.rs

@@ -6,8 +6,6 @@
 
 fn main() {
   tauri::Builder::default()
-    .run(tauri::generate_context!(
-      "../../examples/navigation/tauri.conf.json"
-    ))
+    .run(tauri::build_script_context!())
     .expect("error while running tauri application");
 }

+ 11 - 0
examples/isolation/Cargo.toml

@@ -0,0 +1,11 @@
+[package]
+name = "isolation"
+version = "0.1.0"
+edition = "2021"
+
+[build-dependencies]
+tauri-build = { path = "../../core/tauri-build", features = ["isolation"] }
+
+[dependencies]
+tauri = { path = "../../core/tauri", features = ["isolation"] }
+tauri-utils = { path = "../../core/tauri-utils" }

+ 3 - 0
examples/isolation/build.rs

@@ -0,0 +1,3 @@
+fn main() {
+  tauri_build::build();
+}

+ 1 - 9
examples/isolation/main.rs → examples/isolation/src/main.rs

@@ -11,17 +11,9 @@ fn ping() {
   dbg!(format!("ping: {:?}", Instant::now()));
 }
 
-#[cfg(not(feature = "isolation"))]
-fn main() {
-  compile_error!("Feature `isolation` is required to run this example");
-}
-
-#[cfg(feature = "isolation")]
 fn main() {
   tauri::Builder::default()
     .invoke_handler(tauri::generate_handler![ping])
-    .run(tauri::generate_context!(
-      "../../examples/isolation/tauri.conf.json"
-    ))
+    .run(tauri::build_script_context!())
     .expect("error while running tauri application");
 }

+ 11 - 0
examples/multiwindow/Cargo.toml

@@ -0,0 +1,11 @@
+[package]
+name = "multiwindow"
+version = "0.1.0"
+edition = "2021"
+
+[build-dependencies]
+tauri-build = { path = "../../core/tauri-build" }
+
+[dependencies]
+tauri = { path = "../../core/tauri", features = [ "window-create" ] }
+tauri-utils = { path = "../../core/tauri-utils" }

+ 3 - 0
examples/multiwindow/build.rs

@@ -0,0 +1,3 @@
+fn main() {
+  tauri_build::build();
+}

+ 1 - 3
examples/multiwindow/main.rs → examples/multiwindow/src/main.rs

@@ -28,8 +28,6 @@ fn main() {
       let _window = builder.title("Tauri - Rust").build()?;
       Ok(())
     })
-    .run(tauri::generate_context!(
-      "../../examples/multiwindow/tauri.conf.json"
-    ))
+    .run(tauri::build_script_context!())
     .expect("failed to run tauri application");
 }

+ 11 - 0
examples/navigation/Cargo.toml

@@ -0,0 +1,11 @@
+[package]
+name = "navigation"
+version = "0.1.0"
+edition = "2021"
+
+[build-dependencies]
+tauri-build = { path = "../../core/tauri-build" }
+
+[dependencies]
+tauri = { path = "../../core/tauri", features = [ "window-create" ] }
+tauri-utils = { path = "../../core/tauri-utils" }

+ 3 - 0
examples/navigation/build.rs

@@ -0,0 +1,3 @@
+fn main() {
+  tauri_build::build();
+}

+ 1 - 3
examples/helloworld/main.rs → examples/navigation/src/main.rs

@@ -6,8 +6,6 @@
 
 fn main() {
   tauri::Builder::default()
-    .run(tauri::generate_context!(
-      "../../examples/helloworld/tauri.conf.json"
-    ))
+    .run(tauri::build_script_context!())
     .expect("error while running tauri application");
 }

+ 11 - 0
examples/parent-window/Cargo.toml

@@ -0,0 +1,11 @@
+[package]
+name = "parent-window"
+version = "0.1.0"
+edition = "2021"
+
+[build-dependencies]
+tauri-build = { path = "../../core/tauri-build" }
+
+[dependencies]
+tauri = { path = "../../core/tauri" }
+tauri-utils = { path = "../../core/tauri-utils" }

+ 3 - 0
examples/parent-window/build.rs

@@ -0,0 +1,3 @@
+fn main() {
+  tauri_build::build();
+}

+ 1 - 3
examples/parent-window/main.rs → examples/parent-window/src/main.rs

@@ -36,8 +36,6 @@ fn main() {
         .build()?;
       Ok(())
     })
-    .run(tauri::generate_context!(
-      "../../examples/parent-window/tauri.conf.json"
-    ))
+    .run(tauri::build_script_context!())
     .expect("failed to run tauri application");
 }

+ 1 - 1
examples/resources/src-tauri/src/main.rs

@@ -37,6 +37,6 @@ fn main() {
 
       Ok(())
     })
-    .run(tauri::generate_context!())
+    .run(tauri::build_script_context!())
     .expect("error while running tauri application");
 }

+ 1 - 1
examples/sidecar/src-tauri/src/main.rs

@@ -36,6 +36,6 @@ fn main() {
 
       Ok(())
     })
-    .run(tauri::generate_context!())
+    .run(tauri::build_script_context!())
     .expect("error while running tauri application");
 }

+ 11 - 0
examples/splashscreen/Cargo.toml

@@ -0,0 +1,11 @@
+[package]
+name = "splashscreen"
+version = "0.1.0"
+edition = "2021"
+
+[build-dependencies]
+tauri-build = { path = "../../core/tauri-build" }
+
+[dependencies]
+tauri = { path = "../../core/tauri" }
+tauri-utils = { path = "../../core/tauri-utils" }

+ 3 - 0
examples/splashscreen/build.rs

@@ -0,0 +1,3 @@
+fn main() {
+  tauri_build::build();
+}

+ 1 - 1
examples/splashscreen/main.rs → examples/splashscreen/src/main.rs

@@ -83,7 +83,7 @@ mod ui {
 }
 
 fn context() -> tauri::Context<tauri::utils::assets::EmbeddedAssets> {
-  tauri::generate_context!("../../examples/splashscreen/tauri.conf.json")
+  tauri::build_script_context!()
 }
 
 fn main() {

+ 11 - 0
examples/state/Cargo.toml

@@ -0,0 +1,11 @@
+[package]
+name = "state"
+version = "0.1.0"
+edition = "2021"
+
+[build-dependencies]
+tauri-build = { path = "../../core/tauri-build" }
+
+[dependencies]
+tauri = { path = "../../core/tauri" }
+tauri-utils = { path = "../../core/tauri-utils" }

+ 3 - 0
examples/state/build.rs

@@ -0,0 +1,3 @@
+fn main() {
+  tauri_build::build();
+}

+ 1 - 3
examples/state/main.rs → examples/state/src/main.rs

@@ -78,8 +78,6 @@ fn main() {
       disconnect,
       connection_send
     ])
-    .run(tauri::generate_context!(
-      "../../examples/state/tauri.conf.json"
-    ))
+    .run(tauri::build_script_context!())
     .expect("error while running tauri application");
 }

+ 12 - 0
examples/streaming/Cargo.toml

@@ -0,0 +1,12 @@
+[package]
+name = "streaming"
+version = "0.1.0"
+edition = "2021"
+
+[build-dependencies]
+tauri-build = { path = "../../core/tauri-build" }
+
+[dependencies]
+percent-encoding = "2"
+tauri = { path = "../../core/tauri" }
+tauri-utils = { path = "../../core/tauri-utils" }

+ 3 - 0
examples/streaming/build.rs

@@ -0,0 +1,3 @@
+fn main() {
+  tauri_build::build();
+}

+ 1 - 3
examples/streaming/main.rs → examples/streaming/src/main.rs

@@ -107,9 +107,7 @@ fn main() {
 
       response.mimetype("video/mp4").status(status_code).body(buf)
     })
-    .run(tauri::generate_context!(
-      "../../examples/streaming/tauri.conf.json"
-    ))
+    .run(tauri::build_script_context!())
     .expect("error while running tauri application");
 }
 

+ 1 - 1
examples/tauri-dynamic-lib/src-tauri/src/lib.rs

@@ -10,6 +10,6 @@
 #[no_mangle]
 pub extern "C" fn run_tauri() {
   tauri::Builder::default()
-    .run(tauri::generate_context!("./tauri.conf.json"))
+    .run(tauri::build_script_context!())
     .expect("error while running tauri application");
 }

+ 1 - 1
examples/updater/src-tauri/src/main.rs

@@ -12,6 +12,6 @@ fn my_custom_command(argument: String) {
 fn main() {
   tauri::Builder::default()
     .invoke_handler(tauri::generate_handler![my_custom_command])
-    .run(tauri::generate_context!())
+    .run(tauri::build_script_context!())
     .expect("error while running tauri application");
 }

+ 1 - 1
examples/web/core/tauri/src/main.rs

@@ -12,6 +12,6 @@ fn greet(window: tauri::Window, name: String) {
 fn main() {
   tauri::Builder::default()
     .invoke_handler(tauri::generate_handler![greet])
-    .run(tauri::generate_context!())
+    .run(tauri::build_script_context!())
     .expect("error while running tauri application");
 }

+ 1 - 1
examples/workspace/src-tauri/src/main.rs

@@ -7,6 +7,6 @@
 fn main() {
   core_api::run();
   tauri::Builder::default()
-    .run(tauri::generate_context!())
+    .run(tauri::build_script_context!())
     .expect("error while running tauri application");
 }

+ 1 - 1
tooling/bench/tests/cpu_intensive/src-tauri/src/main.rs

@@ -12,6 +12,6 @@ fn app_completed_successfully() {
 fn main() {
   tauri::Builder::default()
     .invoke_handler(tauri::generate_handler![app_completed_successfully])
-    .run(tauri::generate_context!())
+    .run(tauri::build_script_context!())
     .expect("error while running tauri application");
 }

+ 1 - 1
tooling/bench/tests/files_transfer/src-tauri/src/main.rs

@@ -12,6 +12,6 @@ fn app_should_close(exit_code: i32) {
 fn main() {
   tauri::Builder::default()
     .invoke_handler(tauri::generate_handler![app_should_close])
-    .run(tauri::generate_context!())
+    .run(tauri::build_script_context!())
     .expect("error while running tauri application");
 }

+ 1 - 1
tooling/bench/tests/helloworld/src-tauri/src/main.rs

@@ -12,6 +12,6 @@ fn app_loaded_successfully() {
 fn main() {
   tauri::Builder::default()
     .invoke_handler(tauri::generate_handler![app_loaded_successfully])
-    .run(tauri::generate_context!())
+    .run(tauri::build_script_context!())
     .expect("error while running tauri application");
 }

+ 1 - 1
tooling/cli/node/test/jest/fixtures/app/src-tauri/src/main.rs

@@ -19,6 +19,6 @@ fn main() {
       window.eval("window.onTauriInit()").unwrap();
     })
     .invoke_handler(tauri::generate_handler![exit])
-    .run(tauri::generate_context!())
+    .run(tauri::build_script_context!())
     .expect("error encountered while running tauri application");
 }

+ 1 - 1
tooling/cli/templates/app/src-tauri/src/lib.rs

@@ -1,6 +1,6 @@
 #[cfg_attr(mobile, tauri::mobile_entry_point)]
 pub fn run() {
   tauri::Builder::default()
-    .run(tauri::generate_context!())
+    .run(tauri::build_script_context!())
     .expect("error while running tauri application");
 }

+ 1 - 1
tooling/cli/templates/plugin/__example-api/tauri-app/src-tauri/src/main.rs

@@ -11,6 +11,6 @@ fn main() {
     tauri::Builder::default()
         .invoke_handler(tauri::generate_handler![greet])
         .plugin(tauri_plugin_{{ plugin_name_snake_case }}::init())
-        .run(tauri::generate_context!())
+        .run(tauri::build_script_context!())
         .expect("error while running tauri application");
 }

+ 1 - 1
tooling/cli/templates/plugin/__example-basic/vanilla/src-tauri/src/main.rs

@@ -4,6 +4,6 @@
 fn main() {
   tauri::Builder::default()
     .plugin(tauri_plugin_{{ plugin_name_snake_case }}::init())
-    .run(tauri::generate_context!())
+    .run(tauri::build_script_context!())
     .expect("error while running tauri application");
 }