Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changes/specta-feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
geolocation: patch
geolocation-js: patch
haptics: patch
haptics-js: patch
---

**Breaking change:** `specta` integration is now behind a `specta` feature flag like in Tauri.
8 changes: 8 additions & 0 deletions .changes/specta.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
geolocation: patch
geolocation-js: patch
haptics: patch
haptics-js: patch
---

Unlock and widen `specta` version range to match Tauri. No API changes.
33 changes: 9 additions & 24 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 1 addition & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,9 @@ thiserror = "2"
url = "2"
schemars = "0.8"
dunce = "1"
specta = "=2.0.0-rc.20"
# TODO: remove when specta releases rc.21
specta-util = { version = "^0.0.7", default-features = false, features = [
"export",
] }
specta = "^2.0.0-rc.16"
glob = "0.3"
zbus = "5"
#tauri-specta = "=2.0.0-rc.11"

[workspace.package]
edition = "2021"
Expand Down
2 changes: 1 addition & 1 deletion examples/api/src-tauri/src/tray.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub fn create_tray<R: Runtime>(app: &tauri::AppHandle<R>) -> tauri::Result<()> {
.tooltip("Tauri")
.icon(app.default_window_icon().unwrap().clone())
.menu(&menu1)
.menu_on_left_click(false)
.show_menu_on_left_click(false)
.on_menu_event(move |app, event| match event.id.as_ref() {
"quit" => {
app.exit(0);
Expand Down
8 changes: 5 additions & 3 deletions plugins/geolocation/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ tauri-plugin = { workspace = true, features = ["build"] }
[dependencies]
serde = { workspace = true }
serde_json = { workspace = true }
tauri = { workspace = true, features = ["specta"] }
tauri = { workspace = true }
log = { workspace = true }
thiserror = { workspace = true }
specta = { workspace = true }
specta-util = { workspace = true }
specta = { workspace = true, optional = true }

[target.'cfg(target_os = "ios")'.dependencies]
tauri = { workspace = true, features = ["wry"] }

[features]
specta = ["dep:specta", "tauri/specta"]
5 changes: 0 additions & 5 deletions plugins/geolocation/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use tauri::{command, ipc::Channel, AppHandle, Runtime};
use crate::{GeolocationExt, PermissionStatus, PermissionType, Position, PositionOptions, Result};

#[command]
#[specta::specta]
pub(crate) async fn get_current_position<R: Runtime>(
app: AppHandle<R>,
options: Option<PositionOptions>,
Expand All @@ -16,7 +15,6 @@ pub(crate) async fn get_current_position<R: Runtime>(
}

#[command]
#[specta::specta]
pub(crate) async fn watch_position<R: Runtime>(
app: AppHandle<R>,
options: PositionOptions,
Expand All @@ -26,19 +24,16 @@ pub(crate) async fn watch_position<R: Runtime>(
}

#[command]
#[specta::specta]
pub(crate) async fn clear_watch<R: Runtime>(app: AppHandle<R>, channel_id: u32) -> Result<()> {
app.geolocation().clear_watch(channel_id)
}

#[command]
#[specta::specta]
pub(crate) async fn check_permissions<R: Runtime>(app: AppHandle<R>) -> Result<PermissionStatus> {
app.geolocation().check_permissions()
}

#[command]
#[specta::specta]
pub(crate) async fn request_permissions<R: Runtime>(
app: AppHandle<R>,
permissions: Option<Vec<PermissionType>>,
Expand Down
4 changes: 2 additions & 2 deletions plugins/geolocation/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
// SPDX-License-Identifier: MIT

use serde::{ser::Serializer, Serialize};
use specta::Type;

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)

#[derive(Debug, thiserror::Error, Type)]
#[derive(Debug, thiserror::Error)]
#[cfg_attr(feature = "specta", derive(specta::Type))]
pub enum Error {
#[cfg(mobile)]
#[error(transparent)]
Expand Down
42 changes: 0 additions & 42 deletions plugins/geolocation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ use tauri::{
Manager, Runtime,
};

//use tauri_specta::*;

pub use models::*;

#[cfg(desktop)]
Expand All @@ -27,24 +25,6 @@ use desktop::Geolocation;
#[cfg(mobile)]
use mobile::Geolocation;

/* macro_rules! specta_builder {
() => {
ts::builder()
.commands(collect_commands![
commands::get_current_position,
commands::watch_position,
commands::clear_watch,
commands::check_permissions,
commands::request_permissions
])
.header("// @ts-nocheck")
.config(
specta::ts::ExportConfig::default()
.bigint(specta::ts::BigIntExportBehavior::Number),
)
};
} */

/// 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>;
Expand All @@ -58,9 +38,6 @@ impl<R: Runtime, T: Manager<R>> crate::GeolocationExt<R> for T {

/// Initializes the plugin.
pub fn init<R: Runtime>() -> TauriPlugin<R> {
/* let (invoke_handler, register_events) =
specta_builder!().build_plugin_utils("geolocation").unwrap(); */

Builder::new("geolocation")
.invoke_handler(tauri::generate_handler![
commands::get_current_position,
Expand All @@ -79,22 +56,3 @@ pub fn init<R: Runtime>() -> TauriPlugin<R> {
})
.build()
}

/* #[cfg(test)]
mod test {
use super::*;

#[test]
fn export_types() {
specta_builder!()
.path("./guest-js/bindings.ts")
.config(
specta::ts::ExportConfig::default()
.formatter(specta::ts::formatter::prettier)
.bigint(specta::ts::BigIntExportBehavior::Number),
)
.export_for_plugin("geolocation")
.expect("failed to export specta types");
}
}
*/
19 changes: 12 additions & 7 deletions plugins/geolocation/src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
// SPDX-License-Identifier: MIT

use serde::{Deserialize, Serialize};
use specta::Type;
use tauri::plugin::PermissionState;

#[derive(Debug, Clone, Default, Serialize, Deserialize, Type)]
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[cfg_attr(feature = "specta", derive(specta::Type))]
#[serde(rename_all = "camelCase")]
pub struct PermissionStatus {
/// Permission state for the location alias.
Expand All @@ -25,7 +25,8 @@ pub struct PermissionStatus {
pub coarse_location: PermissionState,
}

#[derive(Debug, Clone, Default, Serialize, Deserialize, Type)]
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[cfg_attr(feature = "specta", derive(specta::Type))]
#[serde(rename_all = "camelCase")]
pub struct PositionOptions {
/// High accuracy mode (such as GPS, if available)
Expand All @@ -46,14 +47,16 @@ pub struct PositionOptions {
pub maximum_age: u32,
}

#[derive(Debug, Clone, Serialize, Deserialize, Type)]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "specta", derive(specta::Type))]
#[serde(rename_all = "camelCase")]
pub enum PermissionType {
Location,
CoarseLocation,
}

#[derive(Debug, Clone, Default, Serialize, Deserialize, Type)]
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[cfg_attr(feature = "specta", derive(specta::Type))]
#[serde(rename_all = "camelCase")]
pub struct Coordinates {
/// Latitude in decimal degrees.
Expand All @@ -73,7 +76,8 @@ pub struct Coordinates {
pub heading: Option<f64>,
}

#[derive(Debug, Clone, Default, Serialize, Deserialize, Type)]
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[cfg_attr(feature = "specta", derive(specta::Type))]
#[serde(rename_all = "camelCase")]
pub struct Position {
/// Creation time for these coordinates.
Expand All @@ -83,7 +87,8 @@ pub struct Position {
pub coords: Coordinates,
}

#[derive(Debug, Clone, Serialize, Deserialize, Type)]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "specta", derive(specta::Type))]
#[serde(untagged)]
pub enum WatchEvent {
Position(Position),
Expand Down
8 changes: 5 additions & 3 deletions plugins/haptics/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ tauri-plugin = { workspace = true, features = ["build"] }
[dependencies]
serde = { workspace = true }
serde_json = { workspace = true }
tauri = { workspace = true, features = ["specta"] }
tauri = { workspace = true }
log = { workspace = true }
thiserror = { workspace = true }
specta = { workspace = true }
specta-util = { workspace = true }
specta = { workspace = true, optional = true }

[target.'cfg(target_os = "ios")'.dependencies]
tauri = { workspace = true, features = ["wry"] }

[features]
specta = ["dep:specta", "tauri/specta"]
4 changes: 0 additions & 4 deletions plugins/haptics/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@ use tauri::{command, AppHandle, Runtime};
use crate::{HapticsExt, ImpactFeedbackStyle, NotificationFeedbackType, Result};

#[command]
#[specta::specta]
pub(crate) async fn vibrate<R: Runtime>(app: AppHandle<R>, duration: u32) -> Result<()> {
app.haptics().vibrate(duration)
}

#[command]
#[specta::specta]
pub(crate) async fn impact_feedback<R: Runtime>(
app: AppHandle<R>,
style: ImpactFeedbackStyle,
Expand All @@ -22,7 +20,6 @@ pub(crate) async fn impact_feedback<R: Runtime>(
}

#[command]
#[specta::specta]
pub(crate) async fn notification_feedback<R: Runtime>(
app: AppHandle<R>,
r#type: NotificationFeedbackType,
Expand All @@ -31,7 +28,6 @@ pub(crate) async fn notification_feedback<R: Runtime>(
}

#[command]
#[specta::specta]
pub(crate) async fn selection_feedback<R: Runtime>(app: AppHandle<R>) -> Result<()> {
app.haptics().selection_feedback()
}
Loading
Loading