Skip to content

Commit 4237e2e

Browse files
committed
upd: Modify macOS system architecture detection
1 parent 1fc4e58 commit 4237e2e

File tree

1 file changed

+23
-19
lines changed

1 file changed

+23
-19
lines changed

src/server/modules/platform/platform.service.ts

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,43 +29,47 @@ export default class PlatformService {
2929

3030
/**
3131
* 从 User-Agent 字符串中检测架构
32+
* Mac 默认 ARM64,Windows 基于 UA 判断
3233
*/
3334
public getArchitectureFromUA(userAgent: string): 'x64' | 'arm64' | 'Unknown' {
35+
if (!userAgent) return 'Unknown';
3436
const ua = userAgent.toLowerCase();
3537

36-
// ARM64 检测
37-
if (ua.includes('arm64') || ua.includes('aarch64')) {
38+
// === Mac 架构检测 ===
39+
if (ua.includes('mac') || ua.includes('darwin')) {
40+
// Mac 默认假设为 ARM64 (Apple Silicon)
3841
return 'arm64';
3942
}
4043

41-
// Apple Silicon Mac 检测 (基于 Safari 版本和特征)
42-
if (ua.includes('mac') && ua.includes('safari')) {
43-
// Safari 14.0+ 更可能是 Apple Silicon (启发式)
44-
const safariMatch = ua.match(/version\/([\d.]+).*safari/);
45-
if (safariMatch) {
46-
const version = parseFloat(safariMatch[1]);
47-
if (version >= 14.0) {
48-
// 进一步检查是否有 Apple Silicon 的迹象
49-
if (ua.includes('applewebkit/605.1.15') || ua.includes('version/14')) {
50-
return 'arm64';
51-
}
52-
}
44+
// === Windows 架构检测 ===
45+
if (ua.includes('windows') || ua.includes('win32') || ua.includes('win64')) {
46+
// ARM64 Windows 检测
47+
if (ua.includes('arm64') || ua.includes('aarch64')) {
48+
return 'arm64';
49+
}
50+
51+
// x64 Windows 检测
52+
if (ua.includes('win64') || ua.includes('x64') || ua.includes('wow64') || ua.includes('amd64') || ua.includes('x86_64')) {
53+
return 'x64';
5354
}
54-
}
5555

56-
// x64 检测
57-
if (ua.includes('x64') || ua.includes('x86_64') || ua.includes('amd64') || ua.includes('wow64')) {
56+
// Windows 默认假设为 x64
5857
return 'x64';
5958
}
6059

61-
// 默认假设 x64 (大多数桌面系统)
62-
if (ua.includes('windows') || ua.includes('mac')) {
60+
// === 通用架构检测 ===
61+
if (ua.includes('arm64') || ua.includes('aarch64')) {
62+
return 'arm64';
63+
}
64+
65+
if (ua.includes('x64') || ua.includes('x86_64') || ua.includes('amd64')) {
6366
return 'x64';
6467
}
6568

6669
return 'Unknown';
6770
}
6871

72+
6973
public async getReleases(): Promise<GetReleasesDTO | null> {
7074
try {
7175
const response = await fetch('https://cdn.algoux.cn/algo-bootstrap/version.json?t=' + Date.now());

0 commit comments

Comments
 (0)