Skip to content

Commit 01cde41

Browse files
committed
Improve Mac platform detection by incorporating navigator.userAgentData.platform checks
1 parent 1767353 commit 01cde41

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

‎packages/ui/src/components/editor/panel/ChatInput/ChatInput.tsx‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,18 @@ export const ChatInput: React.FC<ChatInputProps> = (props) => {
5858
is_history_enabled
5959
} = use_handlers(props)
6060

61-
const is_mac = useMemo(
62-
() => navigator.platform.toUpperCase().indexOf('MAC') >= 0,
63-
[]
64-
)
61+
const is_mac = useMemo(() => {
62+
if (typeof navigator == 'undefined') return false
63+
const any_nav = navigator as any
64+
const uach_platform: string | undefined = any_nav?.userAgentData?.platform
65+
if (typeof uach_platform == 'string') {
66+
return uach_platform.toLowerCase().includes('mac')
67+
}
68+
if (typeof navigator.userAgent == 'string') {
69+
return /mac/i.test(navigator.userAgent)
70+
}
71+
return false
72+
}, [])
6573
const mod_key = is_mac ? 'cmd' : 'ctrl'
6674

6775
useEffect(() => {

0 commit comments

Comments
 (0)