Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/tidy-melons-crash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"app-builder-lib": patch
---

feat: add nsis support for `allowToAddShortcuts` (user decides wether to add a shortcut or not)
)
5 changes: 5 additions & 0 deletions packages/app-builder-lib/scheme.json
Original file line number Diff line number Diff line change
Expand Up @@ -4038,6 +4038,11 @@
"description": "*assisted installer only.* Allow requesting for elevation. If false, user will have to restart installer with elevated permissions.",
"type": "boolean"
},
"allowToAddShortcut": {
"default": false,
"description": "*assisted installer only.* Whether to allow the user to choose to add desktop/start menu shortcuts during installation.",
"type": "boolean"
},
"allowToChangeInstallationDirectory": {
"default": false,
"description": "*assisted installer only.* Whether to allow user to change installation directory.",
Expand Down
2 changes: 2 additions & 0 deletions packages/app-builder-lib/src/targets/nsis/Defines.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ export type Defines = {
INSTALL_MODE_PER_ALL_USERS_DEFAULT?: null
INSTALL_MODE_PER_ALL_USERS_REQUIRED?: null

ALLOW_TO_ADD_SHORTCUT?: null

allowToChangeInstallationDirectory?: null

removeDefaultUninstallWelcomePage?: null
Expand Down
7 changes: 7 additions & 0 deletions packages/app-builder-lib/src/targets/nsis/NsisTarget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,13 @@ export class NsisTarget extends Target {
defines.allowToChangeInstallationDirectory = null
}

if (options.allowToAddShortcut) {
if (oneClick) {
throw new InvalidConfigurationError("allowToAddShortcut makes sense only for assisted installer (please set oneClick to false)")
}
defines.ALLOW_TO_ADD_SHORTCUT = null
}

if (options.removeDefaultUninstallWelcomePage) {
defines.removeDefaultUninstallWelcomePage = null
}
Expand Down
8 changes: 8 additions & 0 deletions packages/app-builder-lib/src/targets/nsis/nsisOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,14 @@ export interface NsisOptions extends CommonNsisOptions, CommonWindowsInstallerCo
*/
readonly allowElevation?: boolean

/**
* *assisted installer only.* Allows the user to choose whether to create desktop and/or start menu shortcuts during installation (e.g. via checkboxes).
* By default, both shortcuts are created automatically.
* If enabled, the user can opt-in or opt-out at install time.
* @default false
*/
readonly allowToAddShortcut?: boolean
Copy link
Collaborator

Choose a reason for hiding this comment

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

Thoughts on renaming this to allowToCustomizeShortcuts since it supports customizing desktop and/or start menu. Thinking "Customize" because it allows the user to allow/enable or disable/remove shortcuts from being created.

Copy link
Author

Choose a reason for hiding this comment

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

why not, good idea

Copy link
Collaborator

Choose a reason for hiding this comment

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

@jaywalker15262 I am unable to push changes to this PR to update the property. Can you please attend to this and I'll be happy to proceed with merging.


/**
* *assisted installer only.* Whether to allow user to change installation directory.
* @default false
Expand Down
5 changes: 5 additions & 0 deletions packages/app-builder-lib/templates/nsis/assistedInstaller.nsh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
!insertmacro PAGE_INSTALL_MODE
!endif

!ifdef ALLOW_TO_ADD_SHORTCUT
!include shortcutsPage.nsh
!insertmacro PAGE_SHORTCUTS
!endif

!ifdef allowToChangeInstallationDirectory
!include StrContains.nsh

Expand Down
143 changes: 97 additions & 46 deletions packages/app-builder-lib/templates/nsis/include/installer.nsh
Original file line number Diff line number Diff line change
Expand Up @@ -187,61 +187,112 @@
!macroend

!macro addStartMenuLink keepShortcuts
!ifndef DO_NOT_CREATE_START_MENU_SHORTCUT
# The keepShortcuts mechanism is NOT enabled.
# Menu shortcut will be recreated.
${if} $keepShortcuts == "false"
!insertmacro cleanupOldMenuDirectory
!insertmacro createMenuDirectory

CreateShortCut "$newStartMenuLink" "$appExe" "" "$appExe" 0 "" "" "${APP_DESCRIPTION}"
# clear error (if shortcut already exists)
ClearErrors
WinShell::SetLnkAUMI "$newStartMenuLink" "${APP_ID}"
# The keepShortcuts mechanism IS enabled.
# The menu shortcut could either not exist (it shouldn't be recreated) or exist in an obsolete location.
${elseif} $oldStartMenuLink != $newStartMenuLink
${andIf} ${FileExists} "$oldStartMenuLink"
!insertmacro createMenuDirectory

Rename $oldStartMenuLink $newStartMenuLink
WinShell::UninstShortcut "$oldStartMenuLink"
WinShell::SetLnkAUMI "$newStartMenuLink" "${APP_ID}"

!insertmacro cleanupOldMenuDirectory
${endIf}
!ifndef ONE_CLICK
!ifdef ALLOW_TO_ADD_SHORTCUT
${If} $USER_STARTMENU_SHORTCUT_CHOICE == "1"
${if} $keepShortcuts == "false"
!insertmacro cleanupOldMenuDirectory
!insertmacro createMenuDirectory
CreateShortCut "$newStartMenuLink" "$appExe" "" "$appExe" 0 "" "" "${APP_DESCRIPTION}"
ClearErrors
WinShell::SetLnkAUMI "$newStartMenuLink" "${APP_ID}"
${elseif} $oldStartMenuLink != $newStartMenuLink
${andIf} ${FileExists} "$oldStartMenuLink"
!insertmacro createMenuDirectory
Rename $oldStartMenuLink $newStartMenuLink
WinShell::UninstShortcut "$oldStartMenuLink"
WinShell::SetLnkAUMI "$newStartMenuLink" "${APP_ID}"
!insertmacro cleanupOldMenuDirectory
${endIf}
${EndIf}
!else
!ifndef DO_NOT_CREATE_START_MENU_SHORTCUT
${if} $keepShortcuts == "false"
!insertmacro cleanupOldMenuDirectory
!insertmacro createMenuDirectory
CreateShortCut "$newStartMenuLink" "$appExe" "" "$appExe" 0 "" "" "${APP_DESCRIPTION}"
ClearErrors
WinShell::SetLnkAUMI "$newStartMenuLink" "${APP_ID}"
${elseif} $oldStartMenuLink != $newStartMenuLink
${andIf} ${FileExists} "$oldStartMenuLink"
!insertmacro createMenuDirectory
Rename $oldStartMenuLink $newStartMenuLink
WinShell::UninstShortcut "$oldStartMenuLink"
WinShell::SetLnkAUMI "$newStartMenuLink" "${APP_ID}"
!insertmacro cleanupOldMenuDirectory
${endIf}
!endif
!endif
!else
!ifndef DO_NOT_CREATE_START_MENU_SHORTCUT
${if} $keepShortcuts == "false"
!insertmacro cleanupOldMenuDirectory
!insertmacro createMenuDirectory
CreateShortCut "$newStartMenuLink" "$appExe" "" "$appExe" 0 "" "" "${APP_DESCRIPTION}"
ClearErrors
WinShell::SetLnkAUMI "$newStartMenuLink" "${APP_ID}"
${elseif} $oldStartMenuLink != $newStartMenuLink
${andIf} ${FileExists} "$oldStartMenuLink"
!insertmacro createMenuDirectory
Rename $oldStartMenuLink $newStartMenuLink
WinShell::UninstShortcut "$oldStartMenuLink"
WinShell::SetLnkAUMI "$newStartMenuLink" "${APP_ID}"
!insertmacro cleanupOldMenuDirectory
${endIf}
!endif
!endif
!macroend

!macro addDesktopLink keepShortcuts
!ifndef DO_NOT_CREATE_DESKTOP_SHORTCUT
# https://github.com/electron-userland/electron-builder/pull/1432
${ifNot} ${isNoDesktopShortcut}
# The keepShortcuts mechanism is NOT enabled.
# Shortcuts will be recreated.
${if} $keepShortcuts == "false"
CreateShortCut "$newDesktopLink" "$appExe" "" "$appExe" 0 "" "" "${APP_DESCRIPTION}"
ClearErrors
WinShell::SetLnkAUMI "$newDesktopLink" "${APP_ID}"
# The keepShortcuts mechanism IS enabled.
# The desktop shortcut could exist in an obsolete location (due to name change).
${elseif} $oldDesktopLink != $newDesktopLink
${andIf} ${FileExists} "$oldDesktopLink"
Rename $oldDesktopLink $newDesktopLink
WinShell::UninstShortcut "$oldDesktopLink"
WinShell::SetLnkAUMI "$newDesktopLink" "${APP_ID}"

!ifdef RECREATE_DESKTOP_SHORTCUT
${elseif} $oldDesktopLink != $newDesktopLink
${orIfNot} ${FileExists} "$oldDesktopLink"
${ifNot} ${isUpdated}
!ifndef ONE_CLICK
!ifdef ALLOW_TO_ADD_SHORTCUT
${If} $USER_DESKTOP_SHORTCUT_CHOICE == "1"
${ifNot} ${isNoDesktopShortcut}
${if} $keepShortcuts == "false"
CreateShortCut "$newDesktopLink" "$appExe" "" "$appExe" 0 "" "" "${APP_DESCRIPTION}"
ClearErrors
WinShell::SetLnkAUMI "$newDesktopLink" "${APP_ID}"
${elseif} $oldDesktopLink != $newDesktopLink
${andIf} ${FileExists} "$oldDesktopLink"
Rename $oldDesktopLink $newDesktopLink
WinShell::UninstShortcut "$oldDesktopLink"
WinShell::SetLnkAUMI "$newDesktopLink" "${APP_ID}"
${endIf}
${endIf}
System::Call 'Shell32::SHChangeNotify(i 0x8000000, i 0, i 0, i 0)'
${EndIf}
!else
!ifndef DO_NOT_CREATE_DESKTOP_SHORTCUT
${ifNot} ${isNoDesktopShortcut}
${if} $keepShortcuts == "false"
CreateShortCut "$newDesktopLink" "$appExe" "" "$appExe" 0 "" "" "${APP_DESCRIPTION}"
ClearErrors
WinShell::SetLnkAUMI "$newDesktopLink" "${APP_ID}"
${elseif} $oldDesktopLink != $newDesktopLink
${andIf} ${FileExists} "$oldDesktopLink"
Rename $oldDesktopLink $newDesktopLink
WinShell::UninstShortcut "$oldDesktopLink"
WinShell::SetLnkAUMI "$newDesktopLink" "${APP_ID}"
${endIf}
${endIf}
System::Call 'Shell32::SHChangeNotify(i 0x8000000, i 0, i 0, i 0)'
!endif
!endif
!else
!ifndef DO_NOT_CREATE_DESKTOP_SHORTCUT
${ifNot} ${isNoDesktopShortcut}
${if} $keepShortcuts == "false"
CreateShortCut "$newDesktopLink" "$appExe" "" "$appExe" 0 "" "" "${APP_DESCRIPTION}"
ClearErrors
WinShell::SetLnkAUMI "$newDesktopLink" "${APP_ID}"
${elseif} $oldDesktopLink != $newDesktopLink
${andIf} ${FileExists} "$oldDesktopLink"
Rename $oldDesktopLink $newDesktopLink
WinShell::UninstShortcut "$oldDesktopLink"
WinShell::SetLnkAUMI "$newDesktopLink" "${APP_ID}"
${endIf}
!endif
${endIf}
System::Call 'Shell32::SHChangeNotify(i 0x8000000, i 0, i 0, i 0)'
${endIf}
!endif
!endif
!macroend
9 changes: 9 additions & 0 deletions packages/app-builder-lib/templates/nsis/installer.nsi
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ Var oldDesktopLink
Var oldShortcutName
Var oldMenuDirectory

!ifndef BUILD_UNINSTALLER
!ifndef ONE_CLICK
!ifdef ALLOW_TO_ADD_SHORTCUT
Var USER_DESKTOP_SHORTCUT_CHOICE
Var USER_STARTMENU_SHORTCUT_CHOICE
!endif
!endif
!endif

!include "common.nsh"
!include "MUI2.nsh"
!include "multiUser.nsh"
Expand Down
44 changes: 44 additions & 0 deletions packages/app-builder-lib/templates/nsis/shortcutsPage.nsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
!include nsDialogs.nsh

Var ShortcutsPageDialog
Var SHORTCUT_DESKTOP_CHECKBOX
Var SHORTCUT_STARTMENU_CHECKBOX

!macro PAGE_SHORTCUTS
!insertmacro MUI_PAGE_INIT
!insertmacro MUI_SET SHORTCUTS_PAGE ""

PageEx custom
PageCallbacks ShortcutsPagePre ShortcutsPageLeave
Caption "Shortcuts"
PageExEnd
!macroend

Function ShortcutsPagePre
nsDialogs::Create 1018
Pop $ShortcutsPageDialog
${If} $ShortcutsPageDialog == "error"
Abort
${EndIf}

${NSD_CreateCheckBox} 10u 10u 120u 12u "Create Desktop Shortcut"
Pop $SHORTCUT_DESKTOP_CHECKBOX
!ifndef DO_NOT_CREATE_DESKTOP_SHORTCUT
${NSD_Check} $SHORTCUT_DESKTOP_CHECKBOX
!endif

${NSD_CreateCheckBox} 10u 30u 140u 12u "Create Start Menu Shortcut"
Pop $SHORTCUT_STARTMENU_CHECKBOX
!ifndef DO_NOT_CREATE_START_MENU_SHORTCUT
${NSD_Check} $SHORTCUT_STARTMENU_CHECKBOX
!endif

nsDialogs::Show
FunctionEnd

Function ShortcutsPageLeave
${NSD_GetState} $SHORTCUT_DESKTOP_CHECKBOX $0
StrCpy $USER_DESKTOP_SHORTCUT_CHOICE $0
${NSD_GetState} $SHORTCUT_STARTMENU_CHECKBOX $0
StrCpy $USER_STARTMENU_SHORTCUT_CHOICE $0
FunctionEnd
Loading