瀏覽代碼

feat(core): finish mutable getters for `Context` (#1814)

chip 4 年之前
父節點
當前提交
754c2e766a
共有 2 個文件被更改,包括 34 次插入1 次删除
  1. 9 0
      .changes/context-mutable-methods.md
  2. 25 1
      core/tauri/src/lib.rs

+ 9 - 0
.changes/context-mutable-methods.md

@@ -0,0 +1,9 @@
+---
+"tauri": patch
+---
+
+Expose mutable getters for the rest of the public `Context` getters.
+* `pub fn assets_mut(&mut self) -> &mut Arc<A>`
+* `pub fn default_window_icon_mut(&mut self) -> &mut Option<Vec<u8>>`
+* `pub fn system_tray_icon_mut(&mut self) -> &mut Option<Icon>`
+* `pub fn package_info_mut(&mut self) -> &mut tauri::api::PackageInfo`

+ 25 - 1
core/tauri/src/lib.rs

@@ -154,24 +154,48 @@ impl<A: Assets> Context<A> {
     self.assets.clone()
   }
 
+  /// A mutable reference to the assets to be served directly by Tauri.
+  #[inline(always)]
+  pub fn assets_mut(&mut self) -> &mut Arc<A> {
+    &mut self.assets
+  }
+
   /// The default window icon Tauri should use when creating windows.
   #[inline(always)]
   pub fn default_window_icon(&self) -> Option<&[u8]> {
     self.default_window_icon.as_deref()
   }
 
-  /// The icon to use use on the system tray UI.
+  /// A mutable reference to the default window icon Tauri should use when creating windows.
+  #[inline(always)]
+  pub fn default_window_icon_mut(&mut self) -> &mut Option<Vec<u8>> {
+    &mut self.default_window_icon
+  }
+
+  /// The icon to use on the system tray UI.
   #[inline(always)]
   pub fn system_tray_icon(&self) -> Option<&Icon> {
     self.system_tray_icon.as_ref()
   }
 
+  /// A mutable reference to the icon to use on the system tray UI.
+  #[inline(always)]
+  pub fn system_tray_icon_mut(&mut self) -> &mut Option<Icon> {
+    &mut self.system_tray_icon
+  }
+
   /// Package information.
   #[inline(always)]
   pub fn package_info(&self) -> &crate::api::PackageInfo {
     &self.package_info
   }
 
+  /// A mutable reference to the package information.
+  #[inline(always)]
+  pub fn package_info_mut(&mut self) -> &mut crate::api::PackageInfo {
+    &mut self.package_info
+  }
+
   /// Create a new [`Context`] from the minimal required items.
   #[inline(always)]
   pub fn new(