Skip to content

Commit

Permalink
fix(nsis): installerHeaderIcon
Browse files Browse the repository at this point in the history
Close #525
  • Loading branch information
develar committed Jun 28, 2016
1 parent 726e574 commit 00e8da8
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 42 deletions.
2 changes: 1 addition & 1 deletion docs/Options.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ See [NSIS target notes](https://github.com/electron-userland/electron-builder/wi
| allowElevation | <a name="NsisOptions-allowElevation"></a>Allow requesting for elevation. If false, user will have to restart installer with elevated permissions. Defaults to `true`.
| oneClick | <a name="NsisOptions-oneClick"></a>One-click installation. Defaults to `true`.
| installerHeader | <a name="NsisOptions-installerHeader"></a>*boring installer only.* `MUI_HEADERIMAGE`, relative to the project directory. Defaults to `build/installerHeader.bmp`
| 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.
| 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.

<a name="LinuxBuildOptions"></a>
### `.build.linux`
Expand Down
4 changes: 2 additions & 2 deletions src/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -375,9 +375,9 @@ export interface NsisOptions {
readonly installerHeader?: string | null

/*
*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.
*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.
*/
readonly headerIcon?: string | null
readonly installerHeaderIcon?: string | null
}

/*
Expand Down
8 changes: 4 additions & 4 deletions src/targets/nsis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export default class NsisTarget extends Target {
APP_ID: appInfo.id,
APP_GUID: guid,
PRODUCT_NAME: appInfo.productName,
INST_DIR_NAME: appInfo.productFilename,
PRODUCT_FILENAME: appInfo.productFilename,
APP_DESCRIPTION: appInfo.description,
VERSION: version,

Expand All @@ -82,9 +82,9 @@ export default class NsisTarget extends Target {
defines.MUI_HEADERIMAGE_BITMAP = installerHeader
}

const headerIcon = oneClick ? await this.getResource(this.options.headerIcon, "headerIcon.ico") : null
if (headerIcon != null) {
defines.HEADER_ICO = headerIcon
const installerHeaderIcon = oneClick ? await this.getResource(this.options.installerHeaderIcon, "installerHeaderIcon.ico") : null
if (installerHeaderIcon != null) {
defines.HEADER_ICO = installerHeaderIcon
}

if (this.options.perMachine === true) {
Expand Down
2 changes: 1 addition & 1 deletion src/targets/squirrelWindows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default class SquirrelWindowsTarget extends Target {
const appInfo = this.packager.appInfo
const version = appInfo.version
const archSuffix = getArchSuffix(arch)
const setupFileName = `${appInfo.productFilename} Setup ${version}${archSuffix}.exe`
const setupFileName = `${appInfo.productFilename} Setup ${version}${archSuffix}.exe`

const installerOutDir = path.join(appOutDir, "..", `win${getArchSuffix(arch)}`)
await emptyDir(installerOutDir)
Expand Down
8 changes: 4 additions & 4 deletions templates/nsis/NsisMultiUser.nsh
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ Var RadioButtonLabel1
!define FOLDERID_UserProgramFiles {5CD7AEE2-2219-4A67-B85D-6C9CE15660CB}
!define KF_FLAG_CREATE 0x00008000

!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
!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
!else
!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"
!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"
!endif

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

!if "${UNINSTALLER_PREFIX}" != UN
;Set default installation location for installer
StrCpy $INSTDIR "$PROGRAMFILES\${INST_DIR_NAME}"
StrCpy $INSTDIR "$PROGRAMFILES\${PRODUCT_FILENAME}"
!endif

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

; Checks registry for previous installation path (both for upgrading, reinstall, or uninstall)
Expand Down
1 change: 0 additions & 1 deletion templates/nsis/boring-installer.nsh
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# http://nsis.sourceforge.net/Run_an_application_shortcut_after_an_install
#!define MUI_FINISHPAGE_RUN_TEXT "Start ${PRODUCT_NAME}"
!define MUI_FINISHPAGE_RUN
!define MUI_FINISHPAGE_RUN_FUNCTION "StartApp"

Expand Down
4 changes: 2 additions & 2 deletions templates/nsis/common.nsh
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ Unicode true
!define MULTIUSER_INSTALLMODE_INSTALL_REGISTRY_KEY "${APP_GUID}"
!define MULTIUSER_INSTALLMODE_UNINSTALL_REGISTRY_KEY "${APP_GUID}"

!define APP_EXECUTABLE_FILENAME "${PRODUCT_NAME}.exe"
!define UNINSTALL_FILENAME "Uninstall ${PRODUCT_NAME}.exe"
!define APP_EXECUTABLE_FILENAME "${PRODUCT_FILENAME}.exe"
!define UNINSTALL_FILENAME "Uninstall ${PRODUCT_FILENAME}.exe"
32 changes: 21 additions & 11 deletions templates/nsis/installer.nsi
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
!include "allowOnlyOneInstallerInstace.nsh"
!include "checkAppRunning.nsh"
!include x64.nsh
!include WinVer.nsh

Function StartApp
ExecShell "" "$SMPROGRAMS\${PRODUCT_NAME}.lnk"
ExecShell "" "$SMPROGRAMS\${PRODUCT_FILENAME}.lnk"
FunctionEnd

!ifdef ONE_CLICK
SilentUnInstall silent
AutoCloseWindow true
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_UNPAGE_INSTFILES
Expand All @@ -22,6 +24,11 @@ Var startMenuLink
Var desktopLink

Function .onInit
${IfNot} ${AtLeastWin7}
MessageBox MB_OK "Windows 7 and above is required"
Quit
${EndIf}

!insertmacro MULTIUSER_INIT
!insertmacro ALLOW_ONLY_ONE_INSTALLER_INSTACE

Expand All @@ -33,7 +40,7 @@ Function .onInit
!endif
${Else}
!ifndef APP_32
MessageBox MB_OK|MB_ICONEXCLAMATION "64-bit Windows is required."
MessageBox MB_OK|MB_ICONEXCLAMATION "64-bit Windows is required"
Quit
!endif
${EndIf}
Expand All @@ -46,19 +53,22 @@ Function .onInit
File /oname=$PLUGINSDIR\app-64.7z "${APP_64}"
!endif
SetCompress "${COMPRESS}"

!ifdef HEADER_ICO
File /oname=$PLUGINSDIR\installerHeaderico.ico "${HEADER_ICO}"
!endif
FunctionEnd

Function un.onInit
!insertmacro MULTIUSER_UNINIT
FunctionEnd

# default section start
Section "install"
SetDetailsPrint none

!ifdef ONE_CLICK
!ifdef HEADER_ICO
SpiderBanner::Show /MODERN /ICON "${HEADER_ICO}"
SpiderBanner::Show /MODERN /ICON "$PLUGINSDIR\installerHeaderico.ico"
!else
SpiderBanner::Show /MODERN
!endif
Expand All @@ -77,14 +87,14 @@ Section "install"

# <% if(fileAssociation){ %>
# specify file association
# ${registerExtension} "$INSTDIR\${PRODUCT_NAME}.exe" "<%= fileAssociation.extension %>" "<%= fileAssociation.fileType %>"
# ${registerExtension} "$INSTDIR\${PRODUCT_FILENAME}.exe" "<%= fileAssociation.extension %>" "<%= fileAssociation.fileType %>"
# <% } %>

WriteUninstaller "${UNINSTALL_FILENAME}"
!insertmacro MULTIUSER_RegistryAddInstallInfo

StrCpy $startMenuLink "$SMPROGRAMS\${PRODUCT_NAME}.lnk"
StrCpy $desktopLink "$DESKTOP\${PRODUCT_NAME}.lnk"
StrCpy $startMenuLink "$SMPROGRAMS\${PRODUCT_FILENAME}.lnk"
StrCpy $desktopLink "$DESKTOP\${PRODUCT_FILENAME}.lnk"

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

StrCpy $startMenuLink "$SMPROGRAMS\${PRODUCT_NAME}.lnk"
StrCpy $desktopLink "$DESKTOP\${PRODUCT_NAME}.lnk"
StrCpy $startMenuLink "$SMPROGRAMS\${PRODUCT_FILENAME}.lnk"
StrCpy $desktopLink "$DESKTOP\${PRODUCT_FILENAME}.lnk"

WinShell::UninstAppUserModelId "${APP_ID}"
WinShell::UninstShortcut "$startMenuLink"
WinShell::UninstShortcut "$$desktopLink"
WinShell::UninstShortcut "$desktopLink"

Delete "$startMenuLink"
Delete "$desktopLink"

# delete the installed files
RMDir /r $INSTDIR

RMDir /r "$APPDATA\${PRODUCT_NAME}"
RMDir /r "$APPDATA\${PRODUCT_FILENAME}"

!insertmacro MULTIUSER_RegistryRemoveInstallInfo

Expand Down
18 changes: 2 additions & 16 deletions test/src/winPackagerTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,7 @@ test.ifNotCiOsx("nsis boring", () => assertPack("test-app-one", _signed({
}
))

test.ifNotCiOsx("nsis boring", () => assertPack("test-app-one", _signed({
targets: Platform.WINDOWS.createTarget(["nsis"]),
devMetadata: {
build: {
nsis: {
oneClick: false,
}
}
}
}), {
useTempDir: true,
}
))

test.ifNotCiOsx("nsis, headerIcon", () => {
test.ifNotCiOsx("nsis, installerHeaderIcon", () => {
let headerIconPath: string | null = null
return assertPack("test-app-one", {
targets: Platform.WINDOWS.createTarget(["nsis"]),
Expand All @@ -73,7 +59,7 @@ test.ifNotCiOsx("nsis, headerIcon", () => {
}
}, {
tempDirCreated: projectDir => {
headerIconPath = path.join(projectDir, "build", "headerIcon.ico")
headerIconPath = path.join(projectDir, "build", "installerHeaderIcon.ico")
return rename(path.join(projectDir, "headerIcon.ico"), headerIconPath)
}
}
Expand Down

0 comments on commit 00e8da8

Please sign in to comment.