wip bsky client for the web & android
bbell.vt3e.cat
1/**
2 * this is v experimental.
3 * for the time being, since i cba to write a capacitor plugin for the system
4 * haptics api, we're just using the browser api.
5 */
6
7import {
8 Haptics,
9 type VibrateOptions,
10 type NotificationOptions,
11 type ImpactOptions,
12 ImpactStyle,
13} from '@capacitor/haptics'
14
15export function isVibrationsEnabled(): boolean {
16 return true
17}
18
19export function tap() {
20 Haptics.vibrate({ duration: 1 })
21}
22
23export async function impact(options?: ImpactOptions): Promise<void> {
24 if (!isVibrationsEnabled()) return
25 try {
26 await Haptics.impact(options || { style: ImpactStyle.Light })
27 } catch {}
28}
29
30export async function notification(options?: NotificationOptions): Promise<void> {
31 if (!isVibrationsEnabled()) return
32 try {
33 await Haptics.notification(options)
34 } catch {}
35}
36
37export async function vibrate(options?: VibrateOptions): Promise<void> {
38 if (!isVibrationsEnabled()) return
39 try {
40 await Haptics.vibrate(options)
41 } catch {}
42}
43
44async function selectionStart(): Promise<void> {
45 if (!isVibrationsEnabled()) return
46 try {
47 await Haptics.selectionStart()
48 } catch {}
49}
50async function selectionChanged(): Promise<void> {
51 if (!isVibrationsEnabled()) return
52 try {
53 await Haptics.selectionChanged()
54 } catch {}
55}
56async function selectionEnd(): Promise<void> {
57 if (!isVibrationsEnabled()) return
58 try {
59 await Haptics.selectionEnd()
60 } catch {}
61}
62
63export const selection = {
64 start: selectionStart,
65 changed: selectionChanged,
66 end: selectionEnd,
67}