pytauri_core/ext_mod_impl/lib/
context.rs

1use pyo3::prelude::*;
2use pyo3_utils::py_wrapper::{PyWrapper, PyWrapperT2};
3
4use crate::{ext_mod::PyAssets, tauri_runtime::Runtime};
5
6type TauriContext = tauri::Context<Runtime>;
7
8/// see also: [tauri::Context]
9#[pyclass(frozen)]
10#[non_exhaustive]
11pub struct Context(pub PyWrapper<PyWrapperT2<TauriContext>>);
12
13impl Context {
14    pub fn new(context: TauriContext) -> Self {
15        Self(PyWrapper::new2(context))
16    }
17}
18
19#[pymethods]
20impl Context {
21    fn set_assets(&self, py: Python<'_>, assets: PyObject) -> PyResult<()> {
22        py.allow_threads(|| {
23            let mut context = self.0.try_lock_inner_mut()??;
24            context.set_assets(Box::new(PyAssets(assets)));
25            Ok(())
26        })
27    }
28}