Files
tauri-plugins-workspace/plugins/geolocation/src/models.rs
T
Fabian-Lars 9606089b2a feat: Add geolocation and haptics plugins (#1599)
* init geolocation plugin

* ios impl (w/o js api)

* generate ts api

* use newer tauri commit

* add temporary postinstall

* include src in files

* guest-js

* just ship dist-js for now

* fix watcher

* fix android compile error

* fix android build for real

* fix heading type

* initial getCurrentPosition android impl (wip)

* prevent panics if errors (strings) are sent over the channel

* Add android watchPosition implementation

* init haptics plugin (android)

* ios and new apis (ANDROID IS LIKELY BROKEN - MAY NOT EVEN COMPILE)

* use tauri-specta that accounts for raw fn arg idents

* add complete android support (it's not working great due to random soft-/hardware support)

* fix(haptics): Fix the NotificationFeedbackType::Success and Version (#1)

* Fix success feedback and version

* Apply suggestions from code review

* Update package.json

---------

Co-authored-by: Fabian-Lars <118197967+FabianLars-crabnebula@users.noreply.github.com>

* android: improve permission callback handling

* keep track of ongoing perms requests

* rebuild

* license headers

* rm sqlite feat

* fmt

* what diff u talkin bout?

* ignore dist-js again

* fix audits

* dedupe api.js

* clippy

* changefiles

* readmes

* clean up todos

* rm dsstore

* rm wrong feats

* mirror

* covector

* rebuild

* ios requires the wry feature

* lint

* update lock

---------

Co-authored-by: fabianlars <fabianlars@fabianlars.de>
Co-authored-by: Brendan Allan <brendonovich@outlook.com>
Co-authored-by: Naman Garg <155433377+naman-crabnebula@users.noreply.github.com>
Co-authored-by: Lucas Nogueira <lucas@crabnebula.dev>
2024-08-02 10:45:47 -03:00

104 lines
3.6 KiB
Rust

// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
use serde::{Deserialize, Serialize};
use specta::Type;
#[derive(Debug, Clone, Default, Serialize, Deserialize, Type)]
#[serde(rename_all = "camelCase")]
pub struct PermissionStatus {
/// Permission state for the location alias.
///
/// On Android it requests/checks both ACCESS_COARSE_LOCATION and ACCESS_FINE_LOCATION permissions.
///
/// On iOS it requests/checks location permissions.
pub location: PermissionState,
/// Permissions state for the coarseLoaction alias.
///
/// On Android it requests/checks ACCESS_COARSE_LOCATION.
///
/// On Android 12+, users can choose between Approximate location (ACCESS_COARSE_LOCATION) and Precise location (ACCESS_FINE_LOCATION).
///
/// On iOS it will have the same value as the `location` alias.
pub coarse_location: PermissionState,
}
/// Permission state.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize, Type)]
#[serde(rename_all = "camelCase")]
pub enum PermissionState {
/// Permission access has been granted.
Granted,
/// Permission access has been denied.
Denied,
/// The end user should be prompted for permission.
#[default]
Prompt,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, Type)]
#[serde(rename_all = "camelCase")]
pub struct PositionOptions {
/// High accuracy mode (such as GPS, if available)
/// Will be ignored on Android 12+ if users didn't grant the ACCESS_FINE_LOCATION permission.
pub enable_high_accuracy: bool,
/// The maximum wait time in milliseconds for location updates.
/// Default: 10000
/// On Android the timeout gets ignored for getCurrentPosition.
/// Ignored on iOS.
// TODO: Handle Infinity and default to it.
// TODO: Should be u64+ but specta doesn't like that?
pub timeout: u32,
/// The maximum age in milliseconds of a possible cached position that is acceptable to return.
/// Default: 0
/// Ignored on iOS.
// TODO: Handle Infinity.
// TODO: Should be u64+ but specta doesn't like that?
pub maximum_age: u32,
}
#[derive(Debug, Clone, Serialize, Deserialize, Type)]
#[serde(rename_all = "camelCase")]
pub enum PermissionType {
Location,
CoarseLocation,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, Type)]
#[serde(rename_all = "camelCase")]
pub struct Coordinates {
/// Latitude in decimal degrees.
pub latitude: f64,
/// Longitude in decimal degrees.
pub longitude: f64,
/// Accuracy level of the latitude and longitude coordinates in meters.
pub accuracy: f64,
/// Accuracy level of the altitude coordinate in meters, if available.
/// Available on all iOS versions and on Android 8 and above.
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.
pub speed: Option<f64>,
/// The heading the user is facing, if available.
pub heading: Option<f64>,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, Type)]
#[serde(rename_all = "camelCase")]
pub struct Position {
/// Creation time for these coordinates.
// TODO: Check if we're actually losing precision.
pub timestamp: u64,
/// The GPS coordinates along with the accuracy of the data.
pub coords: Coordinates,
}
#[derive(Debug, Clone, Serialize, Deserialize, Type)]
#[serde(untagged)]
pub enum WatchEvent {
Position(Position),
Error(String),
}