fix(marketing): detect Mac chip on homepage download button (#4197)
Co-authored-by: Claude Opus 4.8 <[email protected]> Co-authored-by: Julius Marminge <[email protected]> Co-authored-by: codex <[email protected]>
This commit is contained in:
3 files changed
+56
-1
No files matched your search
@@ -0,0 +1,20 @@
|
||||
import { describe, expect, it } from "vite-plus/test";
|
||||
|
||||
import { macArchFromGpuRenderer } from "./macArch";
|
||||
|
||||
describe("macArchFromGpuRenderer", () => {
|
||||
it("detects explicit Apple Silicon renderers", () => {
|
||||
expect(macArchFromGpuRenderer("Apple M4 Pro")).toBe("arm64");
|
||||
});
|
||||
|
||||
it("prefers an Intel GPU marker even when the renderer also mentions Apple", () => {
|
||||
expect(macArchFromGpuRenderer("ANGLE Metal Renderer: Apple, Intel Iris Plus Graphics")).toBe(
|
||||
"x64",
|
||||
);
|
||||
});
|
||||
|
||||
it("uses x64 for ambiguous Safari and unavailable renderer values", () => {
|
||||
expect(macArchFromGpuRenderer("Apple GPU")).toBe("x64");
|
||||
expect(macArchFromGpuRenderer("")).toBe("x64");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,16 @@
|
||||
const INTEL_GPU_PATTERN = /intel|amd|radeon|nvidia|geforce/i;
|
||||
const APPLE_SILICON_GPU_PATTERN = /\bapple\s+m\d/i;
|
||||
|
||||
export function macArchFromGpuRenderer(renderer: string): "arm64" | "x64" {
|
||||
if (INTEL_GPU_PATTERN.test(renderer)) {
|
||||
return "x64";
|
||||
}
|
||||
if (APPLE_SILICON_GPU_PATTERN.test(renderer)) {
|
||||
return "arm64";
|
||||
}
|
||||
|
||||
// Generic "Apple GPU" renderers are ambiguous on Safari. x64 is the safe
|
||||
// fallback because Apple Silicon can run it through Rosetta, while Intel
|
||||
// Macs cannot run an arm64 build.
|
||||
return "x64";
|
||||
}
|
||||
@@ -391,14 +391,33 @@ const mobileEndorsementRows = [
|
||||
|
||||
<script>
|
||||
import { fetchLatestRelease, RELEASES_URL, type ReleaseAsset } from "../lib/releases";
|
||||
import { macArchFromGpuRenderer } from "../lib/macArch";
|
||||
|
||||
type Platform = { os: "mac" | "win" | "linux"; label: string; arch?: string };
|
||||
|
||||
// navigator.userAgent reports "Intel Mac OS X" on both Intel and Apple Silicon
|
||||
// Macs, so probe the GPU renderer instead: Apple Silicon exposes an "Apple" GPU.
|
||||
function detectMacArch(): "arm64" | "x64" {
|
||||
try {
|
||||
const canvas = document.createElement("canvas");
|
||||
const gl = (canvas.getContext("webgl") ||
|
||||
canvas.getContext("experimental-webgl")) as WebGLRenderingContext | null;
|
||||
const debugInfo = gl?.getExtension("WEBGL_debug_renderer_info");
|
||||
if (gl && debugInfo) {
|
||||
const renderer = String(gl.getParameter(debugInfo.UNMASKED_RENDERER_WEBGL) ?? "");
|
||||
return macArchFromGpuRenderer(renderer);
|
||||
}
|
||||
} catch {
|
||||
// fall through to the default below
|
||||
}
|
||||
return macArchFromGpuRenderer("");
|
||||
}
|
||||
|
||||
function detectPlatform(): Platform | null {
|
||||
const ua = navigator.userAgent;
|
||||
if (/Win/i.test(ua)) return { os: "win", label: "Download for Windows" };
|
||||
if (/Mac/i.test(ua)) {
|
||||
return { os: "mac", label: "Download for macOS", arch: "arm64" };
|
||||
return { os: "mac", label: "Download for macOS", arch: detectMacArch() };
|
||||
}
|
||||
if (/Linux/i.test(ua)) return { os: "linux", label: "Download for Linux" };
|
||||
return null;
|
||||
|
||||
Reference in new issue
Block a user