Kaynağa Gözat

feat(core): allow users to access the Assets instance (#1691)

* feat(core): allow users to access the Assets instance

* chore(changes): mark as breaking change [skip ci]
Lucas Fernandes Nogueira 4 yıl önce
ebeveyn
işleme
5110c704be

+ 7 - 0
.changes/assets-refactor.md

@@ -0,0 +1,7 @@
+---
+"tauri-codegen": patch
+"tauri-utils": patch
+"tauri": patch
+---
+
+**Breaking:** The `assets` field on the `tauri::Context` struct is now a `Arc<impl Assets>`.

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

@@ -72,7 +72,7 @@ pub fn context_codegen(data: ContextData) -> Result<TokenStream, EmbeddedAssetsE
   // double braces are purposeful to force the code into a block expression
   Ok(quote!(#root::Context {
     config: #config,
-    assets: #assets,
+    assets: ::std::sync::Arc::new(#assets),
     default_window_icon: #default_window_icon,
     package_info: #root::api::PackageInfo {
       name: #package_name,

+ 6 - 4
core/tauri/src/lib.rs

@@ -39,7 +39,6 @@ pub type Result<T> = std::result::Result<T, Error>;
 pub type SyncTask = Box<dyn FnOnce() + Send>;
 
 use crate::{
-  api::{assets::Assets, config::Config},
   event::{Event, EventHandler},
   runtime::{
     tag::{Tag, TagRef},
@@ -48,11 +47,14 @@ use crate::{
   },
 };
 use serde::Serialize;
-use std::{borrow::Borrow, collections::HashMap, path::PathBuf};
+use std::{borrow::Borrow, collections::HashMap, path::PathBuf, sync::Arc};
 
 // Export types likely to be used by the application.
 pub use {
-  self::api::config::WindowUrl,
+  self::api::{
+    assets::Assets,
+    config::{Config, WindowUrl},
+  },
   self::hooks::{
     Invoke, InvokeError, InvokeHandler, InvokeMessage, InvokeResolver, InvokeResponse, OnPageLoad,
     PageLoadPayload, SetupHook,
@@ -113,7 +115,7 @@ pub struct Context<A: Assets> {
   pub config: Config,
 
   /// The assets to be served directly by Tauri.
-  pub assets: A,
+  pub assets: Arc<A>,
 
   /// The default window icon Tauri should use when creating windows.
   pub default_window_icon: Option<Vec<u8>>,

+ 1 - 1
core/tauri/src/runtime/manager.rs

@@ -134,7 +134,7 @@ impl<P: Params> WindowManager<P> {
         invoke_handler,
         on_page_load,
         config: context.config,
-        assets: Arc::new(context.assets),
+        assets: context.assets,
         default_window_icon: context.default_window_icon,
         salts: Mutex::default(),
         package_info: context.package_info,