mirror of
https://github.com/tauri-apps/tauri.git
synced 2026-04-01 10:01:07 +02:00
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]
This commit is contained in:
committed by
GitHub
parent
26c6a832bf
commit
5110c704be
7
.changes/assets-refactor.md
Normal file
7
.changes/assets-refactor.md
Normal file
@@ -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>`.
|
||||
@@ -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,
|
||||
|
||||
@@ -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>>,
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user