2
votes

I am trying to generate electron app.exe with the use of **electron-builder** and **nsis**, which should ask user input at time of installation.

Following is my **package.json**.
...
"build": {
    "appId": "com.electron.test",
    "productName": "test",
    "win": {
      "target": [
        "nsis"
      ],
      "icon": "assets/icon.ico"
    },
    "nsis": {
      "warningsAsErrors": false,
      "installerIcon": "assets/icon.ico",
      "runAfterFinish": false,
      "oneClick": false,
      "perMachine": true,
      "allowToChangeInstallationDirectory": true,
      "installerHeader": "assets/installerHeader.bmp",
      "include": "build/installer.nsh"
    },
    "mac": {
      "category": "your.app.category.type"
    }
}
...

I want to display custom page **Between** Select Location Page and Installation Progress Page.
Following is my **installer.nsh** which is create one custom page i.e. ask for user to input username and password.


!include "EnvVarUpdate.nsh"
!include "MUI2.nsh"
!include "nsDialogs.nsh"
!include "LogicLib.nsh"

Var Dialog
Var UserLabel
Var UserText
Var UserState
Var PassLabel
Var PassText
Var PassState

;--------------------------------
; Show install details
    ShowInstDetails show

;--------------------------------
;Interface Settings

    !define MUI_ABORTWARNING

Page custom nsDialogsPage nsDialogsPageLeave

Function nsDialogsPage

    nsDialogs::Create 1018
    Pop $Dialog

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

    ${NSD_CreateLabel} 0 0 100% 12u "Username:"
    Pop $UserLabel

    ${NSD_CreateText} 0 13u 100% 12u $UserState
    Pop $UserText

    ${NSD_CreateLabel} 0 39u 100% 12u "Password:"
    Pop $PassLabel

    ${NSD_CreatePassword} 0 52u 100% 12u $PassState
    Pop $PassText

    nsDialogs::Show

FunctionEnd

Function nsDialogsPageLeave

    ${NSD_GetText} $UserText $UserState
    ${NSD_GetText} $PassText $PassState

    ${If} $UserState == ""
        MessageBox MB_OK "Username is missing."
        Abort
    ${EndIf}

    ${If} $PassState == ""
        MessageBox MB_OK "Password is missing."
        Abort
    ${EndIf}

    StrCpy $1 $UserState
    StrCpy $2 $PassState

    FileOpen $9 $INSTDIR\credentials.txt w
    FileWrite $9 "$1:$2"
    FileClose $9
    SetFileAttributes $INSTDIR\credentials.txt HIDDEN|READONLY

FunctionEnd

Section
SectionEnd


!macro customHeader
    
!macroend

!macro preInit
    
!macroend

!macro customInstall
    ${EnvVarUpdate} $0 "PATH" "A" "HKLM" "$INSTDIR"
!macroend

!macro customUnInstall
    ${un.EnvVarUpdate} $0 "PATH" "R" "HKLM" "$INSTDIR"
!macroend



Please provide any solution.


**Thanks & Regards**
Rachit V. Sakhidas

1
What is the question? Compiler errors?Anders

1 Answers

1
votes

It looks like everything is correct. The NSIS script posted is for creating your custom page. What is your question? Do you have any errors or you just do not know what to do?

Q: Your page is not shown in installer?

If no: Did you include you custom page in the electron-nsis script so the page is actually shown?

Q: Do you have troubles with creating custom pages?

If yes: try this tool: https://nsis.sourceforge.io/Install_Designer (I am its developer so feel free to ask here any questions).

It is really tough to says what is wrong with this few information, please post full scripts and logs.