| 1 | export type Arch = |
| 2 | | "macos-arm64" |
| 3 | | "macos-x64" |
| 4 | | "linux-x64" |
| 5 | | "linux-arm64" |
| 6 | | "windows-x64" |
| 7 | | "windows-arm64"; |
| 8 | |
| 9 | export interface UserAgentArchitecture { |
| 10 | architecture?: string; |
| 11 | bitness?: string; |
| 12 | } |
| 13 | |
| 14 | export function detectFromBrowserSignals( |
| 15 | userAgent: string, |
| 16 | userAgentArchitecture?: UserAgentArchitecture, |
| 17 | ): Arch { |
| 18 | const ua = userAgent.toLowerCase(); |
| 19 | const architecture = userAgentArchitecture?.architecture?.toLowerCase(); |
| 20 | const bitness = userAgentArchitecture?.bitness; |
| 21 | if (ua.includes("win")) { |
| 22 | if ( |
| 23 | architecture === "arm64" || |
| 24 | (architecture === "arm" && bitness === "64") || |
| 25 | ua.includes("aarch64") || |
| 26 | ua.includes("arm64") |
| 27 | ) { |
| 28 | return "windows-arm64"; |
| 29 | } |
| 30 | return "windows-x64"; |
| 31 | } |
| 32 | if (ua.includes("linux")) { |
| 33 | if (ua.includes("aarch64") || ua.includes("arm64")) return "linux-arm64"; |
| 34 | return "linux-x64"; |
| 35 | } |
| 36 | // macOS. Since Big Sur the UA reports "Intel Mac OS X" on Apple Silicon |
| 37 | // too, so the UA string cannot distinguish architectures — only |
| 38 | // User-Agent Client Hints can (#5168). Without hints we default to arm64 |
| 39 | // (every Mac sold since late 2020); the arch chooser on the install page |
| 40 | // stays the honest fallback for Intel users. |
| 41 | if (architecture === "x86") return "macos-x64"; |
| 42 | return "macos-arm64"; |
| 43 | } |
| 44 |