Skip to content

Commit

Permalink
feat(portable): Adding support for unique dir on each portable app la…
Browse files Browse the repository at this point in the history
…unch (#6093)

* Allowing boolean flag to `unpackDirName` to utilize `$PLUGINSDIR` (unique to per-app-launch) when set explicitly to `true`. Implements #5764, #5382, #4105
  • Loading branch information
mmaietta committed Jul 29, 2021
1 parent 4111358 commit f8e16db
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 11 deletions.
7 changes: 5 additions & 2 deletions packages/app-builder-lib/scheme.json
Expand Up @@ -4401,8 +4401,11 @@
"type": "boolean"
},
"unpackDirName": {
"description": "The unpack directory name in [TEMP](https://www.askvg.com/where-does-windows-store-temporary-files-and-how-to-change-temp-folder-location/) directory.\n\nDefaults to [uuid](https://github.com/segmentio/ksuid) of build (changed on each build of portable executable).",
"type": "string"
"description": "The unpack directory for the portable app resources.\nIf set to a string, it will be the name in [TEMP](https://www.askvg.com/where-does-windows-store-temporary-files-and-how-to-change-temp-folder-location/) directory.\nIf set explicitly to `false`, it will use the Windows temp directory ($PLUGINSDIR) that is unique to each launch of the portable application.\nDefaults to [uuid](https://github.com/segmentio/ksuid) of build (changed on each build of portable executable).",
"type": [
"string",
"boolean"
]
},
"useZip": {
"default": false,
Expand Down
14 changes: 9 additions & 5 deletions packages/app-builder-lib/src/targets/nsis/NsisTarget.ts
Expand Up @@ -247,12 +247,16 @@ export class NsisTarget extends Target {

this.configureDefinesForAllTypeOfInstaller(defines)
if (isPortable) {
const portableOptions = options as PortableOptions
defines.REQUEST_EXECUTION_LEVEL = portableOptions.requestExecutionLevel || "user"
defines.UNPACK_DIR_NAME = portableOptions.unpackDirName || (await executeAppBuilder(["ksuid"]))
const { unpackDirName, requestExecutionLevel, splashImage } = options as PortableOptions
defines.REQUEST_EXECUTION_LEVEL = requestExecutionLevel || "user"

if (portableOptions.splashImage != null) {
defines.SPLASH_IMAGE = path.resolve(packager.projectDir, portableOptions.splashImage)
// https://github.com/electron-userland/electron-builder/issues/5764
if (typeof unpackDirName === "string" || !unpackDirName) {
defines.UNPACK_DIR_NAME = unpackDirName || (await executeAppBuilder(["ksuid"]))
}

if (splashImage != null) {
defines.SPLASH_IMAGE = path.resolve(packager.projectDir, splashImage)
}
} else {
await this.configureDefines(oneClick, defines)
Expand Down
7 changes: 5 additions & 2 deletions packages/app-builder-lib/src/targets/nsis/nsisOptions.ts
Expand Up @@ -169,11 +169,14 @@ export interface PortableOptions extends TargetSpecificOptions, CommonNsisOption
readonly requestExecutionLevel?: "user" | "highest" | "admin"

/**
* The unpack directory name in [TEMP](https://www.askvg.com/where-does-windows-store-temporary-files-and-how-to-change-temp-folder-location/) directory.
* The unpack directory for the portable app resources.
*
* If set to a string, it will be the name in [TEMP](https://www.askvg.com/where-does-windows-store-temporary-files-and-how-to-change-temp-folder-location/) directory
* If set explicitly to `false`, it will use the Windows temp directory ($PLUGINSDIR) that is unique to each launch of the portable application.
*
* Defaults to [uuid](https://github.com/segmentio/ksuid) of build (changed on each build of portable executable).
*/
readonly unpackDirName?: string
readonly unpackDirName?: string | boolean

/**
* The image to show while the portable executable is extracting. This image must be a bitmap (`.bmp`) image.
Expand Down
8 changes: 6 additions & 2 deletions packages/app-builder-lib/templates/nsis/portable.nsi
Expand Up @@ -30,7 +30,11 @@ Section
HideWindow
!endif

StrCpy $INSTDIR "$TEMP\${UNPACK_DIR_NAME}"
StrCpy $INSTDIR "$PLUGINSDIR\app"
!ifdef UNPACK_DIR_NAME
StrCpy $INSTDIR "$TEMP\${UNPACK_DIR_NAME}"
!endif

RMDir /r $INSTDIR
SetOutPath $INSTDIR

Expand Down Expand Up @@ -82,6 +86,6 @@ Section
ExecWait "$INSTDIR\${APP_EXECUTABLE_FILENAME} $R0" $0
SetErrorLevel $0

SetOutPath $PLUGINSDIR
SetOutPath $EXEDIR
RMDir /r $INSTDIR
SectionEnd
2 changes: 2 additions & 0 deletions test/src/windows/portableTest.ts
Expand Up @@ -39,6 +39,7 @@ test.ifAll.ifNotCi(
publish: null,
portable: {
useZip: true,
unpackDirName: false,
},
compression: "store",
},
Expand All @@ -57,6 +58,7 @@ test.ifNotCiMac(
installerIcon: "foo test space.ico",
},
portable: {
unpackDirName: true,
requestExecutionLevel: "admin",
//tslint:disable-next-line:no-invalid-template-strings
artifactName: "${productName}Portable.${version}.${ext}",
Expand Down

0 comments on commit f8e16db

Please sign in to comment.