pytauri_core/plugins/shell/
mod.rs1use std::{
2 error::Error,
3 fmt::{Debug, Display, Formatter},
4};
5
6use pyo3::{exceptions::PyRuntimeError, prelude::*};
7use tauri_plugin_shell::{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 match value.0 {
25 plugin::Error::Io(e) => e.into(),
26 plugin::Error::Utf8(e) => e.into(),
27 e @ (plugin::Error::CurrentExeHasNoParent
28 | plugin::Error::UnknownProgramName(_)
29 | plugin::Error::Scope(_)
30 | plugin::Error::SidecarNotAllowed(_)
31 | plugin::Error::ProgramNotAllowed(_)
32 | plugin::Error::UnknownEncoding(_)
33 | plugin::Error::Json(_)) => PyRuntimeError::new_err(e.to_string()),
34 }
35 }
36}
37
38impl From<plugin::Error> for PluginError {
39 fn from(value: plugin::Error) -> Self {
40 Self(value)
41 }
42}
43
44#[pyfunction]
46pub fn init() -> Plugin {
47 Plugin::new(Box::new(|| Box::new(plugin::init::<Runtime>())))
48}
49
50#[pymodule(submodule, gil_used = false)]
52pub mod shell {
53 #[pymodule_export]
54 pub use super::init;
55}