Skip to main content

tauri_plugin_system_components/
lib.rs

1//! Native system UI components for Tauri 2.
2//!
3//! - **iOS**: a native `UITabBar` overlaid on the webview — it adopts Liquid
4//!   Glass automatically when the app is built with Xcode 26 against the
5//!   iOS 26 SDK, and refracts the web content rendered behind it. Tab taps
6//!   are forwarded to JS as `tabSelected` events.
7//! - **macOS**: a glass window background via `NSGlassEffectView` (macOS 26),
8//!   with an `NSVisualEffectView` blur fallback on older systems.
9
10use tauri::{
11    plugin::{Builder, TauriPlugin},
12    Manager, Runtime,
13};
14
15pub use models::*;
16
17#[cfg(desktop)]
18mod desktop;
19#[cfg(mobile)]
20mod mobile;
21
22mod commands;
23mod error;
24mod models;
25
26pub use error::{Error, Result};
27
28#[cfg(desktop)]
29use desktop::SystemComponents;
30#[cfg(mobile)]
31use mobile::SystemComponents;
32
33/// Extensions to [`tauri::App`], [`tauri::AppHandle`] and [`tauri::Window`] to access the system-components APIs.
34pub trait SystemComponentsExt<R: Runtime> {
35    fn system_components(&self) -> &SystemComponents<R>;
36}
37
38impl<R: Runtime, T: Manager<R>> crate::SystemComponentsExt<R> for T {
39    fn system_components(&self) -> &SystemComponents<R> {
40        self.state::<SystemComponents<R>>().inner()
41    }
42}
43
44/// Initializes the plugin. Call this from your Tauri app's `lib.rs`:
45///
46/// ```ignore
47/// .plugin(tauri_plugin_system_components::init())
48/// ```
49pub fn init<R: Runtime>() -> TauriPlugin<R> {
50    Builder::new("system-components")
51        .invoke_handler(tauri::generate_handler![
52            commands::configure_tab_bar,
53            commands::remove_tab_bar,
54            commands::show_tab_bar,
55            commands::hide_tab_bar,
56            commands::select_tab,
57            commands::set_badge,
58            commands::get_tab_bar_insets,
59            commands::present_sheet,
60            commands::dismiss_sheet,
61            commands::create_component,
62            commands::update_component,
63            commands::update_components,
64            commands::remove_component,
65            commands::is_glass_supported,
66            commands::set_window_glass,
67            commands::clear_window_glass,
68        ])
69        .setup(|app, api| {
70            #[cfg(mobile)]
71            let system_components = mobile::init(app, api)?;
72            #[cfg(desktop)]
73            let system_components = desktop::init(app, api)?;
74            app.manage(system_components);
75            Ok(())
76        })
77        .build()
78}