Skip to main content

tauri_plugin_material_you/
lib.rs

1use tauri::{
2    plugin::{Builder, TauriPlugin},
3    Runtime,
4};
5
6#[cfg(target_os = "android")]
7use tauri::Manager;
8
9pub use models::*;
10
11#[cfg(target_os = "android")]
12mod commands;
13#[cfg(target_os = "android")]
14mod mobile;
15
16mod error;
17mod models;
18
19pub use error::{Error, Result};
20
21#[cfg(target_os = "android")]
22use mobile::MaterialYou;
23
24/// Extensions to [`tauri::App`], [`tauri::AppHandle`] and [`tauri::Window`] to access the material-you APIs.
25#[cfg(target_os = "android")]
26pub trait MaterialYouExt<R: Runtime> {
27    fn material_you(&self) -> &MaterialYou<R>;
28}
29
30#[cfg(target_os = "android")]
31impl<R: Runtime, T: tauri::Manager<R>> MaterialYouExt<R> for T {
32    fn material_you(&self) -> &MaterialYou<R> {
33        self.state::<MaterialYou<R>>().inner()
34    }
35}
36
37/// Initializes the plugin.
38pub fn init<R: Runtime>() -> TauriPlugin<R> {
39    let builder = Builder::new("material-you");
40
41    #[cfg(target_os = "android")]
42    let builder = builder
43        .invoke_handler(tauri::generate_handler![commands::get_material_you_colours])
44        .setup(|app, api| {
45            let material_you = mobile::init(api, app)?;
46            app.manage(material_you);
47            Ok(())
48        });
49
50    #[cfg(not(target_os = "android"))]
51    let builder = builder.setup(|_, _| Ok(()));
52
53    builder.build()
54}