// afterPack 钩子:未购买 Apple 证书时,electron-builder(24) 会「跳过签名」, // 导致 .app 的 bundle 封印(seal)残缺(codesign --verify 报 "code has no resources // but signature indicates they must be present")。这里在打 DMG 前,用 ad-hoc 身份 // 对整个 app(含内置 sing-box)做一次完整深度重新签名,得到有效封印—— // 用户去掉隔离标记后即可稳定运行。 const { execFileSync } = require('child_process'); const path = require('path'); exports.default = async function afterPack(context) { if (context.electronPlatformName !== 'darwin') return; const appName = `${context.packager.appInfo.productFilename}.app`; const appPath = path.join(context.appOutDir, appName); console.log(` • ad-hoc 深度重签名 app=${appPath}`); // --force 覆盖已有签名,--deep 递归签所有嵌套二进制(sing-box 等),-s - 表示 ad-hoc execFileSync('codesign', ['--force', '--deep', '--sign', '-', appPath], { stdio: 'inherit', }); // 校验封印是否完整(失败则中断构建,避免发出坏包) execFileSync('codesign', ['--verify', '--deep', '--strict', '--verbose=2', appPath], { stdio: 'inherit', }); console.log(' • ad-hoc 签名校验通过 ✔'); };