Some checks failed
integration tests / run-integration-tests (windows-latest) (push) Has been cancelled
Test Rust / test (push) Has been cancelled
test plugins e2e (mobile) / ios (push) Has been cancelled
test plugins e2e / test (map[name:Windows os:windows-latest]) (push) Has been cancelled
test plugins e2e / test (map[name:macOS os:macos-latest]) (push) Has been cancelled
integration tests / run-integration-tests (macos-latest) (push) Has been cancelled
version or publish / version-or-publish (push) Failing after 0s
integration tests / run-integration-tests (ubuntu-22.04) (push) Failing after 0s
Lint JavaScript / eslint (push) Failing after 0s
Sync / sync-to-mirrors (push) Failing after 0s
test plugins e2e (mobile) / android (push) Failing after 0s
test plugins e2e / test (map[name:Linux os:ubuntu-latest]) (push) Failing after 0s
Test Rust / changes (push) Failing after 0s
Lint Rust / changes (push) Failing after 0s
Lint Rust / clippy (push) Has been skipped
Audit Rust / audit-rust (push) Failing after 1s
Audit JavaScript / audit-js (push) Failing after 1s
65 lines
1.7 KiB
Rust
65 lines
1.7 KiB
Rust
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
//! Trigger haptic feedback on supported devices.
|
|
//!
|
|
//! ## Cargo features
|
|
//!
|
|
//! - **specta**: Add support for [`specta::specta`](https://docs.rs/specta/2.0.0-rc.25/specta/attr.specta.html) on structs like [`ImpactFeedbackStyle`], [`NotificationFeedbackType`].
|
|
|
|
use tauri::{
|
|
plugin::{Builder, TauriPlugin},
|
|
Manager, Runtime,
|
|
};
|
|
|
|
pub use models::*;
|
|
|
|
#[cfg(desktop)]
|
|
mod desktop;
|
|
#[cfg(mobile)]
|
|
mod mobile;
|
|
|
|
mod commands;
|
|
mod error;
|
|
mod models;
|
|
|
|
pub use error::{Error, Result};
|
|
|
|
#[cfg(desktop)]
|
|
pub use desktop::Haptics;
|
|
#[cfg(mobile)]
|
|
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>;
|
|
}
|
|
|
|
impl<R: Runtime, T: Manager<R>> crate::HapticsExt<R> for T {
|
|
fn haptics(&self) -> &Haptics<R> {
|
|
self.state::<Haptics<R>>().inner()
|
|
}
|
|
}
|
|
|
|
/// Initializes the plugin.
|
|
pub fn init<R: Runtime>() -> TauriPlugin<R> {
|
|
Builder::new("haptics")
|
|
.invoke_handler(tauri::generate_handler![
|
|
commands::vibrate,
|
|
commands::impact_feedback,
|
|
commands::notification_feedback,
|
|
commands::selection_feedback
|
|
])
|
|
.setup(|app, api| {
|
|
#[cfg(mobile)]
|
|
let haptics = mobile::init(app, api)?;
|
|
#[cfg(desktop)]
|
|
let haptics = desktop::init(app, api)?;
|
|
app.manage(haptics);
|
|
Ok(())
|
|
})
|
|
.build()
|
|
}
|