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>
This commit is contained in:
Fabian-Lars
2024-08-02 15:45:47 +02:00
committed by GitHub
parent 34df132fb1
commit 9606089b2a
102 changed files with 4896 additions and 52 deletions
+95
View File
@@ -0,0 +1,95 @@
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
use serde::{de::DeserializeOwned, Serialize};
use tauri::{
ipc::{Channel, InvokeBody},
plugin::PluginApi,
AppHandle, Runtime,
};
use crate::models::*;
pub fn init<R: Runtime, C: DeserializeOwned>(
app: &AppHandle<R>,
_api: PluginApi<R, C>,
) -> crate::Result<Geolocation<R>> {
Ok(Geolocation(app.clone()))
}
/// Access to the geolocation APIs.
pub struct Geolocation<R: Runtime>(AppHandle<R>);
impl<R: Runtime> Geolocation<R> {
pub fn get_current_position(
&self,
_options: Option<PositionOptions>,
) -> crate::Result<Position> {
Ok(Position::default())
}
pub fn watch_position<F: Fn(WatchEvent) + Send + Sync + 'static>(
&self,
options: PositionOptions,
callback: F,
) -> crate::Result<u32> {
let channel = Channel::new(move |event| {
let payload = match event {
InvokeBody::Json(payload) => serde_json::from_value::<WatchEvent>(payload)
.unwrap_or_else(|error| {
WatchEvent::Error(format!(
"Couldn't deserialize watch event payload: `{error}`"
))
}),
_ => WatchEvent::Error("Unexpected watch event payload.".to_string()),
};
callback(payload);
Ok(())
});
let id = channel.id();
self.watch_position_inner(options, channel)?;
Ok(id)
}
pub(crate) fn watch_position_inner(
&self,
_options: PositionOptions,
_callback_channel: Channel,
) -> crate::Result<()> {
Ok(())
}
pub fn clear_watch(&self, _channel_id: u32) -> crate::Result<()> {
Ok(())
}
pub fn check_permissions(&self) -> crate::Result<PermissionStatus> {
Ok(PermissionStatus::default())
}
pub fn request_permissions(
&self,
_permissions: Option<Vec<PermissionType>>,
) -> crate::Result<PermissionStatus> {
Ok(PermissionStatus::default())
}
}
#[derive(Serialize)]
#[allow(unused)] // TODO:
struct WatchPayload {
options: PositionOptions,
channel: Channel,
}
#[derive(Serialize)]
#[serde(rename_all = "camelCase")]
#[allow(unused)] // TODO:
struct ClearWatchPayload {
channel_id: u32,
}