@@ -484,10 +484,16 @@ impl<R: Runtime> AppHandle<R> {
484
484
/// Ok(())
485
485
/// });
486
486
/// ```
487
- #[ cfg_attr( feature = "tracing" , tracing:: instrument( name = "app::plugin::register" , skip( plugin) , fields( name = plugin. name( ) ) ) ) ]
488
487
pub fn plugin < P : Plugin < R > + ' static > ( & self , plugin : P ) -> crate :: Result < ( ) > {
489
- let mut plugin = Box :: new ( plugin) as Box < dyn Plugin < R > > ;
488
+ self . plugin_boxed ( Box :: new ( plugin) )
489
+ }
490
490
491
+ /// Adds a Tauri application plugin.
492
+ ///
493
+ /// This method is similar to [`Self::plugin`],
494
+ /// but accepts a boxed trait object instead of a generic type.
495
+ #[ cfg_attr( feature = "tracing" , tracing:: instrument( name = "app::plugin::register" , skip( plugin) , fields( name = plugin. name( ) ) ) ) ]
496
+ pub fn plugin_boxed ( & self , mut plugin : Box < dyn Plugin < R > > ) -> crate :: Result < ( ) > {
491
497
let mut store = self . manager ( ) . plugins . lock ( ) . unwrap ( ) ;
492
498
store. initialize ( & mut plugin, self , & self . config ( ) . plugins ) ?;
493
499
store. register ( plugin) ;
@@ -1683,8 +1689,17 @@ tauri::Builder::default()
1683
1689
/// .plugin(plugin::init());
1684
1690
/// ```
1685
1691
#[ must_use]
1686
- pub fn plugin < P : Plugin < R > + ' static > ( mut self , plugin : P ) -> Self {
1687
- self . plugins . register ( Box :: new ( plugin) ) ;
1692
+ pub fn plugin < P : Plugin < R > + ' static > ( self , plugin : P ) -> Self {
1693
+ self . plugin_boxed ( Box :: new ( plugin) )
1694
+ }
1695
+
1696
+ /// Adds a Tauri application plugin.
1697
+ ///
1698
+ /// This method is similar to [`Self::plugin`],
1699
+ /// but accepts a boxed trait object instead of a generic type.
1700
+ #[ must_use]
1701
+ pub fn plugin_boxed ( mut self , plugin : Box < dyn Plugin < R > > ) -> Self {
1702
+ self . plugins . register ( plugin) ;
1688
1703
self
1689
1704
}
1690
1705
0 commit comments