Files
tauri-plugins-workspace/plugins/geolocation/src/lib.rs
T
TonyandGitHub f8053e659e docs: cargo features (#3527)
* dialog

* fs

* geolocation

* haptic

* log

* single instance

* notification

* updater

* ##

* persisted scopes

* stronghold

* sql

* upload

* websocket

* http
(this one was too long that I generated through codex, didn't review yet)

* add change file

* no persisted-scope-js

* add `://`

* Merge branch 'v2' into document-cargo-features

* update system-proxy docs

* finish http docs

* notification doesn't need version bumps

* clean up docs
2026-08-05 15:48:11 +08:00

65 lines
1.7 KiB
Rust

// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
//! Access device geolocation APIs.
//!
//! ## Cargo features
//!
//! - **specta**: Add support for [`specta::specta`](https://docs.rs/specta/2.0.0-rc.25/specta/attr.specta.html) on structs like [`PermissionStatus`], [`PositionOptions`].
use tauri::{
plugin::{Builder, TauriPlugin},
Manager, Runtime,
};
pub use models::*;
#[cfg(desktop)]
mod desktop;
#[cfg(mobile)]
mod mobile;
mod commands;
mod error;
mod models;
pub use error::{Error, Result};
#[cfg(desktop)]
pub use desktop::Geolocation;
#[cfg(mobile)]
pub use mobile::Geolocation;
/// Extensions to [`tauri::App`], [`tauri::AppHandle`], [`tauri::WebviewWindow`], [`tauri::Webview`] and [`tauri::Window`] to access the geolocation APIs.
pub trait GeolocationExt<R: Runtime> {
fn geolocation(&self) -> &Geolocation<R>;
}
impl<R: Runtime, T: Manager<R>> crate::GeolocationExt<R> for T {
fn geolocation(&self) -> &Geolocation<R> {
self.state::<Geolocation<R>>().inner()
}
}
/// Initializes the plugin.
pub fn init<R: Runtime>() -> TauriPlugin<R> {
Builder::new("geolocation")
.invoke_handler(tauri::generate_handler![
commands::get_current_position,
commands::watch_position,
commands::clear_watch,
commands::check_permissions,
commands::request_permissions
])
.setup(|app, api| {
#[cfg(mobile)]
let geolocation = mobile::init(app, api)?;
#[cfg(desktop)]
let geolocation = desktop::init(app, api)?;
app.manage(geolocation);
Ok(())
})
.build()
}