tauri_plugin_geolocation/
lib.rs1use tauri::{
12 Manager, Runtime,
13 plugin::{Builder, TauriPlugin},
14};
15
16pub use models::*;
17
18#[cfg(desktop)]
19mod desktop;
20#[cfg(mobile)]
21mod mobile;
22
23mod commands;
24mod error;
25mod models;
26
27pub use error::{Error, Result};
28
29#[cfg(desktop)]
30pub use desktop::Geolocation;
31#[cfg(mobile)]
32pub use mobile::Geolocation;
33
34pub trait GeolocationExt<R: Runtime> {
36 fn geolocation(&self) -> &Geolocation<R>;
38}
39
40impl<R: Runtime, T: Manager<R>> crate::GeolocationExt<R> for T {
41 fn geolocation(&self) -> &Geolocation<R> {
42 self.state::<Geolocation<R>>().inner()
43 }
44}
45
46pub fn init<R: Runtime>() -> TauriPlugin<R> {
48 Builder::new("geolocation")
49 .invoke_handler(tauri::generate_handler![
50 commands::get_current_position,
51 commands::watch_position,
52 commands::clear_watch,
53 commands::check_permissions,
54 commands::request_permissions
55 ])
56 .setup(|app, api| {
57 #[cfg(mobile)]
58 let geolocation = mobile::init(app, api)?;
59 #[cfg(desktop)]
60 let geolocation = desktop::init(app, api)?;
61 app.manage(geolocation);
62 Ok(())
63 })
64 .build()
65}