Skip to content

Commit

Permalink
feat(core): allow users to access the Assets instance (#1691)
Browse files Browse the repository at this point in the history
* feat(core): allow users to access the Assets instance

* chore(changes): mark as breaking change [skip ci]
  • Loading branch information
lucasfernog committed May 3, 2021
1 parent 26c6a83 commit 5110c70
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
7 changes: 7 additions & 0 deletions .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>`.
2 changes: 1 addition & 1 deletion core/tauri-codegen/src/context.rs
Expand Up @@ -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,
Expand Down
10 changes: 6 additions & 4 deletions core/tauri/src/lib.rs
Expand Up @@ -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},
Expand All @@ -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,
Expand Down Expand Up @@ -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>>,
Expand Down
2 changes: 1 addition & 1 deletion core/tauri/src/runtime/manager.rs
Expand Up @@ -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,
Expand Down

0 comments on commit 5110c70

Please sign in to comment.