Skip to content

Commit

Permalink
feat(portable): adding splash image to portable nsis package
Browse files Browse the repository at this point in the history
  • Loading branch information
catdad authored and develar committed Nov 27, 2019
1 parent c80e5e6 commit 91e6183
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 5 deletions.
9 changes: 8 additions & 1 deletion packages/app-builder-lib/scheme.json
Original file line number Diff line number Diff line change
Expand Up @@ -3942,6 +3942,13 @@
}
]
},
"splashImage": {
"describe": "The image to show while the portable executable is extracting. This image must be a bitmap (`.bmp`) image.",
"type": [
"null",
"string"
]
},
"requestExecutionLevel": {
"default": "user",
"description": "The [requested execution level](http://nsis.sourceforge.net/Reference/RequestExecutionLevel) for Windows.",
Expand Down Expand Up @@ -5978,4 +5985,4 @@
}
},
"type": "object"
}
}
4 changes: 4 additions & 0 deletions packages/app-builder-lib/src/targets/nsis/NsisTarget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,10 @@ export class NsisTarget extends Target {
const portableOptions = options as PortableOptions
defines.REQUEST_EXECUTION_LEVEL = portableOptions.requestExecutionLevel || "user"
defines.UNPACK_DIR_NAME = portableOptions.unpackDirName || (await executeAppBuilder(["ksuid"]))

if (portableOptions.splashImage != null) {
defines.SPLASH_IMAGE = portableOptions.splashImage
}
}
else {
await this.configureDefines(oneClick, defines)
Expand Down
5 changes: 5 additions & 0 deletions packages/app-builder-lib/src/targets/nsis/nsisOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,11 @@ export interface PortableOptions extends TargetSpecificOptions, CommonNsisOption
* Defaults to [uuid](https://github.com/segmentio/ksuid) of build (changed on each build of portable executable).
*/
readonly unpackDirName?: string

/**
* The image to show while the portable executable is extracting. This image must be a bitmap (`.bmp`) image.
*/
readonly splashImage?: string | null
}

/**
Expand Down
23 changes: 21 additions & 2 deletions packages/app-builder-lib/templates/nsis/portable.nsi
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,27 @@ WindowIcon Off
AutoCloseWindow True
RequestExecutionLevel ${REQUEST_EXECUTION_LEVEL}

SilentInstall silent

Function .onInit
SetSilent silent

!insertmacro check64BitAndSetRegView
FunctionEnd

Function .onGUIInit
InitPluginsDir

!ifdef SPLASH_IMAGE
File /oname=$PLUGINSDIR\splash.bmp "${SPLASH_IMAGE}"
BgImage::SetBg $PLUGINSDIR\splash.bmp
BgImage::Redraw
!endif
FunctionEnd

Section
!ifdef SPLASH_IMAGE
HideWindow
!endif

StrCpy $INSTDIR "$TEMP\${UNPACK_DIR_NAME}"
RMDir /r $INSTDIR
SetOutPath $INSTDIR
Expand Down Expand Up @@ -58,6 +72,11 @@ Section
System::Call 'Kernel32::SetEnvironmentVariable(t, t)i ("PORTABLE_EXECUTABLE_FILE", "$EXEPATH").r0'
System::Call 'Kernel32::SetEnvironmentVariable(t, t)i ("PORTABLE_EXECUTABLE_APP_FILENAME", "${APP_FILENAME}").r0'
${StdUtils.GetAllParameters} $R0 0

!ifdef SPLASH_IMAGE
BgImage::Destroy
!endif

ExecWait "$INSTDIR\${APP_EXECUTABLE_FILENAME} $R0" $0
SetErrorLevel $0

Expand Down
12 changes: 12 additions & 0 deletions test/out/windows/__snapshots__/portableTest.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ Object {
}
`;

exports[`portable - splashImage 1`] = `
Object {
"win": Array [
Object {
"arch": "x64",
"file": "Test App ßWPortable.1.1.0.exe",
"safeArtifactName": "TestApp-1.1.0.exe",
},
],
}
`;

exports[`portable 1`] = `
Object {
"win": Array [
Expand Down
16 changes: 14 additions & 2 deletions test/src/windows/portableTest.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Platform, Arch } from "electron-builder"
import * as path from "path"
import { app, copyTestAsset } from "../helpers/packTester"
import { app, copyTestAsset, getFixtureDir } from "../helpers/packTester"

// build in parallel - https://github.com/electron-userland/electron-builder/issues/1340#issuecomment-286061789
test.ifAll.ifNotCiMac("portable", app({
Expand Down Expand Up @@ -54,4 +54,16 @@ test.ifNotCiMac("portable - artifactName and request execution level", app({
projectDirCreated: projectDir => {
return copyTestAsset("headerIcon.ico", path.join(projectDir, "build", "foo test space.ico"))
},
}))
}))

test.ifDevOrWinCi("portable - splashImage", app({
targets: Platform.WINDOWS.createTarget(["portable"]),
config: {
publish: null,
portable: {
//tslint:disable-next-line:no-invalid-template-strings
artifactName: "${productName}Portable.${version}.${ext}",
splashImage: path.resolve(getFixtureDir(), "installerHeader.bmp"),
},
},
}))

0 comments on commit 91e6183

Please sign in to comment.