Utilize the Taptic Engine (TM) on macOS for Tauri v2 apps.
Installations
npm install tauri-plugin-macos-haptics-api
Developer Guide
Typescript
Yes
Module System
ESM
Node Version
20.15.1
NPM Version
10.7.0
Score
70.2
Supply Chain
98.8
Quality
76.9
Maintenance
100
Vulnerability
99.6
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
Rust (47%)
TypeScript (46.7%)
JavaScript (5.22%)
CSS (1.09%)
Developer
itseeleeya
Download Statistics
Total Downloads
149
Last Day
3
Last Week
6
Last Month
16
Last Year
149
GitHub Statistics
3 Stars
15 Commits
1 Watching
2 Branches
1 Contributors
Bundle Size
2.20 kB
Minified
907.00 B
Minified + Gzipped
Package Meta Information
Latest Version
1.0.0
Package Id
tauri-plugin-macos-haptics-api@1.0.0
Unpacked Size
12.98 kB
Size
3.70 kB
File Count
6
NPM Version
10.7.0
Node Version
20.15.1
Publised On
03 Oct 2024
Total Downloads
Cumulative downloads
Total Downloads
149
Last day
0%
3
Compared to previous day
Last week
20%
6
Compared to previous week
Last month
-54.3%
16
Compared to previous month
Last year
0%
149
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
1
Dev Dependencies
4
Tauri Plugin macOS Haptics
Utilize the Taptic Engine™️ on macOS for Tauri v2 apps.
Get the plugin
Using the command line from crates.io:
$ cargo add tauri-plugin-macos-haptics
Or add it manually to Cargo.toml
:
1[target.'cfg(target_os = "macos")'.dependencies] 2tauri-plugin-macos-haptics = "1.0.0"
Note: if you want to include this only on macOS, put
Or get the latest using git:
1[target.'cfg(target_os = "macos")'.dependencies] 2tauri-plugin-macos-haptics = { git = "https://github.com/ItsEeleeya/tauri-plugin-macos-haptics/" }
Get the frontend bindings
pnpm add tauri-plugin-macos-haptics-api
# or
bun add tauri-plugin-macos-haptics-api
# or
npm add tauri-plugin-macos-haptics-api
# or
yarn add tauri-plugin-macos-haptics-api
Usage
1. First initialize the plugin
This is only needed if you want to use it from the frontend.
1fn main() { 2 let mut builder = tauri::Builder::default(); 3 4 #[cfg(target_os = "macos")] 5 { 6 // You can safely init the plugin on any platform. 7 // Or choose to only initialize it on macos. 8 builder = builder.plugin(tauri_plugin_macos_haptics::init()); 9 } 10 11 builder 12 .run(tauri::generate_context!()) 13 .expect("error while running tauri application"); 14}
2. Permissions
Add "macos-haptics:default"
to your permissions.
Usually found under src-tauri/capabilities/*.json
Read more about the specific permissions.
3. Perform a haptic feedback
From Rust:
1 use tauri_plugin_macos_haptics::haptics::*; 2 3 fn provide_feedback() { 4 #[cfg(target_os = "macos")] 5 { 6 use tauri_plugin_macos_haptics::haptics::*; 7 NSHapticFeedbackManager::default_performer().perform(NSHapticFeedbackPattern::Generic, None).ok(); 8 } 9 }
From the frontend (Typescript):
1import { 2 isSupported, 3 perform, 4 HapticFeedbackPattern, 5 PerformanceTime, 6} from "tauri-plugin-macos-haptics-api"; 7 8if (await isSupported()) { 9 perform(HapticFeedbackPattern.LevelChange, PerformanceTime.Now); 10 // Or call the function with no arguments to default to Generic and now. 11}
⚠️ Please note that you should trigger a feedback ONLY in response to user-initiated actions. Ideally, visual feedback, such as a highlight or appearance of an alignment guide, should accompany the feedback.
In some cases, the system may override a call to this method. For example, a Force Touch trackpad won’t provide haptic feedback if the user isn’t touching the trackpad.
Haptic feedback is intended to be provided in response to a user action, such as aligning one object to another. Do not use it to provide feedback for events that are not user initiated. Excessive or unnecessary haptic feedback could be interpreted by the user as a malfunction and could encourage the user to disable haptic feedback entirely.
Learn more about NSHapticFeedbackManager (Apple's documentation)
Contributions
Any contributions are welcomed!
No vulnerabilities found.
No security vulnerabilities found.