tauri_plugin_configurate/
lib.rs1use tauri::{
2 plugin::{Builder, TauriPlugin},
3 Manager, Runtime,
4};
5
6pub use models::*;
7
8#[cfg(desktop)]
9mod desktop;
10#[cfg(mobile)]
11mod mobile;
12
13mod commands;
14mod dotpath;
15mod error;
16mod keyring_store;
17mod locker;
18mod models;
19mod storage;
20mod watcher;
21
22pub use error::{Error, Result};
23
24#[cfg(desktop)]
25use desktop::Configurate;
26#[cfg(mobile)]
27use mobile::Configurate;
28
29pub trait ConfigurateExt<R: Runtime> {
32 fn configurate(&self) -> &Configurate<R>;
33}
34
35impl<R: Runtime, T: Manager<R>> crate::ConfigurateExt<R> for T {
36 fn configurate(&self) -> &Configurate<R> {
37 self.state::<Configurate<R>>().inner()
38 }
39}
40
41pub fn init<R: Runtime>() -> TauriPlugin<R> {
43 Builder::new("configurate")
44 .invoke_handler(tauri::generate_handler![
45 commands::create,
46 commands::load,
47 commands::save,
48 commands::patch,
49 commands::delete,
50 commands::exists,
51 commands::load_all,
52 commands::save_all,
53 commands::patch_all,
54 commands::unlock,
55 commands::watch_file,
56 commands::unwatch_file,
57 commands::list_configs,
58 commands::reset,
59 commands::export_config,
60 commands::import_config,
61 ])
62 .setup(|app, api| {
63 #[cfg(mobile)]
64 let configurate = mobile::init(app, api)?;
65 #[cfg(desktop)]
66 let configurate = desktop::init(app, api)?;
67 app.manage(configurate);
68 app.manage(locker::FileLockRegistry::new());
69 app.manage(std::sync::Arc::new(storage::BackupRegistry::new()));
70 let watcher_state = watcher::WatcherState::new(app.clone())?;
71 app.manage(watcher_state);
72 Ok(())
73 })
74 .on_event(|app, event| {
75 if let tauri::RunEvent::Exit = event {
76 if let Some(registry) = app.try_state::<std::sync::Arc<storage::BackupRegistry>>() {
77 registry.cleanup_all();
78 }
79 }
80 })
81 .build()
82}