Skip to content

Commit

Permalink
Use capacitor for all vibrations
Browse files Browse the repository at this point in the history
  • Loading branch information
benthecarman authored and futurepaul committed Oct 25, 2023
1 parent 5b338b4 commit ffe0088
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/utils/vibrate.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import { Capacitor } from "@capacitor/core";
import { Haptics } from "@capacitor/haptics";
import { NotificationType } from "@capacitor/haptics/dist/esm/definitions";

export const vibrate = async (millis = 250) => {
if (Capacitor.isNativePlatform()) {
try {
await Haptics.vibrate({ duration: millis });
} else {
window.navigator.vibrate(millis);
} catch (error) {
console.warn(error);
}
};

export const vibrateSuccess = async () => {
if (Capacitor.isNativePlatform()) {
try {
await Haptics.notification({ type: NotificationType.Success });
} else {
window.navigator.vibrate([35, 65, 21]);
} catch (error) {
console.warn(error);
}
};

0 comments on commit ffe0088

Please sign in to comment.