Skip to content

Commit

Permalink
feat(nsis): Different Icon for installer / App ? (Windows)
Browse files Browse the repository at this point in the history
Closes #525
  • Loading branch information
develar committed Jun 26, 2016
1 parent b0319c6 commit 65650ea
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 15 deletions.
2 changes: 1 addition & 1 deletion docker/nsis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ rm -rf Docs
rm -rf NSIS.chm
rm -rf Examples
rm -rf Plugins/x86-ansi
unlink makensisw.exe
rm -f makensisw.exe

# nsProcess plugin
curl -L http://nsis.sourceforge.net/mediawiki/images/1/18/NsProcess.zip > a.zip
Expand Down
1 change: 1 addition & 0 deletions docs/Options.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +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.

<a name="LinuxBuildOptions"></a>
### `.build.linux`
Expand Down
5 changes: 5 additions & 0 deletions src/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,11 @@ export interface NsisOptions {
*boring installer only.* `MUI_HEADERIMAGE`, relative to the project directory. Defaults to `build/installerHeader.bmp`
*/
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.
*/
readonly headerIcon?: string | null
}

/*
Expand Down
37 changes: 24 additions & 13 deletions src/targets/nsis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import semver = require("semver")
//noinspection JSUnusedLocalSymbols
const __awaiter = require("../util/awaiter")

const NSIS_VERSION = "nsis-3.0.0-rc.1.2"
const NSIS_VERSION = "nsis-3.0.0-rc.1.3"
//noinspection SpellCheckingInspection
const NSIS_SHA2 = "d96f714ba552a5ebccf2593ed3fee1b072b67e7bfd1b90d66a5eb0cd3ca41d16"
const NSIS_SHA2 = "77bca57e784372dea1b69b0571d89d5a1c879c51d80d7c503f283a2e7de5f072"

//noinspection SpellCheckingInspection
const ELECTRON_BUILDER_NS_UUID = "50e065bc-3134-11e6-9bab-38c9862bdaf3"
Expand Down Expand Up @@ -75,23 +75,20 @@ export default class NsisTarget extends Target {
defines[arch === Arch.x64 ? "APP_64" : "APP_32"] = await file
}

let installerHeader = this.options.installerHeader
if (installerHeader === undefined) {
const resourceList = await packager.resourceList
if (resourceList.includes("installerHeader.bmp")) {
installerHeader = path.join(packager.buildResourcesDir, "installerHeader.bmp")
}
}
else {
installerHeader = path.resolve(packager.projectDir, installerHeader)
}
const oneClick = this.options.oneClick !== false

const installerHeader = oneClick ? null : await this.getResource(this.options.installerHeader, "installerHeader.bmp")
if (installerHeader != null) {
defines.MUI_HEADERIMAGE = null
defines.MUI_HEADERIMAGE_RIGHT = null
defines.MUI_HEADERIMAGE_BITMAP = installerHeader
}

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

if (this.options.perMachine === true) {
defines.MULTIUSER_INSTALLMODE_DEFAULT_ALLUSERS = null
}
Expand Down Expand Up @@ -132,7 +129,6 @@ export default class NsisTarget extends Target {
defines.COMPRESS = "auto"
}

const oneClick = this.options.oneClick !== false
if (oneClick) {
defines.ONE_CLICK = null
}
Expand All @@ -150,6 +146,21 @@ export default class NsisTarget extends Target {
this.packager.dispatchArtifactCreated(installerPath, `${appInfo.name}-Setup-${version}.exe`)
}

protected async getResource(custom: string | n, name: string): Promise<string | null> {
let result = custom
if (result === undefined) {
const resourceList = await this.packager.resourceList
if (resourceList.includes(name)) {
return path.join(this.packager.buildResourcesDir, name)
}
}
else {
return path.resolve(this.packager.projectDir, result)
}

return null
}

private static async executeMakensis(defines: any, commands: any) {
const args: Array<string> = []
for (let name of Object.keys(defines)) {
Expand Down
6 changes: 5 additions & 1 deletion templates/nsis/installer.nsi
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ Section "install"
SetDetailsPrint none

!ifdef ONE_CLICK
SpiderBanner::Show /MODERN
!ifdef HEADER_ICO
SpiderBanner::Show /MODERN /ICON "${HEADER_ICO}"
!else
SpiderBanner::Show /MODERN
!endif
!endif

!insertmacro CHECK_APP_RUNNING "install"
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/test-app-one/headerIcon.ico
Git LFS file not shown
18 changes: 18 additions & 0 deletions test/src/winPackagerTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,24 @@ test.ifNotCiOsx("nsis boring", () => assertPack("test-app-one", _signed({
}
))

test.ifNotCiOsx("nsis, headerIcon", () => {
let headerIconPath: string | null = null
return assertPack("test-app-one", {
targets: Platform.WINDOWS.createTarget(["nsis"]),
effectiveOptionComputed: options => {
const defines = options[0]
assertThat(defines.HEADER_ICO).isEqualTo(headerIconPath)
return false
}
}, {
tempDirCreated: projectDir => {
headerIconPath = path.join(projectDir, "build", "headerIcon.ico")
return rename(path.join(projectDir, "headerIcon.ico"), headerIconPath)
}
}
)
})

test.ifNotCiOsx("nsis boring, MUI_HEADER", () => {
let installerHeaderPath: string | null = null
return assertPack("test-app-one", {
Expand Down

0 comments on commit 65650ea

Please sign in to comment.