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]);
|
||
|
|
}
|