utils/haptics.ts: tick('ptt-on' | 'ptt-off' | 'reaction') → 10/10/8 ms
navigator.vibrate, a no-op without the API (iOS), when the system prefers
reduced motion, or when the new Settings → Calls "Haptic Feedback" switch
(default on, only rendered where the API exists) is off. PTT is observed
once through pttActiveAtom so the keyboard, global-hotkey and on-screen
paths all tick; reactions tick where the reaction event is sent in the
room and thread timelines (quick bar, hover bar, sheet and emoji board
all funnel there).
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PPmy3tPq869XDW4njjVaKA
22 lines
767 B
TypeScript
22 lines
767 B
TypeScript
import { useEffect, useRef } from 'react';
|
|
import { useAtomValue } from 'jotai';
|
|
import { pttActiveAtom } from './useCallHotkeys';
|
|
import { useSetting } from '../state/hooks/settings';
|
|
import { settingsAtom } from '../state/settings';
|
|
import { tick } from '../utils/haptics';
|
|
|
|
/**
|
|
* [Gitea #125] One observer for every push-to-talk path (keyboard, global
|
|
* hotkey, on-screen chip): a tick on engage and on release.
|
|
*/
|
|
export function usePttHaptics(): void {
|
|
const active = useAtomValue(pttActiveAtom);
|
|
const [enabled] = useSetting(settingsAtom, 'hapticFeedback');
|
|
const prev = useRef(active);
|
|
useEffect(() => {
|
|
if (prev.current === active) return;
|
|
prev.current = active;
|
|
tick(active ? 'ptt-on' : 'ptt-off', enabled);
|
|
}, [active, enabled]);
|
|
}
|