From 30c47af1f965deaae98f3a901ebe2a30201f3905 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=94=B5=E6=91=87=E5=B0=8F=E5=AD=90?= Date: Fri, 3 Jul 2026 10:05:50 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20macOS=20=E6=89=93?= =?UTF-8?q?=E5=8C=85=E7=89=88=20WCDB=20=E5=88=9D=E5=A7=8B=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- electron-builder.yml | 17 ++++++++----- package.json | 23 ++++++------------ scripts/after-pack.cjs | 54 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+), 22 deletions(-) create mode 100644 scripts/after-pack.cjs diff --git a/electron-builder.yml b/electron-builder.yml index a48e31e..390219f 100644 --- a/electron-builder.yml +++ b/electron-builder.yml @@ -1,5 +1,6 @@ -appId: com.electron.app -productName: wechatexplorer +appId: com.wechatexplorer.app +productName: WechatExplorer +afterPack: scripts/after-pack.cjs directories: buildResources: build files: @@ -29,10 +30,14 @@ nsis: mac: entitlementsInherit: build/entitlements.mac.plist extendInfo: - - NSCameraUsageDescription: Application requests access to the device's camera. - - NSMicrophoneUsageDescription: Application requests access to the device's microphone. - - NSDocumentsFolderUsageDescription: Application requests access to the user's Documents folder. - - NSDownloadsFolderUsageDescription: Application requests access to the user's Downloads folder. + # The bundled WCDB bridge accepts Electron as its internal host name. The + # public app name and bundle identifier remain WechatExplorer-specific. + CFBundleName: Electron + CFBundleDisplayName: WechatExplorer + NSCameraUsageDescription: Application requests access to the device's camera. + NSMicrophoneUsageDescription: Application requests access to the device's microphone. + NSDocumentsFolderUsageDescription: Application requests access to the user's Documents folder. + NSDownloadsFolderUsageDescription: Application requests access to the user's Downloads folder. notarize: false dmg: artifactName: ${name}-${version}.${ext} diff --git a/package.json b/package.json index 3490716..700d31e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "wechatexplorer", - "version": "2.0.0", + "version": "2.0.1", "description": "mac 版本获取微信聊天记录, AI群聊总结助手", "keywords": [ "wechat", @@ -21,12 +21,12 @@ "dev": "electron-vite dev", "build": "npm run typecheck && electron-vite build", "postinstall": "electron-builder install-app-deps", - "build:unpack": "npm run build && electron-builder --dir", - "build:win": "npm run build && electron-builder --win", - "build:mac:x64": "electron-vite build && electron-builder --mac --x64", - "build:mac:arm64": "electron-vite build && electron-builder --mac --arm64", - "release:mac": "electron-vite build && electron-builder --mac --x64 --arm64 --publish always", - "build:linux": "electron-vite build && electron-builder --linux" + "build:unpack": "npm run build && electron-builder --config electron-builder.yml --dir", + "build:win": "npm run build && electron-builder --config electron-builder.yml --win", + "build:mac:x64": "electron-vite build && electron-builder --config electron-builder.yml --mac --x64", + "build:mac:arm64": "electron-vite build && electron-builder --config electron-builder.yml --mac --arm64", + "release:mac": "electron-vite build && electron-builder --config electron-builder.yml --mac --x64 --arm64 --publish always", + "build:linux": "electron-vite build && electron-builder --config electron-builder.yml --linux" }, "dependencies": { "@electron-toolkit/preload": "^3.0.2", @@ -66,14 +66,5 @@ "electron", "esbuild" ] - }, - "build": { - "artifactName": "${productName}-${version}-${os}-${arch}.${ext}", - "mac": { - "target": [ - "dmg", - "zip" - ] - } } } diff --git a/scripts/after-pack.cjs b/scripts/after-pack.cjs new file mode 100644 index 0000000..13679d4 --- /dev/null +++ b/scripts/after-pack.cjs @@ -0,0 +1,54 @@ +const { existsSync, renameSync } = require('node:fs') +const { execFileSync } = require('node:child_process') +const path = require('node:path') + +const COMPATIBILITY_NAME = 'Electron' +const HELPER_SUFFIXES = ['', ' (Plugin)', ' (Renderer)', ' (GPU)'] + +function setPlistValue(plistPath, key, value) { + execFileSync('/usr/libexec/PlistBuddy', ['-c', `Set :${key} ${value}`, plistPath]) +} + +exports.default = async function afterPack(context) { + if (context.electronPlatformName !== 'darwin') return + + const productName = context.packager.appInfo.productFilename + const appPath = path.join(context.appOutDir, `${productName}.app`) + const contentsPath = path.join(appPath, 'Contents') + const sourceExecutable = path.join(contentsPath, 'MacOS', productName) + const targetExecutable = path.join(contentsPath, 'MacOS', COMPATIBILITY_NAME) + + if (existsSync(sourceExecutable)) renameSync(sourceExecutable, targetExecutable) + if (!existsSync(targetExecutable)) { + throw new Error(`Missing Electron main executable: ${sourceExecutable}`) + } + + const appPlistPath = path.join(contentsPath, 'Info.plist') + setPlistValue(appPlistPath, 'CFBundleExecutable', COMPATIBILITY_NAME) + setPlistValue(appPlistPath, 'CFBundleName', COMPATIBILITY_NAME) + + const frameworksPath = path.join(contentsPath, 'Frameworks') + + for (const suffix of HELPER_SUFFIXES) { + const sourceName = `${productName} Helper${suffix}` + const targetName = `${COMPATIBILITY_NAME} Helper${suffix}` + const sourceBundle = path.join(frameworksPath, `${sourceName}.app`) + const targetBundle = path.join(frameworksPath, `${targetName}.app`) + + if (existsSync(sourceBundle)) renameSync(sourceBundle, targetBundle) + if (!existsSync(targetBundle)) { + throw new Error(`Missing Electron helper bundle: ${sourceBundle}`) + } + + const sourceExecutable = path.join(targetBundle, 'Contents', 'MacOS', sourceName) + const targetExecutable = path.join(targetBundle, 'Contents', 'MacOS', targetName) + if (existsSync(sourceExecutable)) renameSync(sourceExecutable, targetExecutable) + if (!existsSync(targetExecutable)) { + throw new Error(`Missing Electron helper executable: ${sourceExecutable}`) + } + + const plistPath = path.join(targetBundle, 'Contents', 'Info.plist') + setPlistValue(plistPath, 'CFBundleExecutable', targetName) + setPlistValue(plistPath, 'CFBundleName', targetName) + } +}