3
votes

I have created an Electron app which is packaged into an NSIS installer with electron-builder.

Now I would like to add a custom text field to the installer, where the user can input a value (the value should be saved to disk/registry, it needs to be available in the app later).

I saw there is a customWelcomePage macro defined in the installer, which could probably be (mis)used for this purpose? But how would I create a macro which creates a complete page? NSIS is completely new to me, and the examples on the NSIS page seem to be for standalone installers, not for hooking into an existing installer. Or is there another, better approach?

1
You can create custom pages with input controls on it in NSIS but I don't know anything about electron-builder so I can't help you with that part.Anders

1 Answers

0
votes

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.