pytauri_core/
lib.rs

1// See: <https://doc.rust-lang.org/rustdoc/unstable-features.html#extensions-to-the-doc-attribute>
2#![cfg_attr(
3    docsrs,
4    feature(doc_cfg, doc_auto_cfg, doc_cfg_hide),
5    doc(cfg_hide(doc))
6)]
7
8mod ext_mod_impl;
9mod plugins;
10pub mod tauri_runtime;
11pub mod utils;
12
13use pyo3::prelude::*;
14
15pub use plugins::pytauri_plugins;
16
17/// See also: [tauri]
18///
19/// You can access this module in Python via `pytuari.EXT_MOD.pytuari`.
20#[pymodule(submodule, gil_used = false, name = "pytauri")]
21pub mod ext_mod {
22    use super::*;
23
24    #[pymodule_export]
25    pub use ext_mod_impl::lib::{
26        app::App,
27        app_handle::AppHandle,
28        context::Context,
29        emitter::Emitter,
30        event::{Event, EventTarget},
31        listener::Listener,
32        manager::Manager,
33        rect::{LogicalRect, PhysicalRect, Position, Rect, Size},
34        run_event::{
35            CloseRequestApi, DragDropEvent, ExitRequestApi, RunEvent, WebviewEvent, WindowEvent,
36        },
37        runtime::{CursorIcon, Theme, UserAttentionType},
38        url::WebviewUrl,
39        webview_version,
40    };
41    // TODO: constants defined outside a module and then re-exported are not supported,
42    // see <https://github.com/PyO3/pyo3/pull/5150#issuecomment-2889031243>.
43    #[pymodule_export]
44    pub const RESTART_EXIT_CODE: i32 = ext_mod_impl::lib::RESTART_EXIT_CODE;
45    #[pymodule_export]
46    pub const VERSION: &str = ext_mod_impl::lib::VERSION;
47    #[pymodule_export]
48    pub const IS_DEV: bool = ext_mod_impl::lib::IS_DEV;
49
50    pub use ext_mod_impl::lib::{
51        app_handle::{PyAppHandleExt, PyAppHandleStateError, PyAppHandleStateResult},
52        emitter::ImplEmitter,
53        event::EventId,
54        listener::ImplListener,
55        manager::ImplManager,
56        url::Url,
57    };
58
59    pub(crate) use ext_mod_impl::lib::{
60        app::TauriApp,
61        app_handle::{debug_assert_app_handle_py_is_rs, TauriAppHandle},
62        assets::PyAssets,
63        manager::{manager_method_impl, StateManager},
64        rect::{PhysicalPositionF64, PhysicalPositionI32, PhysicalSizeU32},
65        runtime::ConfigInto,
66    };
67    #[expect(unused_imports)] // TODO
68    pub(crate) use ext_mod_impl::lib::{
69        rect::{TauriLogicalRect, TauriPhysicalRect},
70        runtime::ConfigFrom,
71    };
72
73    /// See also: [tauri::ipc]
74    #[pymodule]
75    pub mod ipc {
76        use super::*;
77
78        #[pymodule_export]
79        pub use ext_mod_impl::ipc::{Channel, Invoke, InvokeResolver, JavaScriptChannelId};
80    }
81
82    /// See also: [tauri::webview]
83    #[pymodule]
84    pub mod webview {
85        use super::*;
86
87        #[pymodule_export]
88        pub use ext_mod_impl::webview::{SameSite, Webview, WebviewWindow, WebviewWindowBuilder};
89
90        pub use ext_mod_impl::webview::{Color, Cookie, WebviewWindowBuilderArgs};
91
92        pub(crate) use ext_mod_impl::webview::TauriWebviewWindow;
93        #[expect(unused_imports)] // TODO
94        pub(crate) use ext_mod_impl::webview::{WindowConfigFrom, WindowConfigInto};
95    }
96
97    /// See also: [tauri::menu]
98    #[pymodule]
99    pub mod menu {
100        use super::*;
101
102        #[pymodule_export]
103        pub use ext_mod_impl::menu::{
104            AboutMetadata, CheckMenuItem, ContextMenu, IconMenuItem, Menu, MenuItem, NativeIcon,
105            PredefinedMenuItem, Submenu,
106        };
107
108        // TODO: constants defined outside a module and then re-exported are not supported,
109        // see <https://github.com/PyO3/pyo3/pull/5150#issuecomment-2889031243>.
110        #[pymodule_export]
111        pub const HELP_SUBMENU_ID: &str = ext_mod_impl::menu::HELP_SUBMENU_ID;
112        #[pymodule_export]
113        pub const WINDOW_SUBMENU_ID: &str = ext_mod_impl::menu::WINDOW_SUBMENU_ID;
114
115        pub use ext_mod_impl::menu::{ImplContextMenu, MenuEvent, MenuID, MenuItemKind};
116
117        pub(crate) use ext_mod_impl::menu::context_menu_impl;
118    }
119
120    /// See also: [tauri::image]
121    #[pymodule]
122    pub mod image {
123        use super::*;
124
125        #[pymodule_export]
126        pub use ext_mod_impl::image::Image;
127    }
128
129    /// See also: [tauri::window]
130    #[pymodule]
131    pub mod window {
132        use super::*;
133
134        #[pymodule_export]
135        pub use ext_mod_impl::window::{
136            Effect, EffectState, Monitor, ProgressBarStatus, TitleBarStyle, Window,
137        };
138
139        pub use ext_mod_impl::window::{Effects, ProgressBarState};
140    }
141
142    /// See also: [tauri::tray]
143    #[pymodule]
144    pub mod tray {
145        use super::*;
146
147        #[pymodule_export]
148        pub use ext_mod_impl::tray::{MouseButton, MouseButtonState, TrayIcon, TrayIconEvent};
149
150        pub use ext_mod_impl::tray::TrayIconId;
151    }
152
153    /// See also: [tauri::path]
154    #[pymodule]
155    pub mod path {
156        use super::*;
157
158        #[pymodule_export]
159        pub use ext_mod_impl::path::PathResolver;
160    }
161
162    /// See also: [tauri::plugin]
163    #[pymodule]
164    pub mod plugin {
165        use super::*;
166
167        #[pymodule_export]
168        pub use ext_mod_impl::plugin::Plugin;
169    }
170}