Skip to content

Commit c9c13a0

Browse files
authored
fix(geo/haptics)!: specta version and feature flag (tauri-apps#2316)
1 parent da5c59e commit c9c13a0

File tree

15 files changed

+59
-144
lines changed

15 files changed

+59
-144
lines changed

.changes/specta-feature.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
geolocation: patch
3+
geolocation-js: patch
4+
haptics: patch
5+
haptics-js: patch
6+
---
7+
8+
**Breaking change:** `specta` integration is now behind a `specta` feature flag like in Tauri.

.changes/specta.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
geolocation: patch
3+
geolocation-js: patch
4+
haptics: patch
5+
haptics-js: patch
6+
---
7+
8+
Unlock and widen `specta` version range to match Tauri. No API changes.

Cargo.lock

Lines changed: 9 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,9 @@ thiserror = "2"
2121
url = "2"
2222
schemars = "0.8"
2323
dunce = "1"
24-
specta = "=2.0.0-rc.20"
25-
# TODO: remove when specta releases rc.21
26-
specta-util = { version = "^0.0.7", default-features = false, features = [
27-
"export",
28-
] }
24+
specta = "^2.0.0-rc.16"
2925
glob = "0.3"
3026
zbus = "5"
31-
#tauri-specta = "=2.0.0-rc.11"
3227

3328
[workspace.package]
3429
edition = "2021"

examples/api/src-tauri/src/tray.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub fn create_tray<R: Runtime>(app: &tauri::AppHandle<R>) -> tauri::Result<()> {
4545
.tooltip("Tauri")
4646
.icon(app.default_window_icon().unwrap().clone())
4747
.menu(&menu1)
48-
.menu_on_left_click(false)
48+
.show_menu_on_left_click(false)
4949
.on_menu_event(move |app, event| match event.id.as_ref() {
5050
"quit" => {
5151
app.exit(0);

plugins/geolocation/Cargo.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@ tauri-plugin = { workspace = true, features = ["build"] }
2626
[dependencies]
2727
serde = { workspace = true }
2828
serde_json = { workspace = true }
29-
tauri = { workspace = true, features = ["specta"] }
29+
tauri = { workspace = true }
3030
log = { workspace = true }
3131
thiserror = { workspace = true }
32-
specta = { workspace = true }
33-
specta-util = { workspace = true }
32+
specta = { workspace = true, optional = true }
3433

3534
[target.'cfg(target_os = "ios")'.dependencies]
3635
tauri = { workspace = true, features = ["wry"] }
36+
37+
[features]
38+
specta = ["dep:specta", "tauri/specta"]

plugins/geolocation/src/commands.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use tauri::{command, ipc::Channel, AppHandle, Runtime};
77
use crate::{GeolocationExt, PermissionStatus, PermissionType, Position, PositionOptions, Result};
88

99
#[command]
10-
#[specta::specta]
1110
pub(crate) async fn get_current_position<R: Runtime>(
1211
app: AppHandle<R>,
1312
options: Option<PositionOptions>,
@@ -16,7 +15,6 @@ pub(crate) async fn get_current_position<R: Runtime>(
1615
}
1716

1817
#[command]
19-
#[specta::specta]
2018
pub(crate) async fn watch_position<R: Runtime>(
2119
app: AppHandle<R>,
2220
options: PositionOptions,
@@ -26,19 +24,16 @@ pub(crate) async fn watch_position<R: Runtime>(
2624
}
2725

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

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

4036
#[command]
41-
#[specta::specta]
4237
pub(crate) async fn request_permissions<R: Runtime>(
4338
app: AppHandle<R>,
4439
permissions: Option<Vec<PermissionType>>,

plugins/geolocation/src/error.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
// SPDX-License-Identifier: MIT
44

55
use serde::{ser::Serializer, Serialize};
6-
use specta::Type;
76

87
pub type Result<T> = std::result::Result<T, Error>;
98

109
// TODO: Improve Error handling (different typed errors instead of one (stringified) PluginInvokeError for all mobile errors)
1110

12-
#[derive(Debug, thiserror::Error, Type)]
11+
#[derive(Debug, thiserror::Error)]
12+
#[cfg_attr(feature = "specta", derive(specta::Type))]
1313
pub enum Error {
1414
#[cfg(mobile)]
1515
#[error(transparent)]

plugins/geolocation/src/lib.rs

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ use tauri::{
77
Manager, Runtime,
88
};
99

10-
//use tauri_specta::*;
11-
1210
pub use models::*;
1311

1412
#[cfg(desktop)]
@@ -27,24 +25,6 @@ use desktop::Geolocation;
2725
#[cfg(mobile)]
2826
use mobile::Geolocation;
2927

30-
/* macro_rules! specta_builder {
31-
() => {
32-
ts::builder()
33-
.commands(collect_commands![
34-
commands::get_current_position,
35-
commands::watch_position,
36-
commands::clear_watch,
37-
commands::check_permissions,
38-
commands::request_permissions
39-
])
40-
.header("// @ts-nocheck")
41-
.config(
42-
specta::ts::ExportConfig::default()
43-
.bigint(specta::ts::BigIntExportBehavior::Number),
44-
)
45-
};
46-
} */
47-
4828
/// Extensions to [`tauri::App`], [`tauri::AppHandle`], [`tauri::WebviewWindow`], [`tauri::Webview`] and [`tauri::Window`] to access the geolocation APIs.
4929
pub trait GeolocationExt<R: Runtime> {
5030
fn geolocation(&self) -> &Geolocation<R>;
@@ -58,9 +38,6 @@ impl<R: Runtime, T: Manager<R>> crate::GeolocationExt<R> for T {
5838

5939
/// Initializes the plugin.
6040
pub fn init<R: Runtime>() -> TauriPlugin<R> {
61-
/* let (invoke_handler, register_events) =
62-
specta_builder!().build_plugin_utils("geolocation").unwrap(); */
63-
6441
Builder::new("geolocation")
6542
.invoke_handler(tauri::generate_handler![
6643
commands::get_current_position,
@@ -79,22 +56,3 @@ pub fn init<R: Runtime>() -> TauriPlugin<R> {
7956
})
8057
.build()
8158
}
82-
83-
/* #[cfg(test)]
84-
mod test {
85-
use super::*;
86-
87-
#[test]
88-
fn export_types() {
89-
specta_builder!()
90-
.path("./guest-js/bindings.ts")
91-
.config(
92-
specta::ts::ExportConfig::default()
93-
.formatter(specta::ts::formatter::prettier)
94-
.bigint(specta::ts::BigIntExportBehavior::Number),
95-
)
96-
.export_for_plugin("geolocation")
97-
.expect("failed to export specta types");
98-
}
99-
}
100-
*/

plugins/geolocation/src/models.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
// SPDX-License-Identifier: MIT
44

55
use serde::{Deserialize, Serialize};
6-
use specta::Type;
76
use tauri::plugin::PermissionState;
87

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

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

49-
#[derive(Debug, Clone, Serialize, Deserialize, Type)]
50+
#[derive(Debug, Clone, Serialize, Deserialize)]
51+
#[cfg_attr(feature = "specta", derive(specta::Type))]
5052
#[serde(rename_all = "camelCase")]
5153
pub enum PermissionType {
5254
Location,
5355
CoarseLocation,
5456
}
5557

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

76-
#[derive(Debug, Clone, Default, Serialize, Deserialize, Type)]
79+
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
80+
#[cfg_attr(feature = "specta", derive(specta::Type))]
7781
#[serde(rename_all = "camelCase")]
7882
pub struct Position {
7983
/// Creation time for these coordinates.
@@ -83,7 +87,8 @@ pub struct Position {
8387
pub coords: Coordinates,
8488
}
8589

86-
#[derive(Debug, Clone, Serialize, Deserialize, Type)]
90+
#[derive(Debug, Clone, Serialize, Deserialize)]
91+
#[cfg_attr(feature = "specta", derive(specta::Type))]
8792
#[serde(untagged)]
8893
pub enum WatchEvent {
8994
Position(Position),

0 commit comments

Comments
 (0)