Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(portable): adding splash image to portable nsis package #4425

9 changes: 8 additions & 1 deletion packages/app-builder-lib/scheme.json
Original file line number Diff line number Diff line change
Expand Up @@ -3928,6 +3928,13 @@
}
]
},
"splashImage": {
"describe": "An 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 @@ -5964,4 +5971,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) {
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

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

/**
Expand Down
22 changes: 20 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
!ifndef SPLASH_IMAGE
SetSilent silent
!endif

!insertmacro check64BitAndSetRegView
FunctionEnd

Function .onGUIInit
InitPluginsDir

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

Section
HideWindow

StrCpy $INSTDIR "$TEMP\${UNPACK_DIR_NAME}"
RMDir /r $INSTDIR
SetOutPath $INSTDIR
Expand Down Expand Up @@ -54,6 +68,10 @@ Section
!endif
!endif

!ifdef SPLASH_IMAGE
BgImage::Destroy
!endif

System::Call 'Kernel32::SetEnvironmentVariable(t, t)i ("PORTABLE_EXECUTABLE_DIR", "$EXEDIR").r0'
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'
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.ifNotCiMac("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"),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not a fan of this one. However, I tried tracing through the code quickly and did not find an appropriate location to translate relative input (some-dir/my-image.bmp) to the full path (C:\\Users\\Me\\my-project\\some-dir\\my-image.bmp). I am not sure if NSIS will use a relative path (most likely yes), but it didn't work when I just followed the examples of existing tests.

I'd appreciate any help here. Where would be the best place in the code to resolve the path for this image?

},
},
}))