diff --git a/package.json b/package.json index aab1ae4..0c5cc81 100644 --- a/package.json +++ b/package.json @@ -34,6 +34,7 @@ "dist:mac": "npm run build && npm run rebuild:native && electron-builder --mac" }, "build": { + "beforePack": "./scripts/before-pack.mjs", "appId": "com.scoreko.desktop", "productName": "Scoreko", "artifactName": "${productName}-${version}-${os}-${arch}.${ext}", @@ -81,6 +82,7 @@ "signAndEditExecutable": true }, "nsis": { + "include": "static/installer.nsh", "oneClick": false, "allowToChangeInstallationDirectory": true, "artifactName": "${productName}-setup-${version}.${ext}", diff --git a/scripts/before-pack.mjs b/scripts/before-pack.mjs new file mode 100644 index 0000000..d8b5bde --- /dev/null +++ b/scripts/before-pack.mjs @@ -0,0 +1,13 @@ +// scripts/beforePack.mjs +import fs from 'fs'; +import path from 'path'; +import { fileURLToPath } from 'url'; + +const __dirname = path.dirname(fileURLToPath(import.meta.url)); + +export default async function () { + const src = path.resolve(__dirname, '../static/installSection.nsh'); + const dest = path.resolve(__dirname, '../node_modules/app-builder-lib/templates/nsis/installSection.nsh'); + fs.copyFileSync(src, dest); + console.log('✅ installSection.nsh parcheado'); +} \ No newline at end of file diff --git a/static/installSection.nsh b/static/installSection.nsh new file mode 100644 index 0000000..3a06368 --- /dev/null +++ b/static/installSection.nsh @@ -0,0 +1,110 @@ +!include installer.nsh + +InitPluginsDir + +${IfNot} ${Silent} + SetDetailsPrint both +${endif} + +StrCpy $appExe "$INSTDIR\${APP_EXECUTABLE_FILENAME}" + +# must be called before uninstallOldVersion +!insertmacro setLinkVars + +!ifdef ONE_CLICK + !ifdef HEADER_ICO + File /oname=$PLUGINSDIR\installerHeaderico.ico "${HEADER_ICO}" + !endif + ${IfNot} ${Silent} + !ifdef HEADER_ICO + SpiderBanner::Show /MODERN /ICON "$PLUGINSDIR\installerHeaderico.ico" + !else + SpiderBanner::Show /MODERN + !endif + + FindWindow $0 "#32770" "" $hwndparent + FindWindow $0 "#32770" "" $hwndparent $0 + GetDlgItem $0 $0 1000 + SendMessage $0 ${WM_SETTEXT} 0 "STR:$(installing)" + + StrCpy $1 $hwndparent + System::Call 'user32::ShutdownBlockReasonCreate(${SYSTYPE_PTR}r1, w "$(installing)")' + ${endif} + !insertmacro CHECK_APP_RUNNING +!else + ${ifNot} ${UAC_IsInnerInstance} + !insertmacro CHECK_APP_RUNNING + ${endif} +!endif + +Var /GLOBAL keepShortcuts +StrCpy $keepShortcuts "false" +!insertMacro setIsTryToKeepShortcuts +${if} $isTryToKeepShortcuts == "true" + ReadRegStr $R1 SHELL_CONTEXT "${INSTALL_REGISTRY_KEY}" KeepShortcuts + + ${if} $R1 == "true" + ${andIf} ${FileExists} "$appExe" + StrCpy $keepShortcuts "true" + ${endIf} +${endif} + +!insertmacro uninstallOldVersion SHELL_CONTEXT +!insertmacro handleUninstallResult SHELL_CONTEXT + +${if} $installMode == "all" + !insertmacro uninstallOldVersion HKEY_CURRENT_USER + !insertmacro handleUninstallResult HKEY_CURRENT_USER +${endIf} + +SetOutPath $INSTDIR + +!ifdef UNINSTALLER_ICON + File /oname=uninstallerIcon.ico "${UNINSTALLER_ICON}" +!endif + +!insertmacro installApplicationFiles +!insertmacro registryAddInstallInfo +!insertmacro addStartMenuLink $keepShortcuts +!insertmacro addDesktopLink $keepShortcuts + +${if} ${FileExists} "$newStartMenuLink" + StrCpy $launchLink "$newStartMenuLink" +${else} + StrCpy $launchLink "$INSTDIR\${APP_EXECUTABLE_FILENAME}" +${endIf} + +!ifmacrodef registerFileAssociations + !insertmacro registerFileAssociations +!endif + +!ifmacrodef customInstall + !insertmacro customInstall +!endif + +!macro doStartApp + # otherwise app window will be in background + HideWindow + !insertmacro StartApp +!macroend + +!ifdef ONE_CLICK + # https://github.com/electron-userland/electron-builder/pull/3093#issuecomment-403734568 + !ifdef RUN_AFTER_FINISH + ${ifNot} ${Silent} + ${orIf} ${isForceRun} + !insertmacro doStartApp + ${endIf} + !else + ${if} ${isForceRun} + !insertmacro doStartApp + ${endIf} + !endif + !insertmacro quitSuccess +!else + # for assisted installer run only if silent, because assisted installer has run after finish option + ${if} ${isForceRun} + ${andIf} ${Silent} + !insertmacro doStartApp + ${endIf} +!endif diff --git a/static/installer.nsh b/static/installer.nsh new file mode 100644 index 0000000..870f7ac --- /dev/null +++ b/static/installer.nsh @@ -0,0 +1,4 @@ +!macro customHeader + ShowInstDetails show + ShowUninstDetails show +!macroend \ No newline at end of file