Skip to content

Commit 5110c70

Browse files
authored
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]
1 parent 26c6a83 commit 5110c70

File tree

4 files changed

+15
-6
lines changed

4 files changed

+15
-6
lines changed

.changes/assets-refactor.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"tauri-codegen": patch
3+
"tauri-utils": patch
4+
"tauri": patch
5+
---
6+
7+
**Breaking:** The `assets` field on the `tauri::Context` struct is now a `Arc<impl Assets>`.

core/tauri-codegen/src/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ pub fn context_codegen(data: ContextData) -> Result<TokenStream, EmbeddedAssetsE
7272
// double braces are purposeful to force the code into a block expression
7373
Ok(quote!(#root::Context {
7474
config: #config,
75-
assets: #assets,
75+
assets: ::std::sync::Arc::new(#assets),
7676
default_window_icon: #default_window_icon,
7777
package_info: #root::api::PackageInfo {
7878
name: #package_name,

core/tauri/src/lib.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ pub type Result<T> = std::result::Result<T, Error>;
3939
pub type SyncTask = Box<dyn FnOnce() + Send>;
4040

4141
use crate::{
42-
api::{assets::Assets, config::Config},
4342
event::{Event, EventHandler},
4443
runtime::{
4544
tag::{Tag, TagRef},
@@ -48,11 +47,14 @@ use crate::{
4847
},
4948
};
5049
use serde::Serialize;
51-
use std::{borrow::Borrow, collections::HashMap, path::PathBuf};
50+
use std::{borrow::Borrow, collections::HashMap, path::PathBuf, sync::Arc};
5251

5352
// Export types likely to be used by the application.
5453
pub use {
55-
self::api::config::WindowUrl,
54+
self::api::{
55+
assets::Assets,
56+
config::{Config, WindowUrl},
57+
},
5658
self::hooks::{
5759
Invoke, InvokeError, InvokeHandler, InvokeMessage, InvokeResolver, InvokeResponse, OnPageLoad,
5860
PageLoadPayload, SetupHook,
@@ -113,7 +115,7 @@ pub struct Context<A: Assets> {
113115
pub config: Config,
114116

115117
/// The assets to be served directly by Tauri.
116-
pub assets: A,
118+
pub assets: Arc<A>,
117119

118120
/// The default window icon Tauri should use when creating windows.
119121
pub default_window_icon: Option<Vec<u8>>,

core/tauri/src/runtime/manager.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ impl<P: Params> WindowManager<P> {
134134
invoke_handler,
135135
on_page_load,
136136
config: context.config,
137-
assets: Arc::new(context.assets),
137+
assets: context.assets,
138138
default_window_icon: context.default_window_icon,
139139
salts: Mutex::default(),
140140
package_info: context.package_info,

0 commit comments

Comments
 (0)