From a0b163823d3d94ccc3c1b58f43e415875c77c902 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=94=B5=E6=91=87=E5=B0=8F=E5=AD=90?= Date: Thu, 9 Jul 2026 10:37:11 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/key-service-mac.ts | 38 +++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/src/main/key-service-mac.ts b/src/main/key-service-mac.ts index 3feacc2..ab6ba3c 100644 --- a/src/main/key-service-mac.ts +++ b/src/main/key-service-mac.ts @@ -16,17 +16,35 @@ export interface DatabaseKeyResult { export class KeyServiceMac { private getHelperPath(): string { - const candidates = app.isPackaged - ? [ - path.join(process.resourcesPath, 'resources', 'xkey_helper'), - path.join(process.resourcesPath, 'xkey_helper') - ] - : [ - path.join(process.cwd(), 'resources', 'xkey_helper'), - path.join(app.getAppPath(), 'resources', 'xkey_helper') - ] + // 多 candidate fallback:覆盖 extraResources、asarUnpack、dev 三种场景 + // (extraResources → Contents/Resources/resources/;asarUnpack 同路径;dev → cwd 或 app.getAppPath) + const candidates = [ + // 1) extraResources 标准位置(electron-builder.yml 配的就是这个) + path.join(process.resourcesPath, 'resources', 'xkey_helper'), + // 2) process.resourcesPath 直接(防止 extraResources 没复制成功) + path.join(process.resourcesPath, 'xkey_helper'), + // 3) asarUnpack 路径(如果在 asar 内的 resources/ 被解包到 app.asar.unpacked) + path.join(app.getAppPath(), 'app.asar.unpacked', 'resources', 'xkey_helper'), + // 4) dev 模式 + 打包后某些版本 app.getAppPath() 也指向 .app 根目录 + path.join(app.getAppPath(), 'resources', 'xkey_helper'), + // 5) dev 模式:cwd + path.join(process.cwd(), 'resources', 'xkey_helper') + ].filter((p, idx, arr) => arr.indexOf(p) === idx) // 去重 + + // 诊断:即使命中也打 log,方便排查"装了但找不到"的问题(translocation / quarantine) + const statusList = candidates.map((candidate) => ({ + path: candidate, + exists: fs.existsSync(candidate) + })) + console.log('[KeyServiceMac] xkey_helper candidates:', JSON.stringify(statusList)) const helperPath = candidates.find((candidate) => fs.existsSync(candidate)) - if (!helperPath) throw new Error('找不到 xkey_helper') + if (!helperPath) { + throw new Error( + `找不到 xkey_helper(尝试 ${candidates.length} 个路径;` + + ` app.isPackaged=${app.isPackaged} resourcesPath=${process.resourcesPath} ` + + ` appPath=${app.getAppPath()} cwd=${process.cwd()})` + ) + } return helperPath }