问题
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:
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.
来源:https://stackoverflow.com/questions/51185663/add-custom-page-field-to-nsis-setup-created-with-electron-builder