Skip to content

Commit f458995

Browse files
feat: improve auto-detection (#698)
1 parent 339c450 commit f458995

1 file changed

Lines changed: 32 additions & 15 deletions

File tree

apps/landing-page/src/app/(home)/page.client.tsx

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -150,22 +150,31 @@ export default function HomeClient({ release }: { release: Release }) {
150150
return 'unknown';
151151
}
152152

153-
function detectArch():
154-
| 'x86_64'
155-
| 'arm64'
156-
| 'armv7'
157-
| 'i386'
158-
| 'unknown' {
153+
function detectArch(): 'x86_64' | 'arm64' | 'armv7' | 'i386' | 'unknown' {
159154
if (typeof navigator === 'undefined') return 'unknown';
160-
const ua =
161-
(navigator.userAgent || navigator.platform || '').toLowerCase();
155+
const ua = (
156+
navigator.userAgent ||
157+
navigator.platform ||
158+
''
159+
).toLowerCase();
162160

163161
if (ua.includes('aarch64') || ua.includes('arm64')) return 'arm64';
164-
if (ua.includes('armv7') || ua.includes('armv7l') || ua.includes('armhf'))
162+
if (
163+
ua.includes('armv7') ||
164+
ua.includes('armv7l') ||
165+
ua.includes('armhf')
166+
)
165167
return 'armv7';
166-
if (ua.includes('amd64') || ua.includes('x86_64') || ua.includes('wow64') || ua.includes('win64') || ua.includes('x64'))
168+
if (
169+
ua.includes('amd64') ||
170+
ua.includes('x86_64') ||
171+
ua.includes('wow64') ||
172+
ua.includes('win64') ||
173+
ua.includes('x64')
174+
)
167175
return 'x86_64';
168-
if (ua.includes('i386') || ua.includes('i686') || ua.includes('ia32')) return 'i386';
176+
if (ua.includes('i386') || ua.includes('i686') || ua.includes('ia32'))
177+
return 'i386';
169178
return 'unknown';
170179
}
171180

@@ -206,7 +215,9 @@ export default function HomeClient({ release }: { release: Release }) {
206215
arch = a;
207216
}
208217

209-
const osKey = normalizedOs.includes(':') ? normalizedOs.split(':', 1)[0] : normalizedOs;
218+
const osKey = normalizedOs.includes(':')
219+
? normalizedOs.split(':', 1)[0]
220+
: normalizedOs;
210221
const osKeywords = osKeywordsMap[osKey] || [];
211222
const archKeywords = arch ? archKeywordsMap[arch] || [] : [];
212223

@@ -244,7 +255,10 @@ export default function HomeClient({ release }: { release: Release }) {
244255
}
245256
const osToUse = downloadOS === 'auto' ? detectOS() : downloadOS;
246257
const archToUse = downloadArch === 'auto' ? detectArch() : downloadArch;
247-
const osAndArch = archToUse && archToUse !== 'unknown' ? `${osToUse}:${archToUse}` : osToUse;
258+
const osAndArch =
259+
archToUse && archToUse !== 'unknown'
260+
? `${osToUse}:${archToUse}`
261+
: osToUse;
248262
const asset = findAssetForOS(release, osAndArch);
249263
if (asset) {
250264
// redirect to the asset (GitHub release file)
@@ -254,7 +268,10 @@ export default function HomeClient({ release }: { release: Release }) {
254268
window.location.href = '/download';
255269
}
256270
};
257-
271+
const detectedArchLabel = (() => {
272+
const a = detectArch();
273+
return a && a !== 'unknown' ? ` (${a})` : '';
274+
})();
258275

259276
return (
260277
<main className="relative z-10 mx-auto w-full max-w-7xl px-6">
@@ -338,7 +355,7 @@ export default function HomeClient({ release }: { release: Release }) {
338355
}
339356
className="select variant-form-material"
340357
>
341-
<option value="auto">Auto-detect</option>
358+
<option value="auto">Auto-detect{detectedArchLabel}</option>
342359
<option value="x86_64">x86_64 (amd64)</option>
343360
<option value="arm64">arm64 (aarch64)</option>
344361
<option value="armv7">armv7 (armhf)</option>

0 commit comments

Comments
 (0)