Skip to content

Commit 00e8da8

Browse files
committed
fix(nsis): installerHeaderIcon
Close #525
1 parent 726e574 commit 00e8da8

File tree

9 files changed

+37
-42
lines changed

9 files changed

+37
-42
lines changed

docs/Options.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ See [NSIS target notes](https://github.com/electron-userland/electron-builder/wi
130130
| allowElevation | <a name="NsisOptions-allowElevation"></a>Allow requesting for elevation. If false, user will have to restart installer with elevated permissions. Defaults to `true`.
131131
| oneClick | <a name="NsisOptions-oneClick"></a>One-click installation. Defaults to `true`.
132132
| installerHeader | <a name="NsisOptions-installerHeader"></a>*boring installer only.* `MUI_HEADERIMAGE`, relative to the project directory. Defaults to `build/installerHeader.bmp`
133-
| headerIcon | <a name="NsisOptions-headerIcon"></a>*one-click installer only.* The path to header icon (above the progress bar), relative to the project directory. Defaults to `build/headerIcon.ico` or application icon.
133+
| installerHeaderIcon | <a name="NsisOptions-installerHeaderIcon"></a>*one-click installer only.* The path to header icon (above the progress bar), relative to the project directory. Defaults to `build/installerHeaderIcon.ico` or application icon.
134134

135135
<a name="LinuxBuildOptions"></a>
136136
### `.build.linux`

src/metadata.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,9 +375,9 @@ export interface NsisOptions {
375375
readonly installerHeader?: string | null
376376

377377
/*
378-
*one-click installer only.* The path to header icon (above the progress bar), relative to the project directory. Defaults to `build/headerIcon.ico` or application icon.
378+
*one-click installer only.* The path to header icon (above the progress bar), relative to the project directory. Defaults to `build/installerHeaderIcon.ico` or application icon.
379379
*/
380-
readonly headerIcon?: string | null
380+
readonly installerHeaderIcon?: string | null
381381
}
382382

383383
/*

src/targets/nsis.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export default class NsisTarget extends Target {
5959
APP_ID: appInfo.id,
6060
APP_GUID: guid,
6161
PRODUCT_NAME: appInfo.productName,
62-
INST_DIR_NAME: appInfo.productFilename,
62+
PRODUCT_FILENAME: appInfo.productFilename,
6363
APP_DESCRIPTION: appInfo.description,
6464
VERSION: version,
6565

@@ -82,9 +82,9 @@ export default class NsisTarget extends Target {
8282
defines.MUI_HEADERIMAGE_BITMAP = installerHeader
8383
}
8484

85-
const headerIcon = oneClick ? await this.getResource(this.options.headerIcon, "headerIcon.ico") : null
86-
if (headerIcon != null) {
87-
defines.HEADER_ICO = headerIcon
85+
const installerHeaderIcon = oneClick ? await this.getResource(this.options.installerHeaderIcon, "installerHeaderIcon.ico") : null
86+
if (installerHeaderIcon != null) {
87+
defines.HEADER_ICO = installerHeaderIcon
8888
}
8989

9090
if (this.options.perMachine === true) {

src/targets/squirrelWindows.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export default class SquirrelWindowsTarget extends Target {
2323
const appInfo = this.packager.appInfo
2424
const version = appInfo.version
2525
const archSuffix = getArchSuffix(arch)
26-
const setupFileName = `${appInfo.productFilename} Setup ${version}${archSuffix}.exe`
26+
const setupFileName = `${appInfo.productFilename} Setup ${version}${archSuffix}.exe`
2727

2828
const installerOutDir = path.join(appOutDir, "..", `win${getArchSuffix(arch)}`)
2929
await emptyDir(installerOutDir)

templates/nsis/NsisMultiUser.nsh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ Var RadioButtonLabel1
4444
!define FOLDERID_UserProgramFiles {5CD7AEE2-2219-4A67-B85D-6C9CE15660CB}
4545
!define KF_FLAG_CREATE 0x00008000
4646

47-
!ifdef MULTIUSER_INSTALLMODE_INSTALL_REGISTRY_KEY & MULTIUSER_INSTALLMODE_UNINSTALL_REGISTRY_KEY & MULTIUSER_INSTALLMODE_INSTDIR_REGISTRY_VALUENAME & UNINSTALL_FILENAME & VERSION & APP_EXECUTABLE_FILENAME & PRODUCT_NAME & COMPANY_NAME & INST_DIR_NAME
47+
!ifdef MULTIUSER_INSTALLMODE_INSTALL_REGISTRY_KEY & MULTIUSER_INSTALLMODE_UNINSTALL_REGISTRY_KEY & MULTIUSER_INSTALLMODE_INSTDIR_REGISTRY_VALUENAME & UNINSTALL_FILENAME & VERSION & APP_EXECUTABLE_FILENAME & PRODUCT_NAME & COMPANY_NAME & PRODUCT_FILENAME
4848
!else
49-
!error "Should define all variables: MULTIUSER_INSTALLMODE_INSTALL_REGISTRY_KEY & MULTIUSER_INSTALLMODE_UNINSTALL_REGISTRY_KEY & MULTIUSER_INSTALLMODE_INSTDIR_REGISTRY_VALUENAME & UNINSTALL_FILENAME & VERSION & APP_EXECUTABLE_FILENAME & PRODUCT_NAME & COMPANY_NAME & INST_DIR_NAME"
49+
!error "Should define all variables: MULTIUSER_INSTALLMODE_INSTALL_REGISTRY_KEY & MULTIUSER_INSTALLMODE_UNINSTALL_REGISTRY_KEY & MULTIUSER_INSTALLMODE_INSTDIR_REGISTRY_VALUENAME & UNINSTALL_FILENAME & VERSION & APP_EXECUTABLE_FILENAME & PRODUCT_NAME & COMPANY_NAME & PRODUCT_FILENAME"
5050
!endif
5151

5252
!define MULTIUSER_INSTALLMODE_INSTALL_REGISTRY_KEY2 "Software\${MULTIUSER_INSTALLMODE_INSTALL_REGISTRY_KEY}"
@@ -67,7 +67,7 @@ RequestExecutionLevel user ; will ask elevation only if necessary
6767

6868
!if "${UNINSTALLER_PREFIX}" != UN
6969
;Set default installation location for installer
70-
StrCpy $INSTDIR "$PROGRAMFILES\${INST_DIR_NAME}"
70+
StrCpy $INSTDIR "$PROGRAMFILES\${PRODUCT_FILENAME}"
7171
!endif
7272

7373
; Checks registry for previous installation path (both for upgrading, reinstall, or uninstall)
@@ -102,7 +102,7 @@ RequestExecutionLevel user ; will ask elevation only if necessary
102102
;Everyone is admin on Win9x, so falling back to $ProgramFiles is ok
103103
${IfThen} $LocalAppData == "" ${|} StrCpy $0 $ProgramFiles ${|}
104104
${EndIf}
105-
StrCpy $Instdir "$0\${INST_DIR_NAME}"
105+
StrCpy $Instdir "$0\${PRODUCT_FILENAME}"
106106
!endif
107107

108108
; Checks registry for previous installation path (both for upgrading, reinstall, or uninstall)

templates/nsis/boring-installer.nsh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# http://nsis.sourceforge.net/Run_an_application_shortcut_after_an_install
2-
#!define MUI_FINISHPAGE_RUN_TEXT "Start ${PRODUCT_NAME}"
32
!define MUI_FINISHPAGE_RUN
43
!define MUI_FINISHPAGE_RUN_FUNCTION "StartApp"
54

templates/nsis/common.nsh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ Unicode true
1212
!define MULTIUSER_INSTALLMODE_INSTALL_REGISTRY_KEY "${APP_GUID}"
1313
!define MULTIUSER_INSTALLMODE_UNINSTALL_REGISTRY_KEY "${APP_GUID}"
1414

15-
!define APP_EXECUTABLE_FILENAME "${PRODUCT_NAME}.exe"
16-
!define UNINSTALL_FILENAME "Uninstall ${PRODUCT_NAME}.exe"
15+
!define APP_EXECUTABLE_FILENAME "${PRODUCT_FILENAME}.exe"
16+
!define UNINSTALL_FILENAME "Uninstall ${PRODUCT_FILENAME}.exe"

templates/nsis/installer.nsi

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
!include "allowOnlyOneInstallerInstace.nsh"
66
!include "checkAppRunning.nsh"
77
!include x64.nsh
8+
!include WinVer.nsh
89

910
Function StartApp
10-
ExecShell "" "$SMPROGRAMS\${PRODUCT_NAME}.lnk"
11+
ExecShell "" "$SMPROGRAMS\${PRODUCT_FILENAME}.lnk"
1112
FunctionEnd
1213

1314
!ifdef ONE_CLICK
15+
SilentUnInstall silent
1416
AutoCloseWindow true
1517
!insertmacro MUI_PAGE_INSTFILES
1618
!insertmacro MUI_UNPAGE_INSTFILES
@@ -22,6 +24,11 @@ Var startMenuLink
2224
Var desktopLink
2325

2426
Function .onInit
27+
${IfNot} ${AtLeastWin7}
28+
MessageBox MB_OK "Windows 7 and above is required"
29+
Quit
30+
${EndIf}
31+
2532
!insertmacro MULTIUSER_INIT
2633
!insertmacro ALLOW_ONLY_ONE_INSTALLER_INSTACE
2734

@@ -33,7 +40,7 @@ Function .onInit
3340
!endif
3441
${Else}
3542
!ifndef APP_32
36-
MessageBox MB_OK|MB_ICONEXCLAMATION "64-bit Windows is required."
43+
MessageBox MB_OK|MB_ICONEXCLAMATION "64-bit Windows is required"
3744
Quit
3845
!endif
3946
${EndIf}
@@ -46,19 +53,22 @@ Function .onInit
4653
File /oname=$PLUGINSDIR\app-64.7z "${APP_64}"
4754
!endif
4855
SetCompress "${COMPRESS}"
56+
57+
!ifdef HEADER_ICO
58+
File /oname=$PLUGINSDIR\installerHeaderico.ico "${HEADER_ICO}"
59+
!endif
4960
FunctionEnd
5061

5162
Function un.onInit
5263
!insertmacro MULTIUSER_UNINIT
5364
FunctionEnd
5465

55-
# default section start
5666
Section "install"
5767
SetDetailsPrint none
5868

5969
!ifdef ONE_CLICK
6070
!ifdef HEADER_ICO
61-
SpiderBanner::Show /MODERN /ICON "${HEADER_ICO}"
71+
SpiderBanner::Show /MODERN /ICON "$PLUGINSDIR\installerHeaderico.ico"
6272
!else
6373
SpiderBanner::Show /MODERN
6474
!endif
@@ -77,14 +87,14 @@ Section "install"
7787

7888
# <% if(fileAssociation){ %>
7989
# specify file association
80-
# ${registerExtension} "$INSTDIR\${PRODUCT_NAME}.exe" "<%= fileAssociation.extension %>" "<%= fileAssociation.fileType %>"
90+
# ${registerExtension} "$INSTDIR\${PRODUCT_FILENAME}.exe" "<%= fileAssociation.extension %>" "<%= fileAssociation.fileType %>"
8191
# <% } %>
8292

8393
WriteUninstaller "${UNINSTALL_FILENAME}"
8494
!insertmacro MULTIUSER_RegistryAddInstallInfo
8595

86-
StrCpy $startMenuLink "$SMPROGRAMS\${PRODUCT_NAME}.lnk"
87-
StrCpy $desktopLink "$DESKTOP\${PRODUCT_NAME}.lnk"
96+
StrCpy $startMenuLink "$SMPROGRAMS\${PRODUCT_FILENAME}.lnk"
97+
StrCpy $desktopLink "$DESKTOP\${PRODUCT_FILENAME}.lnk"
8898

8999
# create shortcuts in the start menu and on the desktop
90100
# shortcut for uninstall is bad cause user can choose this by mistake during search, so, we don't add it
@@ -104,20 +114,20 @@ SectionEnd
104114
Section "un.install"
105115
!insertmacro CHECK_APP_RUNNING "uninstall"
106116

107-
StrCpy $startMenuLink "$SMPROGRAMS\${PRODUCT_NAME}.lnk"
108-
StrCpy $desktopLink "$DESKTOP\${PRODUCT_NAME}.lnk"
117+
StrCpy $startMenuLink "$SMPROGRAMS\${PRODUCT_FILENAME}.lnk"
118+
StrCpy $desktopLink "$DESKTOP\${PRODUCT_FILENAME}.lnk"
109119

110120
WinShell::UninstAppUserModelId "${APP_ID}"
111121
WinShell::UninstShortcut "$startMenuLink"
112-
WinShell::UninstShortcut "$$desktopLink"
122+
WinShell::UninstShortcut "$desktopLink"
113123

114124
Delete "$startMenuLink"
115125
Delete "$desktopLink"
116126

117127
# delete the installed files
118128
RMDir /r $INSTDIR
119129

120-
RMDir /r "$APPDATA\${PRODUCT_NAME}"
130+
RMDir /r "$APPDATA\${PRODUCT_FILENAME}"
121131

122132
!insertmacro MULTIUSER_RegistryRemoveInstallInfo
123133

test/src/winPackagerTest.ts

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -48,21 +48,7 @@ test.ifNotCiOsx("nsis boring", () => assertPack("test-app-one", _signed({
4848
}
4949
))
5050

51-
test.ifNotCiOsx("nsis boring", () => assertPack("test-app-one", _signed({
52-
targets: Platform.WINDOWS.createTarget(["nsis"]),
53-
devMetadata: {
54-
build: {
55-
nsis: {
56-
oneClick: false,
57-
}
58-
}
59-
}
60-
}), {
61-
useTempDir: true,
62-
}
63-
))
64-
65-
test.ifNotCiOsx("nsis, headerIcon", () => {
51+
test.ifNotCiOsx("nsis, installerHeaderIcon", () => {
6652
let headerIconPath: string | null = null
6753
return assertPack("test-app-one", {
6854
targets: Platform.WINDOWS.createTarget(["nsis"]),
@@ -73,7 +59,7 @@ test.ifNotCiOsx("nsis, headerIcon", () => {
7359
}
7460
}, {
7561
tempDirCreated: projectDir => {
76-
headerIconPath = path.join(projectDir, "build", "headerIcon.ico")
62+
headerIconPath = path.join(projectDir, "build", "installerHeaderIcon.ico")
7763
return rename(path.join(projectDir, "headerIcon.ico"), headerIconPath)
7864
}
7965
}

0 commit comments

Comments
 (0)