File tree Expand file tree Collapse file tree 1 file changed +32
-1
lines changed
apps/site/hooks/react-client Expand file tree Collapse file tree 1 file changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,37 @@ type UserOSState = {
1515 architecture : Architecture | '' ;
1616} ;
1717
18+ // taken from https://github.com/faisalman/ua-parser-js/issues/732#issue-2348848266
19+ function isAppleSilicon ( ) {
20+ try {
21+ // Best guess if the device uses Apple Silicon: https://stackoverflow.com/a/65412357
22+ const webglContext = document . createElement ( 'canvas' ) . getContext ( 'webgl' ) ;
23+ if ( webglContext == null ) {
24+ return false ;
25+ }
26+ const debugInfo = webglContext . getExtension ( 'WEBGL_debug_renderer_info' ) ;
27+ const renderer =
28+ ( debugInfo &&
29+ webglContext . getParameter ( debugInfo . UNMASKED_RENDERER_WEBGL ) ) ||
30+ '' ;
31+ if ( renderer . match ( / A p p l e / ) && ! renderer . match ( / A p p l e G P U / ) ) {
32+ return true ;
33+ }
34+
35+ if (
36+ webglContext
37+ . getSupportedExtensions ( )
38+ ?. includes ( 'WEBGL_compressed_texture_s3tc_srgb' )
39+ ) {
40+ return true ;
41+ }
42+ } catch {
43+ /**/
44+ }
45+
46+ return false ;
47+ }
48+
1849const useDetectOS = ( ) => {
1950 const [ userOSState , setUserOSState ] = useState < UserOSState > ( {
2051 os : 'LOADING' ,
@@ -41,7 +72,7 @@ const useDetectOS = () => {
4172 // If there is no getHighEntropyValues API on the Browser or it failed to resolve
4273 // we attempt to fallback to what the User Agent indicates
4374 bitness = uaIndicates64 ? '64' : '32' ,
44- architecture = 'x86' ,
75+ architecture = isAppleSilicon ( ) ? 'arm' : 'x86' ,
4576 } ) => {
4677 setUserOSState ( current => ( {
4778 ...current ,
You can’t perform that action at this time.
0 commit comments