File tree Expand file tree Collapse file tree 1 file changed +27
-1
lines changed
apps/site/hooks/react-client Expand file tree Collapse file tree 1 file changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,32 @@ 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 w = document . createElement ( 'canvas' ) . getContext ( 'webgl' ) ;
23+ if ( w == null ) {
24+ return false ;
25+ }
26+ const d = w . getExtension ( 'WEBGL_debug_renderer_info' ) ;
27+ const g = ( d && w . getParameter ( d . UNMASKED_RENDERER_WEBGL ) ) || '' ;
28+ if ( g . match ( / A p p l e / ) && ! g . match ( / A p p l e G P U / ) ) {
29+ return true ;
30+ }
31+
32+ if (
33+ w . getSupportedExtensions ( ) ?. includes ( 'WEBGL_compressed_texture_s3tc_srgb' )
34+ ) {
35+ return true ;
36+ }
37+ } catch {
38+ /**/
39+ }
40+
41+ return false ;
42+ }
43+
1844const useDetectOS = ( ) => {
1945 const [ userOSState , setUserOSState ] = useState < UserOSState > ( {
2046 os : 'LOADING' ,
@@ -41,7 +67,7 @@ const useDetectOS = () => {
4167 // If there is no getHighEntropyValues API on the Browser or it failed to resolve
4268 // we attempt to fallback to what the User Agent indicates
4369 bitness = uaIndicates64 ? '64' : '32' ,
44- architecture = 'x86' ,
70+ architecture = isAppleSilicon ( ) ? 'arm64' : 'x86' ,
4571 } ) => {
4672 setUserOSState ( current => ( {
4773 ...current ,
You can’t perform that action at this time.
0 commit comments