tauri_plugin_widget/
lib.rs1use tauri::{
2 plugin::{Builder, TauriPlugin},
3 Manager, Runtime,
4};
5
6#[cfg(desktop)]
7mod desktop;
8#[cfg(mobile)]
9mod mobile;
10
11mod commands;
12mod error;
13mod model;
14
15pub use error::{Error, Result};
16
17#[cfg(desktop)]
18use desktop::Widget;
19#[cfg(mobile)]
20use mobile::Widget;
21
22pub trait WidgetExt<R: Runtime> {
23 fn widget(&self) -> &Widget<R>;
24}
25
26impl<R: Runtime, T: Manager<R>> crate::WidgetExt<R> for T {
27 fn widget(&self) -> &Widget<R> {
28 self.state::<Widget<R>>().inner()
29 }
30}
31
32pub fn init<R: Runtime>() -> TauriPlugin<R> {
34 Builder::new("widget")
35 .invoke_handler(tauri::generate_handler![
36 commands::set_register_widget,
37 commands::set_items,
38 commands::get_items,
39 commands::reload_all_time_lines,
40 commands::reload_time_lines,
41 commands::request_widget
42 ])
43 .setup(|app, api| {
44 #[cfg(mobile)]
45 let widget = mobile::init(app, api)?;
46 #[cfg(desktop)]
47 let widget = desktop::init(app, api)?;
48 app.manage(widget);
49 Ok(())
50 })
51 .build()
52}