mirror of
https://github.com/Hmbown/DeepSeek-TUI.git
synced 2026-09-03 06:50:13 +08:00
detectFromBrowserSignals declared 'macos-x64' in its Arch union but could never return it: every non-Windows, non-Linux UA fell through to 'macos-arm64', silently handing Intel Mac users the Apple Silicon binary snippet. Since Big Sur the macOS UA reports 'Intel Mac OS X' on Apple Silicon too, so UA parsing fundamentally cannot distinguish the two — only User-Agent Client Hints can. The component already requests architecture/bitness hints; the detector now honors them on the macOS branch (x86 -> macos-x64). Without hints the default stays arm64 (every Mac sold since late 2020) and the page's existing arch chooser remains the honest fallback, so nobody is silently misdetected. Vitest pins: x86 hint -> macos-x64, arm hint -> macos-arm64, and the deliberate no-hint arm64 default on the frozen Intel UA. Agent-assisted change.
44 lines
1.3 KiB
TypeScript
44 lines
1.3 KiB
TypeScript
export type Arch =
|
|
| "macos-arm64"
|
|
| "macos-x64"
|
|
| "linux-x64"
|
|
| "linux-arm64"
|
|
| "windows-x64"
|
|
| "windows-arm64";
|
|
|
|
export interface UserAgentArchitecture {
|
|
architecture?: string;
|
|
bitness?: string;
|
|
}
|
|
|
|
export function detectFromBrowserSignals(
|
|
userAgent: string,
|
|
userAgentArchitecture?: UserAgentArchitecture,
|
|
): Arch {
|
|
const ua = userAgent.toLowerCase();
|
|
const architecture = userAgentArchitecture?.architecture?.toLowerCase();
|
|
const bitness = userAgentArchitecture?.bitness;
|
|
if (ua.includes("win")) {
|
|
if (
|
|
architecture === "arm64" ||
|
|
(architecture === "arm" && bitness === "64") ||
|
|
ua.includes("aarch64") ||
|
|
ua.includes("arm64")
|
|
) {
|
|
return "windows-arm64";
|
|
}
|
|
return "windows-x64";
|
|
}
|
|
if (ua.includes("linux")) {
|
|
if (ua.includes("aarch64") || ua.includes("arm64")) return "linux-arm64";
|
|
return "linux-x64";
|
|
}
|
|
// macOS. Since Big Sur the UA reports "Intel Mac OS X" on Apple Silicon
|
|
// too, so the UA string cannot distinguish architectures — only
|
|
// User-Agent Client Hints can (#5168). Without hints we default to arm64
|
|
// (every Mac sold since late 2020); the arch chooser on the install page
|
|
// stays the honest fallback for Intel users.
|
|
if (architecture === "x86") return "macos-x64";
|
|
return "macos-arm64";
|
|
}
|