NSH 在构建电子应用程序时给我错误

问题描述 投票:0回答:1

我正在尝试使用 myproject.exe 包含字体安装,一切正常,直到我包含 nsh 脚本,可能是什么问题?

!macro customInstall
    # Set the font directory path
    SetOutPath "$FONTS"

    # Copy the font file to the Fonts directory
    File "${__FILEDIR__}\fonts\NotoSansGeorgian.ttf"

    # Register the font
    WriteRegStr HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts" "Noto Sans Georgian (TrueType)" "NotoSansGeorgian.ttf"
    WriteRegStr HKCU "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts" "Noto Sans Georgian (TrueType)" "NotoSansGeorgian.ttf"

    # Send a message to all windows to notify them about the change
    System::Call 'user32::SendMessageA(i 0xffff, i ${WM_FONTCHANGE}, i 0, i 0)'
!macroend

!macro customUnInstall
    # Unregister the font
    DeleteRegValue HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts" "Noto Sans Georgian (TrueType)"
    DeleteRegValue HKCU "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts" "Noto Sans Georgian (TrueType)"

    # Remove the font file from the Fonts directory
    Delete "$FONTS\NotoSansGeorgian.ttf"

    # Send a message to all windows to notify them about the change
    System::Call 'user32::SendMessageA(i 0xffff, i ${WM_FONTCHANGE}, i 0, i 0)'
!macroend

我尝试逐行测试它,我 100% 确定这个脚本有错误

fonts electron nsis
1个回答
0
投票

我对 Electron 一无所知,但我确实知道您应该使用 NSIS wiki 中的字体头文件之一,而不是编写自己的代码。您的代码永远不会调用

AddFontResource
,因此它不会立即显示。如果您正确执行了其他所有操作,它将在重新启动后显示。

您可以调整安装字体中的代码示例来满足您的需求:

!include FontInstall.nsh

!macro customInstall
!insertmacro FontInstallTTF "${__FILEDIR__}\fonts\NotoSansGeorgian.ttf" "NotoSansGeorgian.ttf" "Noto Sans Georgian"
SendMessage ${HWND_BROADCAST} ${WM_FONTCHANGE} 0 0 /TIMEOUT=5000
!macroend

!macro customUnInstall
!insertmacro FontUninstallTTF "NotoSansGeorgian.ttf" "Noto Sans Georgian"
SendMessage ${HWND_BROADCAST} ${WM_FONTCHANGE} 0 0 /TIMEOUT=5000
!macroend

(这假设“Noto Sans Georgian”是正确的注册表名称。如果您不知道,请使用FontInfo插件

© www.soinside.com 2019 - 2024. All rights reserved.