Files
MorphDoc/apps/desktop/electron-builder.config.cjs
T
SkyJourneyandClaude Sonnet 5 1fc30f8cf5 fix: 补齐 macOS 桌面应用的 Markdown 文件关联
问题修复:electron-builder 的 mac 配置块此前没有声明 fileAssociations,
打包出的 .app 缺少 Info.plist 的 CFBundleDocumentTypes,导致 Finder"打开
方式"里找不到 MorphDoc,也无法通过双击 .md/.markdown 文件启动。现在新增
对应声明(.md、.markdown,角色 Editor),与 Windows 侧 ProgID 注册对齐;
主进程既有的 open-file 事件处理无需改动。

验证结果:重新打包 arm64 版本后,用 NSWorkspace 查询 .md 候选打开应用,
MorphDoc.app 已正确出现在列表中。

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01K5N6pcbjV4jVfXrcH3NcLP
2026-08-27 19:52:42 +08:00

160 lines
4.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
const path = require("node:path");
const { version } = require("./package.json");
const brand = require("../../product.json");
const pandocRuntime = require(
"../../packages/docx-engine/src/pandoc-runtime.json"
);
const windowsIcon = path.resolve(
__dirname,
"../../logos/desktop/windows/app.ico"
);
const macIcon = path.resolve(
__dirname,
"../../logos/desktop/macos/app.icns"
);
const nsisInclude = process.env.MD_TO_PDF_NSIS_INCLUDE?.trim() ||
"build/installer.nsh";
// macOS 每次只构建一个架构的 dmgarm64 或 x64),不产出 universal 包——
// 项目内置完整 Chromium/Electron 运行时和固定版本 Pandoc,合并双架构会让单个
// 安装包体积翻倍。目标架构通过环境变量显式声明,用于挑选对应的内置 Pandoc
// 资源目录;不依赖 electron-builder 的 `${arch}` 路径宏(该宏在 extraResources
// 场景下有已知的可靠性问题)。
const macTargetArch = process.env.MD_TO_PDF_MAC_TARGET_ARCH?.trim() || "";
if (macTargetArch && macTargetArch !== "arm64" && macTargetArch !== "x64") {
throw new Error(
`未知 macOS 目标架构:${macTargetArch}(仅支持 arm64 或 x64`
);
}
module.exports = {
appId: brand.appId,
productName: brand.englishName,
copyright: "Copyright © YIXIONG Tech.ltd",
asar: true,
electronLanguages: ["zh-CN", "en-US"],
directories: {
output: `out/v${version}`
},
files: [
"dist/**/*",
"package.json"
],
extraResources: [
{
from: "../web/dist",
to: "dist",
filter: ["**/*"]
},
{
from: "../../themes",
to: "themes",
filter: ["**/*"]
},
{
from: "../../samples",
to: "samples",
filter: ["**/*"]
},
{
from: "../../output/font-packs/root",
to: "font-packs",
filter: ["**/*"]
},
{
from: windowsIcon,
to: "app.ico"
},
{
from: macIcon,
to: "app.icns"
}
],
win: {
target: [
{
target: "nsis",
arch: ["x64"]
},
{
target: "zip",
arch: ["x64"]
}
],
icon: windowsIcon,
executableName: brand.executableName,
artifactName: `${brand.artifactPrefix}-${version}-x86_64.\${ext}`,
extraResources: [
{
from: `.runtime/pandoc/${pandocRuntime.version}/windows-x86_64`,
to: `pandoc/${pandocRuntime.version}/windows-x86_64`,
filter: [
"pandoc.exe",
"COPYING.rtf",
"COPYRIGHT.txt",
"runtime-manifest.json"
]
}
]
},
nsis: {
oneClick: false,
allowToChangeInstallationDirectory: true,
perMachine: false,
allowElevation: true,
createDesktopShortcut: false,
createStartMenuShortcut: false,
shortcutName: brand.displayName,
uninstallDisplayName: brand.displayName,
installerIcon: windowsIcon,
uninstallerIcon: windowsIcon,
installerLanguages: ["zh_CN"],
include: nsisInclude,
artifactName: `${brand.artifactPrefix}-${version}-x86_64-Setup.\${ext}`
},
mac: {
category: "public.app-category.productivity",
icon: macIcon,
executableName: brand.executableName,
// 项目当前没有 Apple Developer 证书,显式声明不签名,与 Windows 侧
// 一贯记录在案的"未签名"状态保持一致;后续如需公证再补齐。
identity: null,
target: [
{
target: "dmg"
}
],
// 声明 .md/.markdown 文件关联,写入 Info.plist 的 CFBundleDocumentTypes
// 否则 Finder 的"打开方式"里不会出现本应用;与 Windows 侧的 ProgID 注册
// 是对等能力,主进程已有的 open-file 事件处理无需改动。
fileAssociations: [
{
ext: ["md", "markdown"],
name: "Markdown",
description: "Markdown 文档",
role: "Editor",
icon: macIcon
}
],
extraResources: macTargetArch
? [
{
from: `.runtime/pandoc/${pandocRuntime.version}/darwin-${macTargetArch}`,
to: `pandoc/${pandocRuntime.version}/darwin-${macTargetArch}`,
filter: [
"pandoc",
"COPYING.md",
"COPYRIGHT",
"runtime-manifest.json"
]
}
]
: []
},
dmg: {
title: brand.displayName,
artifactName: `${brand.artifactPrefix}-${version}-\${arch}.\${ext}`
}
};