3

I'm working with an electron application that is built via electron-builder. When I generate the installer and begin installing with it, I see that the cancel button is disabled.

I've looked around at some electron builder documentation and done a few google searches but I seem to be coming up blank here.

edit: Discovered that I can use build/installer.nsh to actually modify UI elements, now I'm just wondering, how do I gain access to the button to enable / disable it, the examples I've seen use an .ini file to store options or something similar, but I'm getting recommendations to use nsDialogs.

Is nsDialogs something that's already readily accessible to me or do I need to import something into my installer.nsh file to use nsDialogs?

And by that token, how would I access the cancel button in nsDialogs?

Is there a configurable value that enables me to... enable that cancel button so users can choose to cancel during installation?

Thanks!

Morklympious
  • 1,065
  • 8
  • 12
  • Do you want to change the page that does the installing? – Anders Nov 29 '21 at 20:56
  • Not really, no. I just have a default page that does the confirming that uses want to install, and then another page that shows the gauge installing the application. The footer then should have an enabled "cancel" button, instead of its current situarion where the cancel button is disabled the whole time. – Morklympious Nov 29 '21 at 21:05
  • Which of those two pages do you want to change? – Anders Nov 29 '21 at 22:00
  • Sorry, let me explain this just a bit better: When I open my built installer, I get a view asking me where the destination folder will be for the install, and at the footer I have [INSTALL] and [CANCEL] buttons, both are enabled and pressable. I press [INSTALL]. The footer changes into 3 buttons: [BACK], [NEXT], and [CANCEL] while a gauge indicating the install progress is shown in the installer window body. I want to change this second view such that [CANCEL] is able to be clicked and will cancel the installation while it's in progress. I currently can't do that. Does that help? – Morklympious Nov 29 '21 at 23:20

1 Answers1

2

NSIS installers do not support canceling the installation when you enter the InstFiles page (or any page after it). This is by design because of how the scripting language works.

If you don't mind hacks you can call the uninstaller when the user clicks cancel during the install phase:

Var Cancel
!include LogicLib.nsh
!include WinMessages.nsh

Function .onUserAbort
    StrCmp $Cancel "" +3
        IntOp $Cancel $Cancel | 1
        Abort
FunctionEnd

!macro FakeWork c
!if "${c}" < 10
Sleep 333
DetailPrint .
!define /redef /math c "${c}" + 1
!insertmacro ${__MACRO__} "${c}"
!endif
!macroend

Section Uninstall
!insertmacro FakeWork 0
Delete "$InstDir\Uninst.exe"
RMDir "$InstDir"
SectionEnd

Function CheckCancel
${If} $Cancel = 1
    IntOp $Cancel $Cancel + 1
    GetDlgItem $0 $hwndParent 2
    EnableWindow $0 0
    DetailPrint "Canceling..."
    SetDetailsPrint none
    ExecWait '"$InstDir\Uninst.exe" /S _?=$InstDir'
    Delete "$InstDir\Uninst.exe"
    RMDir "$InstDir"
    SetDetailsPrint both
    Quit
${EndIf}
FunctionEnd


Section
SetOutPath $InstDir
WriteUninstaller "$InstDir\Uninst.exe"
StrCpy $Cancel 0 ; Allow special cancel mode
GetDlgItem $0 $hwndParent 2
EnableWindow $0 1 ; Enable cancel button

!insertmacro FakeWork 0 ; Replace these with File or other instructions
Call CheckCancel
!insertmacro FakeWork 0
Call CheckCancel
!insertmacro FakeWork 0
Call CheckCancel

StrCpy $Cancel "" ; We are done, ignore special cancel mode
SectionEnd

(I have no idea how to integrate this with electron-builder, sorry)

If you want a proper roll-back installer, try Inno Setup or WiX (MSI).

Anders
  • 97,548
  • 12
  • 110
  • 164
  • Frankly this is a great answer and it pretty much answers my question in that it looks like I can't do what I want necessarily by DESIGN. Thank you so much for this back and forth! TAKE MY REP. – Morklympious Nov 30 '21 at 01:50