fix: mac arm通过文件夹打开被判定为intel芯片

mac os升级27 权限问题解决文档
This commit is contained in:
Wxw-Gu committed 2026-11-06 11:10:01 +08:00
1 parent 80e0f43529
commit 05b881d79e
18 files changed
+1066 -29

No files matched your search

+7
View File
@@ -7,6 +7,13 @@ export function buildSafeDiagnosticSummary(
`TraceMemo: ${environment.appVersion}`,
`操作系统: ${environment.osVersion}`,
...(environment.architecture ? [`处理器架构: ${environment.architecture}`] : []),
...(environment.hardwareArchitecture
? [
`硬件架构: ${environment.hardwareArchitecture}${
environment.underARM64Translation ? '(Rosetta 转译)' : ''
}`
]
: []),
`微信客户端: ${environment.wechatVersion}`,
`数据结构: ${environment.dataStructureVersion}`,
`数据目录: ${environment.dataDirectoryDetected ? '已检测到' : '未检测到'}`,
+17
View File
@@ -1,3 +1,5 @@
import type { MacHardwareArch, MacKeyFlow } from './macos-arch'
export type DatabaseKeyValidationCode =
| 'INVALID_FORMAT'
| 'DATABASE_OPEN_FAILED'
@@ -66,7 +68,22 @@ export interface AccountDiscoveryResult {
export interface DatabaseKeyEnvironment {
platform: NodeJS.Platform
/**
* 进程运行架构(`process.arch`)。原生库按它选择,不要用硬件架构替换:
* Rosetta 下的 x64 进程无法加载 arm64 动态库。
*/
architecture?: string
/** CPU 实际架构,来自 `hw.optional.arm64`。 */
hardwareArchitecture?: MacHardwareArch
/** 当前进程是否被 Rosetta 翻译。 */
underARM64Translation?: boolean
/**
* 密钥流程的唯一判据。UI 读它,主进程分流也读它,避免两侧各自推断。
* 缺省时 UI 回落到 `architecture`,用于主进程尚未提供该字段的场景。
*/
macKeyFlow?: MacKeyFlow
/** 架构信号矛盾时的诊断标记,例如 `hardware_arch_unknown`。 */
archAnomalies?: string[]
osVersion: string
appVersion: string
wechatVersion: string
+80
View File
@@ -0,0 +1,80 @@
/**
* macOS 硬件架构与密钥流程的判定规则。
*
* 三个概念必须分开,混用会把 Apple Silicon 上的 x64 运行时当成 Intel 机器:
*
* - hardwareArch CPU 实际架构,来自 `hw.optional.arm64`
* - runtimeArch 当前 Electron 可执行文件的架构(`process.arch`)
* - underARM64Translation 该进程是否被 Rosetta 翻译
*
* 密钥流程只能由这三者共同决定;原生库加载仍然只看 runtimeArch,
* 因为同一进程内不能混用 arm64 与 x86_64 代码。
*/
export type MacHardwareArch = 'arm64' | 'x64' | 'unknown'
export type MacKeyFlow = 'apple-silicon' | 'intel' | 'arch-mismatch' | 'unsupported'
export interface MacArchSnapshot {
platform: NodeJS.Platform
hardwareArch: MacHardwareArch
runtimeArch: string
underARM64Translation: boolean
macKeyFlow: MacKeyFlow
/** 检测到的矛盾信号,仅用于诊断上报,不参与流程选择。 */
anomalies: string[]
}
export interface MacArchInput {
platform: NodeJS.Platform
hardwareArch: MacHardwareArch
runtimeArch: string
underARM64Translation: boolean
}
export const ARCH_MISMATCH_X64_ON_ARM_ERROR =
'当前 Mac 使用 Apple 芯片,但 TraceMemo 正在运行 Intel 版本。请安装 Apple Silicon(arm64)版本后重试。'
/**
* 判定顺序有约束,不能调整:
*
* 1. 转译标志排在 sysctl 之前 —— 它由内核按当前进程直接给出,比一次外部命令更可信。
* 即使 sysctl 失败(hardwareArch 为 unknown),只要进程被翻译且运行 x64,
* 硬件就必然是 Apple 芯片,必须拦下。
* 2. 硬件明确为 arm64 时,即使转译标志缺失,也不能走 Intel 流程 ——
* 那等于在 Apple 芯片上装 Intel 运行环境。
* 3. 只有硬件为 x64 或无法确认、且未经转译的 x64 进程,才允许走 Intel 流程。
* 无法确认时保留兼容路径,避免无故阻断真正的 Intel Mac。
*/
export function resolveMacKeyFlow(input: MacArchInput): MacKeyFlow {
if (input.platform !== 'darwin') return 'unsupported'
if (input.runtimeArch === 'arm64') return 'apple-silicon'
if (input.runtimeArch !== 'x64') return 'unsupported'
if (input.underARM64Translation) return 'arch-mismatch'
if (input.hardwareArch === 'arm64') return 'arch-mismatch'
return 'intel'
}
/**
* Intel 运行环境探测要起一个 x86 子进程,只在真正的 Intel Mac 上才有意义。
* 其它流程(尤其 `arch-mismatch`)一律跳过,避免刷新连接页就拉起错误的 helper。
*/
export function shouldProbeIntelEnvironment(flow: MacKeyFlow): boolean {
return flow === 'intel'
}
export function buildMacArchSnapshot(input: MacArchInput): MacArchSnapshot {
const anomalies: string[] = []
if (input.hardwareArch === 'unknown') anomalies.push('hardware_arch_unknown')
if (input.runtimeArch === 'arm64' && input.underARM64Translation) {
anomalies.push('translation_flag_with_native_arm64')
}
if (input.runtimeArch === 'x64' && input.hardwareArch === 'arm64' && !input.underARM64Translation) {
// 硬件是 ARM、进程是 x64、却无转译标志:信号矛盾。流程仍按 arch-mismatch,
// 这个名字只用于诊断,不参与判定。
anomalies.push('x64_runtime_on_arm_without_translation_flag')
}
if (input.runtimeArch === 'x64' && input.underARM64Translation && input.hardwareArch !== 'arm64') {
anomalies.push('translation_flag_without_arm_hardware')
}
return { ...input, macKeyFlow: resolveMacKeyFlow(input), anomalies }
}