feat: 实现 Windows 可选字体包安装链
This commit is contained in:
@@ -1,3 +1,67 @@
|
||||
!ifdef FONT_PACK_COMPANION_FILE
|
||||
!ifndef BUILD_UNINSTALLER
|
||||
!include "FileFunc.nsh"
|
||||
!include "nsDialogs.nsh"
|
||||
|
||||
Var fontPackCompanionAvailable
|
||||
Var fontPackCompanionCheckbox
|
||||
Var fontPackCompanionExitCode
|
||||
Var fontPackCompanionHash
|
||||
Var fontPackCompanionPath
|
||||
Var fontPackCompanionSelected
|
||||
|
||||
!macro customInit
|
||||
StrCpy $fontPackCompanionAvailable "0"
|
||||
StrCpy $fontPackCompanionSelected "0"
|
||||
StrCpy $fontPackCompanionPath "$EXEDIR\${FONT_PACK_COMPANION_FILE}"
|
||||
IfFileExists "$fontPackCompanionPath" 0 font_pack_init_done
|
||||
${StdUtils.HashFile} $fontPackCompanionHash "SHA2-256" "$fontPackCompanionPath"
|
||||
StrCmp $fontPackCompanionHash "${FONT_PACK_COMPANION_SHA256}" 0 font_pack_init_done
|
||||
StrCpy $fontPackCompanionAvailable "1"
|
||||
IfSilent font_pack_silent font_pack_interactive
|
||||
font_pack_interactive:
|
||||
StrCpy $fontPackCompanionSelected "1"
|
||||
Goto font_pack_init_done
|
||||
font_pack_silent:
|
||||
${GetParameters} $R0
|
||||
${GetOptions} $R0 "/WITHFONTPACK=" $R1
|
||||
StrCmp $R1 "1" 0 font_pack_init_done
|
||||
StrCpy $fontPackCompanionSelected "1"
|
||||
font_pack_init_done:
|
||||
!macroend
|
||||
|
||||
Function FontPackCompanionPage
|
||||
StrCmp $fontPackCompanionAvailable "1" 0 font_pack_page_skip
|
||||
nsDialogs::Create 1018
|
||||
Pop $R0
|
||||
StrCmp $R0 "error" 0 +2
|
||||
Abort
|
||||
${NSD_CreateLabel} 0 0 100% 28u "检测到经过完整性校验的可选字体包。安装后,政企公文主题可使用与 PDF 相同的原生中文字体资产。"
|
||||
Pop $R0
|
||||
${NSD_CreateCheckbox} 0 38u 100% 14u "安装 ${FONT_PACK_COMPANION_NAME}"
|
||||
Pop $fontPackCompanionCheckbox
|
||||
${NSD_Check} $fontPackCompanionCheckbox
|
||||
nsDialogs::Show
|
||||
Return
|
||||
font_pack_page_skip:
|
||||
Abort
|
||||
FunctionEnd
|
||||
|
||||
Function FontPackCompanionPageLeave
|
||||
${NSD_GetState} $fontPackCompanionCheckbox $R0
|
||||
StrCmp $R0 ${BST_CHECKED} 0 font_pack_page_unchecked
|
||||
StrCpy $fontPackCompanionSelected "1"
|
||||
Return
|
||||
font_pack_page_unchecked:
|
||||
StrCpy $fontPackCompanionSelected "0"
|
||||
FunctionEnd
|
||||
|
||||
!macro customPageAfterChangeDir
|
||||
Page custom FontPackCompanionPage FontPackCompanionPageLeave
|
||||
!macroend
|
||||
!endif
|
||||
!endif
|
||||
|
||||
!macro customInstall
|
||||
WriteRegStr SHCTX \
|
||||
"Software\Classes\MarkdownPdfExporter.Markdown" \
|
||||
@@ -43,6 +107,24 @@
|
||||
"" \
|
||||
"$INSTDIR\md-to-pdf.exe"
|
||||
StrCpy $launchLink "$INSTDIR\md-to-pdf.exe"
|
||||
!ifdef FONT_PACK_COMPANION_FILE
|
||||
StrCmp $fontPackCompanionAvailable "1" 0 font_pack_install_done
|
||||
StrCmp $fontPackCompanionSelected "1" 0 font_pack_install_done
|
||||
${StdUtils.HashFile} $fontPackCompanionHash "SHA2-256" "$fontPackCompanionPath"
|
||||
StrCmp $fontPackCompanionHash "${FONT_PACK_COMPANION_SHA256}" 0 font_pack_integrity_failed
|
||||
DetailPrint "正在安装可选字体包:${FONT_PACK_COMPANION_NAME}"
|
||||
ExecWait '"$fontPackCompanionPath" /S' $fontPackCompanionExitCode
|
||||
StrCmp $fontPackCompanionExitCode "0" font_pack_install_done
|
||||
DetailPrint "可选字体包安装失败,退出码:$fontPackCompanionExitCode"
|
||||
IfSilent font_pack_install_done 0
|
||||
MessageBox MB_ICONEXCLAMATION|MB_OK "主程序已安装,但可选字体包安装失败(退出码 $fontPackCompanionExitCode)。您可以稍后单独运行字体包安装器。"
|
||||
Goto font_pack_install_done
|
||||
font_pack_integrity_failed:
|
||||
DetailPrint "可选字体包完整性复核失败,已跳过安装。"
|
||||
IfSilent font_pack_install_done 0
|
||||
MessageBox MB_ICONEXCLAMATION|MB_OK "可选字体包完整性复核失败,主程序已安装,但字体包已跳过。"
|
||||
font_pack_install_done:
|
||||
!endif
|
||||
System::Call 'shell32::SHChangeNotify(i 0x08000000, i 0, i 0, i 0)'
|
||||
!macroend
|
||||
|
||||
|
||||
@@ -5,6 +5,8 @@ const windowsIcon = path.resolve(
|
||||
__dirname,
|
||||
"../../logos/desktop/windows/app.ico"
|
||||
);
|
||||
const nsisInclude = process.env.MD_TO_PDF_NSIS_INCLUDE?.trim() ||
|
||||
"build/installer.nsh";
|
||||
|
||||
module.exports = {
|
||||
appId: "com.md-to-pdf.desktop",
|
||||
@@ -71,7 +73,7 @@ module.exports = {
|
||||
installerIcon: windowsIcon,
|
||||
uninstallerIcon: windowsIcon,
|
||||
installerLanguages: ["zh_CN"],
|
||||
include: "build/installer.nsh",
|
||||
include: nsisInclude,
|
||||
artifactName: `md-to-pdf-${version}-x86_64-Setup.\${ext}`
|
||||
}
|
||||
};
|
||||
|
||||
@@ -58,6 +58,28 @@ describe("桌面发行构建链", () => {
|
||||
expect(builderConfig).toContain('to: "samples"');
|
||||
});
|
||||
|
||||
it("仅在组合构建时接入经过哈希校验的同目录字体包", () => {
|
||||
const builderConfig = readFileSync(
|
||||
`${desktopRoot}/electron-builder.config.cjs`,
|
||||
"utf8"
|
||||
);
|
||||
const installerInclude = readFileSync(
|
||||
`${desktopRoot}/build/installer.nsh`,
|
||||
"utf8"
|
||||
);
|
||||
const companionBuild = readFileSync(
|
||||
`${projectRoot}/scripts/build-desktop-with-font-pack.mjs`,
|
||||
"utf8"
|
||||
);
|
||||
|
||||
expect(builderConfig).toContain("MD_TO_PDF_NSIS_INCLUDE");
|
||||
expect(installerInclude).toContain("FONT_PACK_COMPANION_SHA256");
|
||||
expect(installerInclude).toContain("StdUtils.HashFile");
|
||||
expect(installerInclude).toContain("/WITHFONTPACK=");
|
||||
expect(companionBuild).toContain("createDesktopCompanionInclude");
|
||||
expect(companionBuild).toContain("MD_TO_PDF_NSIS_INCLUDE");
|
||||
});
|
||||
|
||||
it("将 DOCX Lua Filter 复制到桌面主进程资源目录", () => {
|
||||
const buildScript = readFileSync(
|
||||
`${desktopRoot}/scripts/build-main.mjs`,
|
||||
|
||||
Reference in New Issue
Block a user