chore: update documentation

This commit is contained in:
Lucas Nogueira
2026-09-22 11:30:47 -03:00
parent d869c162a7
commit a87a3c7d44
104 changed files with 4875 additions and 222 deletions
+8
View File
@@ -18,18 +18,26 @@ pub fn init<R: Runtime, C: DeserializeOwned>(
pub struct Haptics<R: Runtime>(AppHandle<R>);
impl<R: Runtime> Haptics<R> {
/// No-op on desktop; haptic feedback is not supported on Linux, macOS or Windows. Always
/// returns `Ok`.
pub fn vibrate(&self, _duration: u32) -> crate::Result<()> {
Ok(())
}
/// No-op on desktop; haptic feedback is not supported on Linux, macOS or Windows. Always
/// returns `Ok`.
pub fn impact_feedback(&self, _style: ImpactFeedbackStyle) -> crate::Result<()> {
Ok(())
}
/// No-op on desktop; haptic feedback is not supported on Linux, macOS or Windows. Always
/// returns `Ok`.
pub fn notification_feedback(&self, _type: NotificationFeedbackType) -> crate::Result<()> {
Ok(())
}
/// No-op on desktop; haptic feedback is not supported on Linux, macOS or Windows. Always
/// returns `Ok`.
pub fn selection_feedback(&self) -> crate::Result<()> {
Ok(())
}
+5
View File
@@ -4,13 +4,18 @@
use serde::{ser::Serializer, Serialize};
/// Alias for a [`std::result::Result`] with the error type [`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)
/// Errors returned by the haptics APIs.
#[derive(Debug, thiserror::Error)]
#[cfg_attr(feature = "specta", derive(specta::Type))]
pub enum Error {
/// The call to the Android or iOS plugin implementation failed, either because the
/// arguments could not be serialized, the response could not be deserialized, or the
/// native side rejected the call. Only produced on Android and iOS.
#[cfg(mobile)]
#[error(transparent)]
PluginInvoke(
+1
View File
@@ -33,6 +33,7 @@ pub use mobile::Haptics;
/// Extensions to [`tauri::App`], [`tauri::AppHandle`], [`tauri::WebviewWindow`], [`tauri::Webview`] and [`tauri::Window`] to access the haptics APIs.
pub trait HapticsExt<R: Runtime> {
/// Returns a handle to the [`Haptics`] APIs.
fn haptics(&self) -> &Haptics<R>;
}
+29
View File
@@ -32,18 +32,40 @@ pub fn init<R: Runtime, C: DeserializeOwned>(
pub struct Haptics<R: Runtime>(PluginHandle<R>);
impl<R: Runtime> Haptics<R> {
/// Triggers a vibration for `duration` milliseconds.
///
/// On iOS this plays a continuous [Core Haptics](https://developer.apple.com/documentation/corehaptics)
/// pattern when the device supports it, falling back to the system alert vibration
/// otherwise. On Android it uses [`Vibrator`](https://developer.android.com/reference/android/os/Vibrator).
///
/// # Errors
///
/// Returns [`Error::PluginInvoke`](crate::Error::PluginInvoke) if the underlying Android or
/// iOS plugin invocation fails.
pub fn vibrate(&self, duration: u32) -> crate::Result<()> {
self.0
.run_mobile_plugin("vibrate", VibratePayload { duration })
.map_err(Into::into)
}
/// Triggers an impact-feedback haptic with the given [`ImpactFeedbackStyle`].
///
/// # Errors
///
/// Returns [`Error::PluginInvoke`](crate::Error::PluginInvoke) if the underlying Android or
/// iOS plugin invocation fails.
pub fn impact_feedback(&self, style: ImpactFeedbackStyle) -> crate::Result<()> {
self.0
.run_mobile_plugin("impactFeedback", ImpactFeedbackPayload { style })
.map_err(Into::into)
}
/// Triggers a notification-feedback haptic for the given [`NotificationFeedbackType`].
///
/// # Errors
///
/// Returns [`Error::PluginInvoke`](crate::Error::PluginInvoke) if the underlying Android or
/// iOS plugin invocation fails.
pub fn notification_feedback(&self, r#type: NotificationFeedbackType) -> crate::Result<()> {
self.0
.run_mobile_plugin(
@@ -53,6 +75,13 @@ impl<R: Runtime> Haptics<R> {
.map_err(Into::into)
}
/// Triggers a haptic indicating that a selection changed, e.g. when the value of a picker
/// control changes.
///
/// # Errors
///
/// Returns [`Error::PluginInvoke`](crate::Error::PluginInvoke) if the underlying Android or
/// iOS plugin invocation fails.
pub fn selection_feedback(&self) -> crate::Result<()> {
self.0
.run_mobile_plugin("selectionFeedback", ())
+18
View File
@@ -13,24 +13,42 @@ pub struct HapticsOptions {
}
*/
/// The style of an impact-feedback haptic.
///
/// On iOS this maps directly to a `UIImpactFeedbackGenerator.FeedbackStyle` case. On Android,
/// which has no equivalent system API, each style instead plays a distinct vibration waveform of
/// increasing intensity. Has no effect on desktop platforms. Defaults to `Medium`.
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "specta", derive(specta::Type))]
#[serde(rename_all = "camelCase")]
pub enum ImpactFeedbackStyle {
/// A collision between small, light user interface elements.
Light,
/// A collision between moderately sized user interface elements.
#[default]
Medium,
/// A collision between large, heavy user interface elements.
Heavy,
/// A soft, muted impact between user interface elements.
Soft,
/// A sharp, rigid impact between user interface elements.
Rigid,
}
/// The type of notification feedback, indicating the outcome of a task or action.
///
/// On iOS this maps directly to a `UINotificationFeedbackGenerator.FeedbackType` case. On
/// Android, which has no equivalent system API, each type instead plays a distinct vibration
/// waveform. Has no effect on desktop platforms. Defaults to `Success`.
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "specta", derive(specta::Type))]
#[serde(rename_all = "camelCase")]
pub enum NotificationFeedbackType {
/// A task or action has completed successfully.
#[default]
Success,
/// A task or action has produced a warning.
Warning,
/// A task or action has failed.
Error,
}