2025-09-19 16:17:14 +08:00
|
|
|
// 轻量平台检测,避免在 SSR 或无 navigator 的环境报错
|
|
|
|
|
export const isMac = (): boolean => {
|
|
|
|
|
try {
|
|
|
|
|
const ua = navigator.userAgent || "";
|
|
|
|
|
const plat = (navigator.platform || "").toLowerCase();
|
|
|
|
|
return /mac/i.test(ua) || plat.includes("mac");
|
|
|
|
|
} catch {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const isWindows = (): boolean => {
|
|
|
|
|
try {
|
|
|
|
|
const ua = navigator.userAgent || "";
|
|
|
|
|
return /windows|win32|win64/i.test(ua);
|
|
|
|
|
} catch {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const isLinux = (): boolean => {
|
|
|
|
|
try {
|
|
|
|
|
const ua = navigator.userAgent || "";
|
|
|
|
|
// WebKitGTK/Chromium 在 Linux/Wayland/X11 下 UA 通常包含 Linux 或 X11
|
2025-10-08 21:22:56 +08:00
|
|
|
return (
|
|
|
|
|
/linux|x11/i.test(ua) && !/android/i.test(ua) && !isMac() && !isWindows()
|
|
|
|
|
);
|
2025-09-19 16:17:14 +08:00
|
|
|
} catch {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
};
|