fix(geo/haptics)!: specta version and feature flag (#2316)

pull/2317/head
Fabian-Lars 5 months ago committed by GitHub
parent da5c59e2fe
commit c9c13a0fe7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -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.

@ -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
Cargo.lock generated

@ -876,9 +876,9 @@ dependencies = [
[[package]] [[package]]
name = "cargo_toml" name = "cargo_toml"
version = "0.17.2" version = "0.21.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a969e13a7589e9e3e4207e153bae624ade2b5622fb4684a4923b23ec3d57719" checksum = "5fbd1fe9db3ebf71b89060adaf7b0504c2d6a425cf061313099547e382c2e472"
dependencies = [ dependencies = [
"serde", "serde",
"toml 0.8.19", "toml 0.8.19",
@ -3370,7 +3370,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fc2f4eb4bc735547cfed7c0a4922cbd04a4655978c09b54f1f7b228750664c34" checksum = "fc2f4eb4bc735547cfed7c0a4922cbd04a4655978c09b54f1f7b228750664c34"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"windows-targets 0.48.5", "windows-targets 0.52.6",
] ]
[[package]] [[package]]
@ -3859,7 +3859,7 @@ version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "af1844ef2428cc3e1cb900be36181049ef3d3193c63e43026cfe202983b27a56" checksum = "af1844ef2428cc3e1cb900be36181049ef3d3193c63e43026cfe202983b27a56"
dependencies = [ dependencies = [
"proc-macro-crate 1.3.1", "proc-macro-crate 3.2.0",
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.90", "syn 2.0.90",
@ -5793,18 +5793,6 @@ dependencies = [
"syn 2.0.90", "syn 2.0.90",
] ]
[[package]]
name = "specta-util"
version = "0.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e8113d65b58a6de3184b01d6df9e50b6d4bbe7f724251f576d84f23228824456"
dependencies = [
"ctor",
"serde",
"specta",
"specta-macros",
]
[[package]] [[package]]
name = "spin" name = "spin"
version = "0.9.8" version = "0.9.8"
@ -6324,9 +6312,9 @@ checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1"
[[package]] [[package]]
name = "tauri" name = "tauri"
version = "2.2.0" version = "2.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2e2e3349fbb2be7af9fad1b43d61ac83ba55ab48d47fbe1b2732f0c8211610a9" checksum = "2979ec5ec5a9310b15d1548db3b8de98d8f75abf2b5b00fec9cd5c0553ecc09c"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"bytes", "bytes",
@ -6358,7 +6346,6 @@ dependencies = [
"serde_repr", "serde_repr",
"serialize-to-javascript", "serialize-to-javascript",
"specta", "specta",
"specta-util",
"swift-rs", "swift-rs",
"tauri-build", "tauri-build",
"tauri-macros", "tauri-macros",
@ -6379,9 +6366,9 @@ dependencies = [
[[package]] [[package]]
name = "tauri-build" name = "tauri-build"
version = "2.0.4" version = "2.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b274ec7239ada504deb615f1c8abd7ba99631e879709e6f10e5d17217058d976" checksum = "8e950124f6779c6cf98e3260c7a6c8488a74aa6350dd54c6950fdaa349bca2df"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"cargo_toml", "cargo_toml",
@ -6587,7 +6574,6 @@ dependencies = [
"serde", "serde",
"serde_json", "serde_json",
"specta", "specta",
"specta-util",
"tauri", "tauri",
"tauri-plugin", "tauri-plugin",
"thiserror 2.0.9", "thiserror 2.0.9",
@ -6614,7 +6600,6 @@ dependencies = [
"serde", "serde",
"serde_json", "serde_json",
"specta", "specta",
"specta-util",
"tauri", "tauri",
"tauri-plugin", "tauri-plugin",
"thiserror 2.0.9", "thiserror 2.0.9",
@ -8101,7 +8086,7 @@ version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb"
dependencies = [ dependencies = [
"windows-sys 0.48.0", "windows-sys 0.59.0",
] ]
[[package]] [[package]]

@ -21,14 +21,9 @@ thiserror = "2"
url = "2" url = "2"
schemars = "0.8" schemars = "0.8"
dunce = "1" dunce = "1"
specta = "=2.0.0-rc.20" specta = "^2.0.0-rc.16"
# TODO: remove when specta releases rc.21
specta-util = { version = "^0.0.7", default-features = false, features = [
"export",
] }
glob = "0.3" glob = "0.3"
zbus = "5" zbus = "5"
#tauri-specta = "=2.0.0-rc.11"
[workspace.package] [workspace.package]
edition = "2021" edition = "2021"

@ -45,7 +45,7 @@ pub fn create_tray<R: Runtime>(app: &tauri::AppHandle<R>) -> tauri::Result<()> {
.tooltip("Tauri") .tooltip("Tauri")
.icon(app.default_window_icon().unwrap().clone()) .icon(app.default_window_icon().unwrap().clone())
.menu(&menu1) .menu(&menu1)
.menu_on_left_click(false) .show_menu_on_left_click(false)
.on_menu_event(move |app, event| match event.id.as_ref() { .on_menu_event(move |app, event| match event.id.as_ref() {
"quit" => { "quit" => {
app.exit(0); app.exit(0);

@ -26,11 +26,13 @@ tauri-plugin = { workspace = true, features = ["build"] }
[dependencies] [dependencies]
serde = { workspace = true } serde = { workspace = true }
serde_json = { workspace = true } serde_json = { workspace = true }
tauri = { workspace = true, features = ["specta"] } tauri = { workspace = true }
log = { workspace = true } log = { workspace = true }
thiserror = { workspace = true } thiserror = { workspace = true }
specta = { workspace = true } specta = { workspace = true, optional = true }
specta-util = { workspace = true }
[target.'cfg(target_os = "ios")'.dependencies] [target.'cfg(target_os = "ios")'.dependencies]
tauri = { workspace = true, features = ["wry"] } tauri = { workspace = true, features = ["wry"] }
[features]
specta = ["dep:specta", "tauri/specta"]

@ -7,7 +7,6 @@ use tauri::{command, ipc::Channel, AppHandle, Runtime};
use crate::{GeolocationExt, PermissionStatus, PermissionType, Position, PositionOptions, Result}; use crate::{GeolocationExt, PermissionStatus, PermissionType, Position, PositionOptions, Result};
#[command] #[command]
#[specta::specta]
pub(crate) async fn get_current_position<R: Runtime>( pub(crate) async fn get_current_position<R: Runtime>(
app: AppHandle<R>, app: AppHandle<R>,
options: Option<PositionOptions>, options: Option<PositionOptions>,
@ -16,7 +15,6 @@ pub(crate) async fn get_current_position<R: Runtime>(
} }
#[command] #[command]
#[specta::specta]
pub(crate) async fn watch_position<R: Runtime>( pub(crate) async fn watch_position<R: Runtime>(
app: AppHandle<R>, app: AppHandle<R>,
options: PositionOptions, options: PositionOptions,
@ -26,19 +24,16 @@ pub(crate) async fn watch_position<R: Runtime>(
} }
#[command] #[command]
#[specta::specta]
pub(crate) async fn clear_watch<R: Runtime>(app: AppHandle<R>, channel_id: u32) -> Result<()> { pub(crate) async fn clear_watch<R: Runtime>(app: AppHandle<R>, channel_id: u32) -> Result<()> {
app.geolocation().clear_watch(channel_id) app.geolocation().clear_watch(channel_id)
} }
#[command] #[command]
#[specta::specta]
pub(crate) async fn check_permissions<R: Runtime>(app: AppHandle<R>) -> Result<PermissionStatus> { pub(crate) async fn check_permissions<R: Runtime>(app: AppHandle<R>) -> Result<PermissionStatus> {
app.geolocation().check_permissions() app.geolocation().check_permissions()
} }
#[command] #[command]
#[specta::specta]
pub(crate) async fn request_permissions<R: Runtime>( pub(crate) async fn request_permissions<R: Runtime>(
app: AppHandle<R>, app: AppHandle<R>,
permissions: Option<Vec<PermissionType>>, permissions: Option<Vec<PermissionType>>,

@ -3,13 +3,13 @@
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
use serde::{ser::Serializer, Serialize}; use serde::{ser::Serializer, Serialize};
use specta::Type;
pub type Result<T> = std::result::Result<T, Error>; 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) // 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 { pub enum Error {
#[cfg(mobile)] #[cfg(mobile)]
#[error(transparent)] #[error(transparent)]

@ -7,8 +7,6 @@ use tauri::{
Manager, Runtime, Manager, Runtime,
}; };
//use tauri_specta::*;
pub use models::*; pub use models::*;
#[cfg(desktop)] #[cfg(desktop)]
@ -27,24 +25,6 @@ use desktop::Geolocation;
#[cfg(mobile)] #[cfg(mobile)]
use mobile::Geolocation; 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. /// Extensions to [`tauri::App`], [`tauri::AppHandle`], [`tauri::WebviewWindow`], [`tauri::Webview`] and [`tauri::Window`] to access the geolocation APIs.
pub trait GeolocationExt<R: Runtime> { pub trait GeolocationExt<R: Runtime> {
fn geolocation(&self) -> &Geolocation<R>; fn geolocation(&self) -> &Geolocation<R>;
@ -58,9 +38,6 @@ impl<R: Runtime, T: Manager<R>> crate::GeolocationExt<R> for T {
/// Initializes the plugin. /// Initializes the plugin.
pub fn init<R: Runtime>() -> TauriPlugin<R> { pub fn init<R: Runtime>() -> TauriPlugin<R> {
/* let (invoke_handler, register_events) =
specta_builder!().build_plugin_utils("geolocation").unwrap(); */
Builder::new("geolocation") Builder::new("geolocation")
.invoke_handler(tauri::generate_handler![ .invoke_handler(tauri::generate_handler![
commands::get_current_position, commands::get_current_position,
@ -79,22 +56,3 @@ pub fn init<R: Runtime>() -> TauriPlugin<R> {
}) })
.build() .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");
}
}
*/

@ -3,10 +3,10 @@
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use specta::Type;
use tauri::plugin::PermissionState; 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")] #[serde(rename_all = "camelCase")]
pub struct PermissionStatus { pub struct PermissionStatus {
/// Permission state for the location alias. /// Permission state for the location alias.
@ -25,7 +25,8 @@ pub struct PermissionStatus {
pub coarse_location: PermissionState, 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")] #[serde(rename_all = "camelCase")]
pub struct PositionOptions { pub struct PositionOptions {
/// High accuracy mode (such as GPS, if available) /// High accuracy mode (such as GPS, if available)
@ -46,14 +47,16 @@ pub struct PositionOptions {
pub maximum_age: u32, 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")] #[serde(rename_all = "camelCase")]
pub enum PermissionType { pub enum PermissionType {
Location, Location,
CoarseLocation, 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")] #[serde(rename_all = "camelCase")]
pub struct Coordinates { pub struct Coordinates {
/// Latitude in decimal degrees. /// Latitude in decimal degrees.
@ -73,7 +76,8 @@ pub struct Coordinates {
pub heading: Option<f64>, 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")] #[serde(rename_all = "camelCase")]
pub struct Position { pub struct Position {
/// Creation time for these coordinates. /// Creation time for these coordinates.
@ -83,7 +87,8 @@ pub struct Position {
pub coords: Coordinates, pub coords: Coordinates,
} }
#[derive(Debug, Clone, Serialize, Deserialize, Type)] #[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "specta", derive(specta::Type))]
#[serde(untagged)] #[serde(untagged)]
pub enum WatchEvent { pub enum WatchEvent {
Position(Position), Position(Position),

@ -26,11 +26,13 @@ tauri-plugin = { workspace = true, features = ["build"] }
[dependencies] [dependencies]
serde = { workspace = true } serde = { workspace = true }
serde_json = { workspace = true } serde_json = { workspace = true }
tauri = { workspace = true, features = ["specta"] } tauri = { workspace = true }
log = { workspace = true } log = { workspace = true }
thiserror = { workspace = true } thiserror = { workspace = true }
specta = { workspace = true } specta = { workspace = true, optional = true }
specta-util = { workspace = true }
[target.'cfg(target_os = "ios")'.dependencies] [target.'cfg(target_os = "ios")'.dependencies]
tauri = { workspace = true, features = ["wry"] } tauri = { workspace = true, features = ["wry"] }
[features]
specta = ["dep:specta", "tauri/specta"]

@ -7,13 +7,11 @@ use tauri::{command, AppHandle, Runtime};
use crate::{HapticsExt, ImpactFeedbackStyle, NotificationFeedbackType, Result}; use crate::{HapticsExt, ImpactFeedbackStyle, NotificationFeedbackType, Result};
#[command] #[command]
#[specta::specta]
pub(crate) async fn vibrate<R: Runtime>(app: AppHandle<R>, duration: u32) -> Result<()> { pub(crate) async fn vibrate<R: Runtime>(app: AppHandle<R>, duration: u32) -> Result<()> {
app.haptics().vibrate(duration) app.haptics().vibrate(duration)
} }
#[command] #[command]
#[specta::specta]
pub(crate) async fn impact_feedback<R: Runtime>( pub(crate) async fn impact_feedback<R: Runtime>(
app: AppHandle<R>, app: AppHandle<R>,
style: ImpactFeedbackStyle, style: ImpactFeedbackStyle,
@ -22,7 +20,6 @@ pub(crate) async fn impact_feedback<R: Runtime>(
} }
#[command] #[command]
#[specta::specta]
pub(crate) async fn notification_feedback<R: Runtime>( pub(crate) async fn notification_feedback<R: Runtime>(
app: AppHandle<R>, app: AppHandle<R>,
r#type: NotificationFeedbackType, r#type: NotificationFeedbackType,
@ -31,7 +28,6 @@ pub(crate) async fn notification_feedback<R: Runtime>(
} }
#[command] #[command]
#[specta::specta]
pub(crate) async fn selection_feedback<R: Runtime>(app: AppHandle<R>) -> Result<()> { pub(crate) async fn selection_feedback<R: Runtime>(app: AppHandle<R>) -> Result<()> {
app.haptics().selection_feedback() app.haptics().selection_feedback()
} }

@ -3,13 +3,13 @@
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
use serde::{ser::Serializer, Serialize}; use serde::{ser::Serializer, Serialize};
use specta::Type;
pub type Result<T> = std::result::Result<T, Error>; 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) // 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 { pub enum Error {
#[cfg(mobile)] #[cfg(mobile)]
#[error(transparent)] #[error(transparent)]

@ -7,8 +7,6 @@ use tauri::{
Manager, Runtime, Manager, Runtime,
}; };
//use tauri_specta::*;
pub use models::*; pub use models::*;
#[cfg(desktop)] #[cfg(desktop)]
@ -27,23 +25,6 @@ use desktop::Haptics;
#[cfg(mobile)] #[cfg(mobile)]
use mobile::Haptics; use mobile::Haptics;
/* macro_rules! specta_builder {
() => {
ts::builder()
.commands(collect_commands![
commands::vibrate,
commands::impact_feedback,
commands::notification_feedback,
commands::selection_feedback
])
.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 haptics APIs. /// Extensions to [`tauri::App`], [`tauri::AppHandle`], [`tauri::WebviewWindow`], [`tauri::Webview`] and [`tauri::Window`] to access the haptics APIs.
pub trait HapticsExt<R: Runtime> { pub trait HapticsExt<R: Runtime> {
fn haptics(&self) -> &Haptics<R>; fn haptics(&self) -> &Haptics<R>;
@ -57,9 +38,6 @@ impl<R: Runtime, T: Manager<R>> crate::HapticsExt<R> for T {
/// Initializes the plugin. /// Initializes the plugin.
pub fn init<R: Runtime>() -> TauriPlugin<R> { pub fn init<R: Runtime>() -> TauriPlugin<R> {
/* let (invoke_handler, register_events) =
specta_builder!().build_plugin_utils("haptics").unwrap(); */
Builder::new("haptics") Builder::new("haptics")
.invoke_handler(tauri::generate_handler![ .invoke_handler(tauri::generate_handler![
commands::vibrate, commands::vibrate,
@ -77,22 +55,3 @@ pub fn init<R: Runtime>() -> TauriPlugin<R> {
}) })
.build() .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("haptics")
.expect("failed to export specta types");
}
}
*/

@ -3,9 +3,9 @@
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use specta::Type;
/* /*
#[derive(Debug, Clone, Default, Serialize, Deserialize, Type)] #[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[cfg_attr(feature = "specta", derive(specta::Type))]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct HapticsOptions { pub struct HapticsOptions {
// TODO: support array to match web api // TODO: support array to match web api
@ -13,7 +13,8 @@ pub struct HapticsOptions {
} }
*/ */
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize, Type)] #[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "specta", derive(specta::Type))]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub enum ImpactFeedbackStyle { pub enum ImpactFeedbackStyle {
Light, Light,
@ -24,7 +25,8 @@ pub enum ImpactFeedbackStyle {
Rigid, Rigid,
} }
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize, Type)] #[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "specta", derive(specta::Type))]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub enum NotificationFeedbackType { pub enum NotificationFeedbackType {
#[default] #[default]

Loading…
Cancel
Save