Skip to content

Commit 350e241

Browse files
committed
feat(nsis): option to not create desktop shortcut
Close #1597
1 parent 02dd8a1 commit 350e241

File tree

5 files changed

+24
-9
lines changed

5 files changed

+24
-9
lines changed

docs/Options.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ Configuration Options
275275
If `oneClick` is `false`: no install mode installer page (choice per-machine or per-user), always install per-machine.
276276
* <a name="NsisOptions-allowElevation"></a>`allowElevation` = `true` Boolean - *boring installer only.* Allow requesting for elevation. If false, user will have to restart installer with elevated permissions.
277277
* <a name="NsisOptions-allowToChangeInstallationDirectory"></a>`allowToChangeInstallationDirectory` = `false` Boolean - *boring installer only.* Whether to allow user to change installation directory.
278+
* <a name="NsisOptions-createDesktopShortcut"></a>`createDesktopShortcut` = `true` Boolean - Whether to create desktop shortcut.
278279
* <a name="NsisOptions-runAfterFinish"></a>`runAfterFinish` = `true` Boolean - *one-click installer only.* Run application after finish.
279280
* <a name="NsisOptions-installerIcon"></a>`installerIcon` String - The path to installer icon, relative to the the [build resources](https://github.com/electron-userland/electron-builder/wiki/Options#MetadataDirectories-buildResources) or to the project directory. Defaults to `build/installerIcon.ico` or application icon.
280281
* <a name="NsisOptions-uninstallerIcon"></a>`uninstallerIcon` String - The path to uninstaller icon, relative to the the [build resources](https://github.com/electron-userland/electron-builder/wiki/Options#MetadataDirectories-buildResources) or to the project directory. Defaults to `build/uninstallerIcon.ico` or application icon.

packages/electron-builder/src/options/winOptions.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,12 @@ export interface NsisOptions extends CommonNsisOptions, TargetSpecificOptions {
132132
*/
133133
readonly allowToChangeInstallationDirectory?: boolean
134134

135+
/**
136+
* Whether to create desktop shortcut.
137+
* @default true
138+
*/
139+
readonly createDesktopShortcut?: boolean
140+
135141
/**
136142
* *one-click installer only.* Run application after finish.
137143
* @default true

packages/electron-builder/src/targets/nsis.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,10 @@ export class NsisTarget extends Target {
410410
defines.MUI_UNICON = uninstallerIcon
411411
}
412412

413-
defines.UNINSTALL_DISPLAY_NAME = packager.expandMacro(this.options.uninstallDisplayName || "${productName} ${version}", null, {}, false)
413+
defines.UNINSTALL_DISPLAY_NAME = packager.expandMacro(options.uninstallDisplayName || "${productName} ${version}", null, {}, false)
414+
if (options.createDesktopShortcut === false) {
415+
defines.DO_NOT_CREATE_DESKTOP_SHORTCUT = null
416+
}
414417
}
415418

416419
private configureDefinesForAllTypeOfInstaller(defines: any) {

packages/electron-builder/templates/nsis/installSection.nsh

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,18 @@ ${endif}
8787

8888
StrCpy $appExe "$INSTDIR\${APP_EXECUTABLE_FILENAME}"
8989
Var /GLOBAL shortcuts
90-
StrCpy $shortcuts ""
91-
!ifndef allowToChangeInstallationDirectory
92-
ReadRegStr $R1 SHELL_CONTEXT "${INSTALL_REGISTRY_KEY}" KeepShortcuts
93-
94-
${if} $R1 == "true"
95-
${andIf} ${FileExists} "$appExe"
96-
StrCpy $shortcuts "--keep-shortcuts"
97-
${endIf}
90+
!ifdef DO_NOT_CREATE_DESKTOP_SHORTCUT
91+
StrCpy $shortcuts "--keep-shortcuts"
92+
!else
93+
StrCpy $shortcuts ""
94+
!ifndef allowToChangeInstallationDirectory
95+
ReadRegStr $R1 SHELL_CONTEXT "${INSTALL_REGISTRY_KEY}" KeepShortcuts
96+
97+
${if} $R1 == "true"
98+
${andIf} ${FileExists} "$appExe"
99+
StrCpy $shortcuts "--keep-shortcuts"
100+
${endIf}
101+
!endif
98102
!endif
99103

100104
!ifdef ONE_CLICK

test/src/windows/oneClickInstallerTest.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ test.ifAll.ifNotCiMac("multi language license", app({
3737
publish: null,
3838
nsis: {
3939
uninstallDisplayName: "Hi!!!",
40+
createDesktopShortcut: false,
4041
}
4142
},
4243
}, {

0 commit comments

Comments
 (0)