diff --git a/.changes/specta-feature.md b/.changes/specta-feature.md new file mode 100644 index 00000000..86e0f2e8 --- /dev/null +++ b/.changes/specta-feature.md @@ -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. diff --git a/.changes/specta.md b/.changes/specta.md new file mode 100644 index 00000000..3542780f --- /dev/null +++ b/.changes/specta.md @@ -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. diff --git a/Cargo.lock b/Cargo.lock index 729d187e..108bf8ad 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -876,9 +876,9 @@ dependencies = [ [[package]] name = "cargo_toml" -version = "0.17.2" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a969e13a7589e9e3e4207e153bae624ade2b5622fb4684a4923b23ec3d57719" +checksum = "5fbd1fe9db3ebf71b89060adaf7b0504c2d6a425cf061313099547e382c2e472" dependencies = [ "serde", "toml 0.8.19", @@ -3370,7 +3370,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc2f4eb4bc735547cfed7c0a4922cbd04a4655978c09b54f1f7b228750664c34" dependencies = [ "cfg-if", - "windows-targets 0.48.5", + "windows-targets 0.52.6", ] [[package]] @@ -3859,7 +3859,7 @@ version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "af1844ef2428cc3e1cb900be36181049ef3d3193c63e43026cfe202983b27a56" dependencies = [ - "proc-macro-crate 1.3.1", + "proc-macro-crate 3.2.0", "proc-macro2", "quote", "syn 2.0.90", @@ -5793,18 +5793,6 @@ dependencies = [ "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]] name = "spin" version = "0.9.8" @@ -6324,9 +6312,9 @@ checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1" [[package]] name = "tauri" -version = "2.2.0" +version = "2.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e2e3349fbb2be7af9fad1b43d61ac83ba55ab48d47fbe1b2732f0c8211610a9" +checksum = "2979ec5ec5a9310b15d1548db3b8de98d8f75abf2b5b00fec9cd5c0553ecc09c" dependencies = [ "anyhow", "bytes", @@ -6358,7 +6346,6 @@ dependencies = [ "serde_repr", "serialize-to-javascript", "specta", - "specta-util", "swift-rs", "tauri-build", "tauri-macros", @@ -6379,9 +6366,9 @@ dependencies = [ [[package]] name = "tauri-build" -version = "2.0.4" +version = "2.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b274ec7239ada504deb615f1c8abd7ba99631e879709e6f10e5d17217058d976" +checksum = "8e950124f6779c6cf98e3260c7a6c8488a74aa6350dd54c6950fdaa349bca2df" dependencies = [ "anyhow", "cargo_toml", @@ -6587,7 +6574,6 @@ dependencies = [ "serde", "serde_json", "specta", - "specta-util", "tauri", "tauri-plugin", "thiserror 2.0.9", @@ -6614,7 +6600,6 @@ dependencies = [ "serde", "serde_json", "specta", - "specta-util", "tauri", "tauri-plugin", "thiserror 2.0.9", @@ -8101,7 +8086,7 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" dependencies = [ - "windows-sys 0.48.0", + "windows-sys 0.59.0", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index e31c9867..d85be889 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/examples/api/src-tauri/src/tray.rs b/examples/api/src-tauri/src/tray.rs index bf3ba5d6..7b1321a5 100644 --- a/examples/api/src-tauri/src/tray.rs +++ b/examples/api/src-tauri/src/tray.rs @@ -45,7 +45,7 @@ pub fn create_tray(app: &tauri::AppHandle) -> 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); diff --git a/plugins/geolocation/Cargo.toml b/plugins/geolocation/Cargo.toml index 86b8e461..5c5537c0 100644 --- a/plugins/geolocation/Cargo.toml +++ b/plugins/geolocation/Cargo.toml @@ -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"] diff --git a/plugins/geolocation/src/commands.rs b/plugins/geolocation/src/commands.rs index 9f9b7aa0..d2cae848 100644 --- a/plugins/geolocation/src/commands.rs +++ b/plugins/geolocation/src/commands.rs @@ -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( app: AppHandle, options: Option, @@ -16,7 +15,6 @@ pub(crate) async fn get_current_position( } #[command] -#[specta::specta] pub(crate) async fn watch_position( app: AppHandle, options: PositionOptions, @@ -26,19 +24,16 @@ pub(crate) async fn watch_position( } #[command] -#[specta::specta] pub(crate) async fn clear_watch(app: AppHandle, channel_id: u32) -> Result<()> { app.geolocation().clear_watch(channel_id) } #[command] -#[specta::specta] pub(crate) async fn check_permissions(app: AppHandle) -> Result { app.geolocation().check_permissions() } #[command] -#[specta::specta] pub(crate) async fn request_permissions( app: AppHandle, permissions: Option>, diff --git a/plugins/geolocation/src/error.rs b/plugins/geolocation/src/error.rs index 30ff7f44..21cfce52 100644 --- a/plugins/geolocation/src/error.rs +++ b/plugins/geolocation/src/error.rs @@ -3,13 +3,13 @@ // SPDX-License-Identifier: MIT use serde::{ser::Serializer, Serialize}; -use specta::Type; pub type Result = std::result::Result; // 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)] diff --git a/plugins/geolocation/src/lib.rs b/plugins/geolocation/src/lib.rs index eed4a475..55f50aa0 100644 --- a/plugins/geolocation/src/lib.rs +++ b/plugins/geolocation/src/lib.rs @@ -7,8 +7,6 @@ use tauri::{ Manager, Runtime, }; -//use tauri_specta::*; - pub use models::*; #[cfg(desktop)] @@ -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 { fn geolocation(&self) -> &Geolocation; @@ -58,9 +38,6 @@ impl> crate::GeolocationExt for T { /// Initializes the plugin. pub fn init() -> TauriPlugin { - /* let (invoke_handler, register_events) = - specta_builder!().build_plugin_utils("geolocation").unwrap(); */ - Builder::new("geolocation") .invoke_handler(tauri::generate_handler![ commands::get_current_position, @@ -79,22 +56,3 @@ pub fn init() -> TauriPlugin { }) .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"); - } -} - */ diff --git a/plugins/geolocation/src/models.rs b/plugins/geolocation/src/models.rs index 165c036f..c08bb27a 100644 --- a/plugins/geolocation/src/models.rs +++ b/plugins/geolocation/src/models.rs @@ -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. @@ -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) @@ -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. @@ -73,7 +76,8 @@ pub struct Coordinates { pub heading: Option, } -#[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. @@ -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), diff --git a/plugins/haptics/Cargo.toml b/plugins/haptics/Cargo.toml index f18672f9..924f1830 100644 --- a/plugins/haptics/Cargo.toml +++ b/plugins/haptics/Cargo.toml @@ -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"] diff --git a/plugins/haptics/src/commands.rs b/plugins/haptics/src/commands.rs index b2bbd1b0..76f097c0 100644 --- a/plugins/haptics/src/commands.rs +++ b/plugins/haptics/src/commands.rs @@ -7,13 +7,11 @@ use tauri::{command, AppHandle, Runtime}; use crate::{HapticsExt, ImpactFeedbackStyle, NotificationFeedbackType, Result}; #[command] -#[specta::specta] pub(crate) async fn vibrate(app: AppHandle, duration: u32) -> Result<()> { app.haptics().vibrate(duration) } #[command] -#[specta::specta] pub(crate) async fn impact_feedback( app: AppHandle, style: ImpactFeedbackStyle, @@ -22,7 +20,6 @@ pub(crate) async fn impact_feedback( } #[command] -#[specta::specta] pub(crate) async fn notification_feedback( app: AppHandle, r#type: NotificationFeedbackType, @@ -31,7 +28,6 @@ pub(crate) async fn notification_feedback( } #[command] -#[specta::specta] pub(crate) async fn selection_feedback(app: AppHandle) -> Result<()> { app.haptics().selection_feedback() } diff --git a/plugins/haptics/src/error.rs b/plugins/haptics/src/error.rs index 30ff7f44..21cfce52 100644 --- a/plugins/haptics/src/error.rs +++ b/plugins/haptics/src/error.rs @@ -3,13 +3,13 @@ // SPDX-License-Identifier: MIT use serde::{ser::Serializer, Serialize}; -use specta::Type; pub type Result = std::result::Result; // 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)] diff --git a/plugins/haptics/src/lib.rs b/plugins/haptics/src/lib.rs index 0a727e14..f56e5212 100644 --- a/plugins/haptics/src/lib.rs +++ b/plugins/haptics/src/lib.rs @@ -7,8 +7,6 @@ use tauri::{ Manager, Runtime, }; -//use tauri_specta::*; - pub use models::*; #[cfg(desktop)] @@ -27,23 +25,6 @@ use desktop::Haptics; #[cfg(mobile)] 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. pub trait HapticsExt { fn haptics(&self) -> &Haptics; @@ -57,9 +38,6 @@ impl> crate::HapticsExt for T { /// Initializes the plugin. pub fn init() -> TauriPlugin { - /* let (invoke_handler, register_events) = - specta_builder!().build_plugin_utils("haptics").unwrap(); */ - Builder::new("haptics") .invoke_handler(tauri::generate_handler![ commands::vibrate, @@ -77,22 +55,3 @@ pub fn init() -> TauriPlugin { }) .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"); - } -} - */ diff --git a/plugins/haptics/src/models.rs b/plugins/haptics/src/models.rs index 9f3b2035..50a1fb16 100644 --- a/plugins/haptics/src/models.rs +++ b/plugins/haptics/src/models.rs @@ -3,9 +3,9 @@ // SPDX-License-Identifier: MIT 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")] pub struct HapticsOptions { // 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")] pub enum ImpactFeedbackStyle { Light, @@ -24,7 +25,8 @@ pub enum ImpactFeedbackStyle { 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")] pub enum NotificationFeedbackType { #[default]