()
| 40 | import { VolumeUpIcon } from '../icons/VolumeUpIcon'; |
| 41 | |
| 42 | export const SystemSettings: FC = () => { |
| 43 | const { |
| 44 | settings, |
| 45 | updateSetting, |
| 46 | shortcutRegistrationError, |
| 47 | clearShortcutRegistrationError, |
| 48 | } = useAppContext(); |
| 49 | |
| 50 | const [recordingShortcut, setRecordingShortcut] = useState(false); |
| 51 | const [liveModifierAccelerator, setLiveModifierAccelerator] = useState(''); |
| 52 | const shortcutRowRef = useRef<HTMLDivElement>(null); |
| 53 | const isMac = window.gitify.platform.isMacOS(); |
| 54 | |
| 55 | useEffect(() => { |
| 56 | if (!recordingShortcut) { |
| 57 | return; |
| 58 | } |
| 59 | |
| 60 | const onPointerDown = (event: PointerEvent) => { |
| 61 | if (shortcutRowRef.current?.contains(event.target as Node)) { |
| 62 | return; |
| 63 | } |
| 64 | setRecordingShortcut(false); |
| 65 | }; |
| 66 | |
| 67 | document.addEventListener('pointerdown', onPointerDown, true); |
| 68 | return () => { |
| 69 | document.removeEventListener('pointerdown', onPointerDown, true); |
| 70 | }; |
| 71 | }, [recordingShortcut]); |
| 72 | |
| 73 | useEffect(() => { |
| 74 | if (!recordingShortcut) { |
| 75 | setLiveModifierAccelerator(''); |
| 76 | return; |
| 77 | } |
| 78 | |
| 79 | const activeModifierAccelerator = (event: KeyboardEvent) => |
| 80 | MODIFIER_SEGMENTS.filter((m) => m.test(event)) |
| 81 | .map((m) => m.accelerator) |
| 82 | .join('+'); |
| 83 | |
| 84 | const onKeyDown = (event: KeyboardEvent) => { |
| 85 | event.preventDefault(); |
| 86 | event.stopPropagation(); |
| 87 | |
| 88 | setLiveModifierAccelerator(activeModifierAccelerator(event)); |
| 89 | |
| 90 | const accelerator = keyboardEventToAccelerator(event); |
| 91 | if (accelerator) { |
| 92 | clearShortcutRegistrationError(); |
| 93 | updateSetting('openGitifyShortcut', accelerator); |
| 94 | setLiveModifierAccelerator(''); |
| 95 | setRecordingShortcut(false); |
| 96 | } |
| 97 | }; |
| 98 | |
| 99 | const onKeyUp = (event: KeyboardEvent) => { |
nothing calls this directly
no test coverage detected