chore: update documentation

This commit is contained in:
Lucas Nogueira
2026-09-22 11:30:47 -03:00
parent d869c162a7
commit a87a3c7d44
104 changed files with 4875 additions and 222 deletions
+5
View File
@@ -22,6 +22,7 @@ pub fn init<R: Runtime, C: DeserializeOwned>(
pub struct Geolocation<R: Runtime>(AppHandle<R>);
impl<R: Runtime> Geolocation<R> {
/// Not implemented on desktop platforms; always resolves to a default, zeroed [`Position`] without reading any real location.
pub fn get_current_position(
&self,
_options: Option<PositionOptions>,
@@ -29,6 +30,7 @@ impl<R: Runtime> Geolocation<R> {
Ok(Position::default())
}
/// Not implemented on desktop platforms. Registers a channel for `channel_id` bookkeeping, but `callback` is never invoked with a real [`WatchEvent`].
pub fn watch_position<F: Fn(WatchEvent) + Send + Sync + 'static>(
&self,
options: PositionOptions,
@@ -64,14 +66,17 @@ impl<R: Runtime> Geolocation<R> {
Ok(())
}
/// Not implemented on desktop platforms; always succeeds without doing anything.
pub fn clear_watch(&self, _channel_id: u32) -> crate::Result<()> {
Ok(())
}
/// Not implemented on desktop platforms; always resolves to the default [`PermissionStatus`] (both permissions in the [`Prompt`](tauri::plugin::PermissionState::Prompt) state).
pub fn check_permissions(&self) -> crate::Result<PermissionStatus> {
Ok(PermissionStatus::default())
}
/// Not implemented on desktop platforms; always resolves to the default [`PermissionStatus`] without prompting the user.
pub fn request_permissions(
&self,
_permissions: Option<Vec<PermissionType>>,
+3
View File
@@ -4,13 +4,16 @@
use serde::{ser::Serializer, Serialize};
/// Alias for the result type returned by the geolocation APIs.
pub type Result<T> = std::result::Result<T, Error>;
// TODO: Improve Error handling (different typed errors instead of one (stringified) PluginInvokeError for all mobile errors)
/// Errors that can occur while interacting with the geolocation APIs.
#[derive(Debug, thiserror::Error)]
#[cfg_attr(feature = "specta", derive(specta::Type))]
pub enum Error {
/// Forwards an error returned by the underlying Android or iOS plugin invocation.
#[cfg(mobile)]
#[error(transparent)]
PluginInvoke(
+1
View File
@@ -33,6 +33,7 @@ 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> {
/// Returns the handle to the geolocation APIs.
fn geolocation(&self) -> &Geolocation<R>;
}
+4
View File
@@ -33,6 +33,7 @@ pub fn init<R: Runtime, C: DeserializeOwned>(
pub struct Geolocation<R: Runtime>(PluginHandle<R>);
impl<R: Runtime> Geolocation<R> {
/// Returns the device's current [`Position`]. On Android this returns the last known location immediately if it is still within `maximum_age`, otherwise it requests a fresh reading. Errors if location services are disabled or the required permission was not granted.
pub fn get_current_position(
&self,
options: Option<PositionOptions>,
@@ -81,18 +82,21 @@ impl<R: Runtime> Geolocation<R> {
.map_err(Into::into)
}
/// Removes the position watcher registered with the given `channel_id`, as returned by [`Self::watch_position`]. Stops the platform location updates once no watcher remains.
pub fn clear_watch(&self, channel_id: u32) -> crate::Result<()> {
self.0
.run_mobile_plugin("clearWatch", ClearWatchPayload { channel_id })
.map_err(Into::into)
}
/// Returns the current [`PermissionStatus`] for the geolocation APIs. Errors if location services are disabled on the device.
pub fn check_permissions(&self) -> crate::Result<PermissionStatus> {
self.0
.run_mobile_plugin("checkPermissions", ())
.map_err(Into::into)
}
/// Requests the given `permissions` (or all of them when `None`) and returns the resulting [`PermissionStatus`]. Errors if location services are disabled on the device.
pub fn request_permissions(
&self,
permissions: Option<Vec<PermissionType>>,
+11 -1
View File
@@ -5,6 +5,7 @@
use serde::{Deserialize, Serialize};
use tauri::plugin::PermissionState;
/// The current permission state for the geolocation APIs.
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[cfg_attr(feature = "specta", derive(specta::Type))]
#[serde(rename_all = "camelCase")]
@@ -25,6 +26,7 @@ pub struct PermissionStatus {
pub coarse_location: PermissionState,
}
/// Options used to configure a [`get_current_position`](crate::Geolocation::get_current_position) or [`watch_position`](crate::Geolocation::watch_position) request.
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[cfg_attr(feature = "specta", derive(specta::Type))]
#[serde(rename_all = "camelCase")]
@@ -47,14 +49,18 @@ pub struct PositionOptions {
pub maximum_age: u32,
}
/// The individual permission aliases that can be requested with [`request_permissions`](crate::Geolocation::request_permissions).
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "specta", derive(specta::Type))]
#[serde(rename_all = "camelCase")]
pub enum PermissionType {
/// The `location` alias. On Android this maps to both `ACCESS_COARSE_LOCATION` and `ACCESS_FINE_LOCATION`. On iOS it maps to the standard location permission.
Location,
/// The `coarseLocation` alias. On Android this maps to `ACCESS_COARSE_LOCATION` only. On iOS it behaves the same as [`Location`](Self::Location).
CoarseLocation,
}
/// The GPS coordinates of a [`Position`], along with the accuracy of each reading.
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[cfg_attr(feature = "specta", derive(specta::Type))]
#[serde(rename_all = "camelCase")]
@@ -70,12 +76,13 @@ pub struct Coordinates {
pub altitude_accuracy: Option<f64>,
/// The altitude the user is at, if available.
pub altitude: Option<f64>,
// The speed the user is traveling, if available.
/// The speed the user is traveling, in meters per second, if available.
pub speed: Option<f64>,
/// The heading the user is facing, if available.
pub heading: Option<f64>,
}
/// A geolocation reading, as returned by [`get_current_position`](crate::Geolocation::get_current_position) and reported through [`WatchEvent::Position`].
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[cfg_attr(feature = "specta", derive(specta::Type))]
#[serde(rename_all = "camelCase")]
@@ -87,10 +94,13 @@ pub struct Position {
pub coords: Coordinates,
}
/// A single update sent through the channel callback registered with [`watch_position`](crate::Geolocation::watch_position).
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "specta", derive(specta::Type))]
#[serde(untagged)]
pub enum WatchEvent {
/// A new position was read successfully.
Position(Position),
/// The platform failed to read a position; the string is the platform-provided error message.
Error(String),
}