pytauri_core/plugins/os/
mod.rs

1use std::{
2    error::Error,
3    fmt::{Debug, Display, Formatter},
4};
5
6use pyo3::prelude::*;
7use tauri_plugin_os::{self as plugin};
8
9use crate::{ext_mod::plugin::Plugin, tauri_runtime::Runtime};
10
11#[derive(Debug)]
12struct PluginError(plugin::Error);
13
14impl Display for PluginError {
15    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
16        Display::fmt(&self.0, f)
17    }
18}
19
20impl Error for PluginError {}
21
22impl From<PluginError> for PyErr {
23    fn from(value: PluginError) -> Self {
24        // Since tauri_plugin_os::Error is an empty enum,
25        // this match is unreachable but we keep it for consistency
26        match value.0 {}
27    }
28}
29
30impl From<plugin::Error> for PluginError {
31    fn from(value: plugin::Error) -> Self {
32        Self(value)
33    }
34}
35
36/// See also: [tauri_plugin_os::init]
37#[pyfunction]
38pub fn init() -> Plugin {
39    Plugin::new(Box::new(|| Box::new(plugin::init::<Runtime>())))
40}
41
42/// See also: [tauri_plugin_os]
43#[pymodule(submodule, gil_used = false)]
44pub mod os {
45    #[pymodule_export]
46    pub use super::init;
47}