pytauri_core/ext_mod_impl/
plugin.rs1use pyo3::prelude::*;
2use pyo3_utils::py_wrapper::{ConsumedResult, LockResult, PyWrapper, PyWrapperT2};
3use tauri::plugin;
4
5use crate::tauri_runtime::Runtime;
6
7type BoxedPlugin = Box<dyn plugin::Plugin<Runtime>>;
8type PluginFactory = Box<dyn FnOnce() -> BoxedPlugin + Send + Sync>;
9
10#[pyclass(frozen)]
12#[non_exhaustive]
13pub struct Plugin(PyWrapper<PyWrapperT2<PluginFactory>>);
14
15impl Plugin {
16 pub fn new(plugin_fn: PluginFactory) -> Self {
17 Self(PyWrapper::new2(plugin_fn))
18 }
19
20 pub fn into_tauri(&self) -> LockResult<ConsumedResult<BoxedPlugin>> {
24 self.0
25 .try_take_inner()
26 .map(|inner| inner.map(|plugin_fn| plugin_fn()))
27 }
28}