pytauri_core/plugins/clipboard_manager/
mod.rs

1use std::{
2    error::Error,
3    fmt::{Debug, Display, Formatter},
4};
5
6use pyo3::{exceptions::PyRuntimeError, prelude::*};
7use tauri_plugin_clipboard_manager::{self as plugin};
8
9use crate::{ext_mod::plugin::Plugin, tauri_runtime::Runtime, utils::TauriError};
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        match value.0 {
25            plugin::Error::Tauri(e) => TauriError::from(e).into(),
26            e @ plugin::Error::Clipboard(_) => PyRuntimeError::new_err(e.to_string()),
27        }
28    }
29}
30
31impl From<plugin::Error> for PluginError {
32    fn from(value: plugin::Error) -> Self {
33        Self(value)
34    }
35}
36
37/// See also: [tauri_plugin_clipboard_manager::init]
38#[pyfunction]
39pub fn init() -> Plugin {
40    Plugin::new(Box::new(|| Box::new(plugin::init::<Runtime>())))
41}
42
43/// See also: [tauri_plugin_clipboard_manager]
44#[pymodule(submodule, gil_used = false)]
45pub mod clipboard_manager {
46    #[pymodule_export]
47    pub use super::init;
48}