12 Haptics
原文链接: https://tauri.app/plugin/haptics/
在 Android 和 iOS 上提供触觉反馈与振动。
支持的平台
| 平台 | 支持程度 | 说明 |
|---|
| Windows | 不支持 | |
| Linux | 不支持 | |
| macOS | 不支持 | |
| Android | 完整支持 | |
| iOS | 完整支持 | |
设置
自动
使用你的项目包管理器添加依赖:
1
| npm run tauri add haptics
|
1
| yarn run tauri add haptics
|
1
| deno task tauri add haptics
|
1
| cargo tauri add haptics
|
手动
在 src-tauri 文件夹中运行以下命令,把插件加入 Cargo.toml 里的项目依赖:
1
| cargo add tauri-plugin-haptics
|
修改 lib.rs 初始化插件:
1
2
3
4
5
6
7
| #[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
tauri::Builder::default()
.plugin(tauri_plugin_haptics::init())
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
|
用你偏好的 JavaScript 包管理器安装 JavaScript 端绑定:
1
| npm install @tauri-apps/plugin-haptics
|
1
| yarn add @tauri-apps/plugin-haptics
|
1
| pnpm add @tauri-apps/plugin-haptics
|
1
| deno add npm:@tauri-apps/plugin-haptics
|
1
| bun add @tauri-apps/plugin-haptics
|
用法
haptics 插件在 JavaScript 中可用。
1
2
3
4
5
6
7
8
9
10
11
| import {
vibrate,
impactFeedback,
notificationFeedback,
selectionFeedback,
} from '@tauri-apps/plugin-haptics';
await vibrate(1);
await impactFeedback('medium');
await notificationFeedback('warning');
await selectionFeedback();
|
权限
默认情况下,所有有潜在危险的插件命令和作用域都被阻止,无法访问。你必须在 capabilities 配置中修改权限才能启用它们。
更多信息请参阅能力概述,以及使用插件权限的分步指南。
1
2
3
4
5
6
| {
"permissions": [
...,
"haptics:default"
]
}
|