Skip to main content

tauri_plugin_app_icon/
lib.rs

1use tauri::{
2    plugin::{Builder, TauriPlugin},
3    Runtime,
4};
5#[cfg(mobile)]
6use tauri::Manager;
7
8pub use models::*;
9
10pub mod commands;
11mod error;
12#[cfg(mobile)]
13mod mobile;
14mod models;
15
16pub use error::{Error, Result};
17
18#[cfg(mobile)]
19use mobile::AppIcon;
20
21#[cfg(mobile)]
22pub trait AppIconExt<R: Runtime> {
23    fn app_icon(&self) -> &AppIcon<R>;
24}
25
26#[cfg(mobile)]
27impl<R: Runtime, T: tauri::Manager<R>> crate::AppIconExt<R> for T {
28    fn app_icon(&self) -> &AppIcon<R> {
29        self.state::<AppIcon<R>>().inner()
30    }
31}
32
33pub fn init<R: Runtime>() -> TauriPlugin<R> {
34    Builder::new("app-icon")
35        .invoke_handler(tauri::generate_handler![
36            commands::is_supported,
37            commands::get_name,
38            commands::change,
39            commands::reset,
40        ])
41        .setup(|_app, api| {
42            #[cfg(mobile)]
43            {
44                let app_icon = mobile::init(_app, api)?;
45                _app.manage(app_icon);
46            }
47            Ok(())
48        })
49        .build()
50}