From 5110c704be67e51d49fb83f3710afb593973dcf9 Mon Sep 17 00:00:00 2001 From: Lucas Fernandes Nogueira Date: Mon, 3 May 2021 15:07:38 -0300 Subject: [PATCH] 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] --- .changes/assets-refactor.md | 7 +++++++ core/tauri-codegen/src/context.rs | 2 +- core/tauri/src/lib.rs | 10 ++++++---- core/tauri/src/runtime/manager.rs | 2 +- 4 files changed, 15 insertions(+), 6 deletions(-) create mode 100644 .changes/assets-refactor.md diff --git a/.changes/assets-refactor.md b/.changes/assets-refactor.md new file mode 100644 index 000000000..9fd475e1b --- /dev/null +++ b/.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`. diff --git a/core/tauri-codegen/src/context.rs b/core/tauri-codegen/src/context.rs index a0d369e70..f6e37c743 100644 --- a/core/tauri-codegen/src/context.rs +++ b/core/tauri-codegen/src/context.rs @@ -72,7 +72,7 @@ pub fn context_codegen(data: ContextData) -> Result = std::result::Result; pub type SyncTask = Box; 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 { pub config: Config, /// The assets to be served directly by Tauri. - pub assets: A, + pub assets: Arc, /// The default window icon Tauri should use when creating windows. pub default_window_icon: Option>, diff --git a/core/tauri/src/runtime/manager.rs b/core/tauri/src/runtime/manager.rs index 8713d8348..ddb2c6ffb 100644 --- a/core/tauri/src/runtime/manager.rs +++ b/core/tauri/src/runtime/manager.rs @@ -134,7 +134,7 @@ impl WindowManager

{ 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,