feat(website): improve ARM detection

This commit is contained in:
Elian Doran 2025-09-30 22:20:10 +03:00
parent c74ba44b91
commit 80be4cc6b8
No known key found for this signature in database
7 changed files with 29 additions and 8 deletions

View File

@ -24,5 +24,5 @@ dist-ssr
*.sw?
*.d.ts
!types-assets.d.ts
!types.d.ts
*.map

View File

@ -17,6 +17,7 @@
"eslint": "^9.36.0",
"eslint-config-preact": "^2.0.0",
"typescript": "^5.9.2",
"user-agent-data-types": "0.4.2",
"vite": "^7.0.4"
},
"eslintConfig": {

View File

@ -11,7 +11,9 @@ interface DownloadButtonProps {
export default function DownloadButton({ big }: DownloadButtonProps) {
const [ recommendedDownload, setRecommendedDownload ] = useState<RecommendedDownload | null>();
useEffect(() => setRecommendedDownload(getRecommendedDownload()), []);
useEffect(() => {
getRecommendedDownload()?.then(setRecommendedDownload);
}, []);
return (recommendedDownload &&
<>

View File

@ -188,9 +188,14 @@ export function buildDownloadUrl(app: App, platform: Platform, format: string, a
}
}
export function getArchitecture(): Architecture | null {
export async function getArchitecture(): Promise<Architecture | null> {
if (typeof window === "undefined") return null;
if (navigator.userAgentData) {
const { architecture } = await navigator.userAgentData.getHighEntropyValues(["architecture"]);
return architecture?.startsWith("arm") ? "arm64" : "x64";
}
const userAgent = navigator.userAgent.toLowerCase();
if (userAgent.includes('arm64') || userAgent.includes('aarch64')) {
return 'arm64';
@ -212,10 +217,10 @@ export function getPlatform(): Platform | null {
}
}
export function getRecommendedDownload(): RecommendedDownload | null {
export async function getRecommendedDownload(): Promise<RecommendedDownload | null> {
if (typeof window === "undefined") return null;
const architecture = getArchitecture();
const architecture = await getArchitecture();
const platform = getPlatform();
if (!platform || !architecture) return null;

View File

@ -14,7 +14,7 @@ export default function DownloadPage() {
const [ userPlatform, setUserPlatform ] = useState<Platform>();
useLayoutEffect(() => {
setCurrentArch(getArchitecture() ?? "x64");
getArchitecture().then((arch) => setCurrentArch(arch ?? "x64"));
setUserPlatform(getPlatform() ?? "windows");
}, []);

1
apps/website/src/types.d.ts vendored Normal file
View File

@ -0,0 +1 @@
/// <reference types="user-agent-data-types" />

16
pnpm-lock.yaml generated
View File

@ -787,6 +787,9 @@ importers:
typescript:
specifier: ^5.9.2
version: 5.9.2
user-agent-data-types:
specifier: 0.4.2
version: 0.4.2
vite:
specifier: ^7.0.4
version: 7.1.7(@types/node@24.6.0)(jiti@2.6.0)(less@4.1.3)(lightningcss@1.30.1)(sass-embedded@1.91.0)(sass@1.91.0)(terser@5.44.0)(tsx@4.20.6)(yaml@2.8.1)
@ -13299,6 +13302,9 @@ packages:
peerDependencies:
react: ^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0
user-agent-data-types@0.4.2:
resolution: {integrity: sha512-jXep3kO/dGNmDOkbDa8ccp4QArgxR4I76m3QVcJ1aOF0B9toc+YtSXtX5gLdDTZXyWlpQYQrABr6L1L2GZOghw==}
userhome@1.0.1:
resolution: {integrity: sha512-5cnLm4gseXjAclKowC4IjByaGsjtAoV6PrOQOljplNB54ReUYJP8HdAFq2muHinSDAh09PPX/uXDPfdxRHvuSA==}
engines: {node: '>= 0.8.0'}
@ -14680,6 +14686,8 @@ snapshots:
'@ckeditor/ckeditor5-typing': 46.1.1
'@ckeditor/ckeditor5-utils': 46.1.1
ckeditor5: 46.1.1(patch_hash=8331a09d41443b39ea1c784daaccfeb0da4f9065ed556e7de92e9c77edd9eb41)
transitivePeerDependencies:
- supports-color
'@ckeditor/ckeditor5-autosave@46.1.1':
dependencies:
@ -14710,6 +14718,8 @@ snapshots:
'@ckeditor/ckeditor5-ui': 46.1.1
'@ckeditor/ckeditor5-utils': 46.1.1
ckeditor5: 46.1.1(patch_hash=8331a09d41443b39ea1c784daaccfeb0da4f9065ed556e7de92e9c77edd9eb41)
transitivePeerDependencies:
- supports-color
'@ckeditor/ckeditor5-bookmark@46.1.1':
dependencies:
@ -15026,8 +15036,6 @@ snapshots:
'@ckeditor/ckeditor5-utils': 46.1.1
ckeditor5: 46.1.1(patch_hash=8331a09d41443b39ea1c784daaccfeb0da4f9065ed556e7de92e9c77edd9eb41)
es-toolkit: 1.39.5
transitivePeerDependencies:
- supports-color
'@ckeditor/ckeditor5-editor-multi-root@46.1.1':
dependencies:
@ -15221,6 +15229,8 @@ snapshots:
'@ckeditor/ckeditor5-widget': 46.1.1
ckeditor5: 46.1.1(patch_hash=8331a09d41443b39ea1c784daaccfeb0da4f9065ed556e7de92e9c77edd9eb41)
es-toolkit: 1.39.5
transitivePeerDependencies:
- supports-color
'@ckeditor/ckeditor5-icons@46.1.1': {}
@ -29683,6 +29693,8 @@ snapshots:
dependencies:
react: 16.14.0
user-agent-data-types@0.4.2: {}
userhome@1.0.1: {}
username@5.1.0: