将自定义页面/字段添加到使用electronic-builder创建的NSIS设置中

时间:2018-07-05 07:34:15

标签: electron nsis electron-builder

我创建了一个Electron应用程序,该应用程序与电子生成器一起打包到NSIS安装程序中。

现在,我想在安装程序中添加一个自定义文本字段,用户可以在其中输入一个值(该值应保存到磁盘/注册表中,以后需要在应用程序中可用)。

我看到安装程序中定义了一个customWelcomePage宏,它可能被(错误地)用于此目的?但是如何创建一个可以创建完整页面的宏? NSIS对我来说是全新的,并且NSIS页面上的示例似乎是针对独立安装程序的,而不是挂钩到现有安装程序的。还是有另一种更好的方法?

1 个答案:

答案 0 :(得分:0)

I've been working on the same thing recently. Here's what I did:

First, use the include option to point to a .nsh file (I'm doing this in package.json):

{
  "build": {
    "appId": "...",
    "nsis": {
      "include": "build/installer.nsh"
    }
  }
}

Then you can put your custom NSIS code inside that .nsh file:

!include nsDialogs.nsh

XPStyle on

Var Dialog

Page custom myCustomPage

Function myCustomPage

    nsDialogs::Create 1018
    Pop $Dialog

    ${If} $Dialog == error
        Abort
    ${EndIf}

    ...

    nsDialogs::Show

FunctionEnd

Section
SectionEnd

I adapted code from Mevia's question when I was creating my custom page. This will make a page that appears before the actual installation (Mevia's problem), so you should be careful where you save the input data.

I believe that using include instead of a script is what allows you to write code for a single page, rather than having to write the entire installer script yourself.