25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。
TypeScript aicliclickhousedatabasedatabase-clientdatabase-managementdockerguimcpmongodbmysqlpostgresqlredisrustsql-serversqlitetaurivue
fix(website): detect Intel Macs for downloads
t8y22346dbbdd737
diff --git a/docs/components/landing/InstallTabs.tsx b/docs/components/landing/InstallTabs.tsxindex e6a0163b46..6bd4cc48ce 100644--- a/docs/components/landing/InstallTabs.tsx+++ b/docs/components/landing/InstallTabs.tsx@@ -3,6 +3,7 @@import { ChevronDown, Download, Server } from "lucide-react";import { useEffect, useMemo, useState } from "react";import { createInstallOptions } from "@/lib/downloadLinks";+import { detectPlatformId } from "@/lib/platformDetection";type InstallTabsProps = {lang: "en" | "cn";@@ -32,14 +33,6 @@ const platformIconPaths = {},};-function detectPlatformId(): string {- if (typeof navigator === "undefined") return "macos-arm";- const ua = navigator.userAgent.toLowerCase();- if (ua.includes("win")) return "windows";- if (ua.includes("linux")) return ua.includes("aarch64") || ua.includes("arm") ? "linux-arm" : "linux";- return "macos-arm";-}-function PlatformIcon({ id, size, variant }: { id: string; size: number; variant: "dark" | "light" }) {const src = platformIconPaths[variant][id as keyof (typeof platformIconPaths)["dark"]];if (!src) return <Server size={size} />;@@ -52,7 +45,15 @@ export function InstallTabs({ lang, version }: InstallTabsProps) {const [platformId, setPlatformId] = useState("macos-arm");useEffect(() => {- setPlatformId(detectPlatformId());+ let cancelled = false;++ void detectPlatformId(navigator).then((detectedPlatformId) => {+ if (!cancelled) setPlatformId(detectedPlatformId);+ });++ return () => {+ cancelled = true;+ };}, []);useEffect(() => {diff --git a/docs/lib/platformDetection.test.ts b/docs/lib/platformDetection.test.tsnew file mode 100644index 0000000000..74016d5f99--- /dev/null+++ b/docs/lib/platformDetection.test.ts@@ -0,0 +1,40 @@+import assert from "node:assert/strict";+import { test } from "vitest";++import { detectPlatformId } from "./platformDetection";++const macUserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 Chrome/150.0.0.0 Safari/537.36";++test("detects an Intel Mac from Chromium architecture hints", async () => {+ const platformId = await detectPlatformId({+ userAgent: macUserAgent,+ userAgentData: {+ platform: "macOS",+ getHighEntropyValues: async () => ({ architecture: "x86" }),+ },+ });++ assert.equal(platformId, "macos-intel");+});++test("does not trust the Intel token in an Apple Silicon Mac user agent", async () => {+ const platformId = await detectPlatformId({+ userAgent: macUserAgent,+ userAgentData: {+ platform: "macOS",+ getHighEntropyValues: async () => ({ architecture: "arm" }),+ },+ });++ assert.equal(platformId, "macos-arm");+});++test("keeps the Apple Silicon fallback when architecture hints are unavailable", async () => {+ assert.equal(await detectPlatformId({ userAgent: macUserAgent }), "macos-arm");+});++test("keeps existing Windows and Linux detection", async () => {+ assert.equal(await detectPlatformId({ userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64)" }), "windows");+ assert.equal(await detectPlatformId({ userAgent: "Mozilla/5.0 (X11; Linux x86_64)" }), "linux");+ assert.equal(await detectPlatformId({ userAgent: "Mozilla/5.0 (X11; Linux aarch64)" }), "linux-arm");+});diff --git a/docs/lib/platformDetection.ts b/docs/lib/platformDetection.tsnew file mode 100644index 0000000000..0a3b71c953--- /dev/null+++ b/docs/lib/platformDetection.ts@@ -0,0 +1,37 @@+export type DownloadPlatformId = "linux-arm" | "linux" | "macos-arm" | "macos-intel" | "windows";++type UserAgentDataLike = {+ platform?: string;+ getHighEntropyValues?: (hints: string[]) => Promise<{ architecture?: string }>;+};++export type NavigatorLike = {+ userAgent: string;+ userAgentData?: UserAgentDataLike;+};++async function detectArchitecture(navigatorLike: NavigatorLike): Promise<string> {+ try {+ const values = await navigatorLike.userAgentData?.getHighEntropyValues?.(["architecture"]);+ return values?.architecture?.toLowerCase() ?? "";+ } catch {+ return "";+ }+}++export async function detectPlatformId(navigatorLike?: NavigatorLike): Promise<DownloadPlatformId> {+ if (!navigatorLike) return "macos-arm";++ const userAgent = navigatorLike.userAgent.toLowerCase();+ const platform = navigatorLike.userAgentData?.platform?.toLowerCase() ?? "";+ if (userAgent.includes("win") || platform === "windows") return "windows";++ const architecture = await detectArchitecture(navigatorLike);+ const isArm = architecture.includes("arm") || userAgent.includes("aarch64") || userAgent.includes("arm");++ if (userAgent.includes("linux") || platform === "linux") return isArm ? "linux-arm" : "linux";+ if (userAgent.includes("macintosh") || platform === "macos") {+ if (architecture.includes("x86") || architecture.includes("amd64") || architecture.includes("x64")) return "macos-intel";+ }+ return "macos-arm";+}