mirror of
https://github.com/tauri-apps/tauri.git
synced 2026-04-01 10:01:07 +02:00
feat(tauri): add plugin_boxed methods (#13837)
* feat(tauri): add `plugin_dyn` methods * refactor: rename `plugin_dyn` to `plugin_boxed`
This commit is contained in:
5
.changes/plugin-boxed.md
Normal file
5
.changes/plugin-boxed.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
tauri: "minor:enhance"
|
||||
---
|
||||
|
||||
Add `AppHandle::plugin_boxed` and `Builder::plugin_boxed` methods to allow adding plugins in the form of boxed trait objects.
|
||||
@@ -484,10 +484,16 @@ impl<R: Runtime> AppHandle<R> {
|
||||
/// Ok(())
|
||||
/// });
|
||||
/// ```
|
||||
#[cfg_attr(feature = "tracing", tracing::instrument(name = "app::plugin::register", skip(plugin), fields(name = plugin.name())))]
|
||||
pub fn plugin<P: Plugin<R> + 'static>(&self, plugin: P) -> crate::Result<()> {
|
||||
let mut plugin = Box::new(plugin) as Box<dyn Plugin<R>>;
|
||||
self.plugin_boxed(Box::new(plugin))
|
||||
}
|
||||
|
||||
/// Adds a Tauri application plugin.
|
||||
///
|
||||
/// This method is similar to [`Self::plugin`],
|
||||
/// but accepts a boxed trait object instead of a generic type.
|
||||
#[cfg_attr(feature = "tracing", tracing::instrument(name = "app::plugin::register", skip(plugin), fields(name = plugin.name())))]
|
||||
pub fn plugin_boxed(&self, mut plugin: Box<dyn Plugin<R>>) -> crate::Result<()> {
|
||||
let mut store = self.manager().plugins.lock().unwrap();
|
||||
store.initialize(&mut plugin, self, &self.config().plugins)?;
|
||||
store.register(plugin);
|
||||
@@ -1683,8 +1689,17 @@ tauri::Builder::default()
|
||||
/// .plugin(plugin::init());
|
||||
/// ```
|
||||
#[must_use]
|
||||
pub fn plugin<P: Plugin<R> + 'static>(mut self, plugin: P) -> Self {
|
||||
self.plugins.register(Box::new(plugin));
|
||||
pub fn plugin<P: Plugin<R> + 'static>(self, plugin: P) -> Self {
|
||||
self.plugin_boxed(Box::new(plugin))
|
||||
}
|
||||
|
||||
/// Adds a Tauri application plugin.
|
||||
///
|
||||
/// This method is similar to [`Self::plugin`],
|
||||
/// but accepts a boxed trait object instead of a generic type.
|
||||
#[must_use]
|
||||
pub fn plugin_boxed(mut self, plugin: Box<dyn Plugin<R>>) -> Self {
|
||||
self.plugins.register(plugin);
|
||||
self
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user