pytauri_core/plugins/deep_link/
mod.rs

1use std::{
2    error::Error,
3    fmt::{Debug, Display, Formatter},
4};
5
6use pyo3::{exceptions::PyRuntimeError, prelude::*};
7use tauri_plugin_deep_link::{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            e @ plugin::Error::UnsupportedPlatform => PyRuntimeError::new_err(e.to_string()),
26            plugin::Error::Io(e) => e.into(),
27            plugin::Error::Tauri(e) => TauriError::from(e).into(),
28            #[cfg(target_os = "windows")]
29            e @ plugin::Error::Windows(_) => PyRuntimeError::new_err(e.to_string()),
30            #[cfg(target_os = "linux")]
31            e @ (plugin::Error::Ini(_) | plugin::Error::ParseIni(_)) => {
32                PyRuntimeError::new_err(e.to_string())
33            }
34            #[cfg(any(target_os = "ios", target_os = "android"))]
35            e @ plugin::Error::PluginInvoke(_) => PyRuntimeError::new_err(e.to_string()),
36        }
37    }
38}
39
40impl From<plugin::Error> for PluginError {
41    fn from(value: plugin::Error) -> Self {
42        Self(value)
43    }
44}
45
46/// See also: [tauri_plugin_deep_link::init]
47#[pyfunction]
48pub fn init() -> Plugin {
49    Plugin::new(Box::new(|| Box::new(plugin::init::<Runtime>())))
50}
51
52/// See also: [tauri_plugin_deep_link]
53#[pymodule(submodule, gil_used = false)]
54pub mod deep_link {
55    #[pymodule_export]
56    pub use super::init;
57}