diff --git a/packaging/windows/farmcontrol.nsi b/packaging/windows/farmcontrol.nsi index 2bbd8c6..2b8d1f6 100644 --- a/packaging/windows/farmcontrol.nsi +++ b/packaging/windows/farmcontrol.nsi @@ -67,7 +67,7 @@ Function .onInit !insertmacro progressPhase "Starting installation" !insertmacro progressStatus "Starting Farm Control installation..." !insertmacro progressCopyTotal "${APP_COPY_TOTAL_BYTES}" - !insertmacro progressPercent 0 + !insertmacro progressStart ; In-app updates install into Farm Control.new while the running process ; keeps using Farm Control; the folders are swapped after exit (/RESTARTFC). @@ -78,6 +78,8 @@ Function .onInit StrCpy $FinalInstDir $INSTDIR !insertmacro uninstallPreviousFarmControl ${EndIf} + + !insertmacro progressPrepare FunctionEnd Function .onInstFailed @@ -93,17 +95,17 @@ Section "Farm Control" SecMain !insertmacro progressPhase "Copying application files" !insertmacro progressStatus "Copying application files..." - !insertmacro progressPercent 0 + !insertmacro progressCopyStart SetOverwrite try !insertmacro copyApplicationFilesWithProgress - !insertmacro progressPercent 75 + !insertmacro progressCopyComplete !insertmacro customInstall + !insertmacro progressFinalizeInstall !insertmacro progressPhase "Finalizing installation" - !insertmacro progressStatus "Writing uninstall information..." - !insertmacro progressPercent 90 + !insertmacro progressStatus "Writing installation registry entries..." WriteRegStr HKCU "Software\Tom Butcher\Farm Control" "InstallDir" $FinalInstDir WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\Farm Control" \ @@ -119,8 +121,14 @@ Section "Farm Control" SecMain WriteRegDWORD HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\Farm Control" \ "NoRepair" 1 + !insertmacro progressWriteUninstaller + !insertmacro progressStatus "Writing uninstall information..." + WriteUninstaller "$INSTDIR\Uninstall.exe" + !insertmacro progressFinalize + + ; For in-app updates (/RESTARTFC) the success signal is emitted from ; restartFarmControlAfterUpdate, right before the install directory swap, ; so the running app quits while this installer stays alive. diff --git a/packaging/windows/installer.nsh b/packaging/windows/installer.nsh index 57d5d10..4e273ea 100644 --- a/packaging/windows/installer.nsh +++ b/packaging/windows/installer.nsh @@ -95,10 +95,56 @@ Var UpdateParentPid ${EndIf} !macroend +!define PROGRESS_START 1 +!define PREPARE_PROGRESS 3 +!define COPY_PROGRESS_START 5 +!define COPY_PROGRESS_END 90 +!define CONFIGURE_PROGRESS 91 +!define SHORTCUTS_PROGRESS 93 +!define FINALIZE_PROGRESS 95 +!define UNINSTALLER_PROGRESS 97 +!define COMPLETE_PROGRESS 99 + !macro progressPercent percent !insertmacro progressLog "installer:%${percent}" !macroend +!macro progressStart + !insertmacro progressPercent "${PROGRESS_START}" +!macroend + +!macro progressPrepare + !insertmacro progressPercent "${PREPARE_PROGRESS}" +!macroend + +!macro progressCopyStart + !insertmacro progressPercent "${COPY_PROGRESS_START}" +!macroend + +!macro progressCopyComplete + !insertmacro progressPercent "${COPY_PROGRESS_END}" +!macroend + +!macro progressConfigure + !insertmacro progressPercent "${CONFIGURE_PROGRESS}" +!macroend + +!macro progressShortcuts + !insertmacro progressPercent "${SHORTCUTS_PROGRESS}" +!macroend + +!macro progressFinalizeInstall + !insertmacro progressPercent "${FINALIZE_PROGRESS}" +!macroend + +!macro progressWriteUninstaller + !insertmacro progressPercent "${UNINSTALLER_PROGRESS}" +!macroend + +!macro progressFinalize + !insertmacro progressPercent "${COMPLETE_PROGRESS}" +!macroend + !macro progressPhase phase !insertmacro progressLog "installer:PHASE:${phase}" !macroend @@ -302,6 +348,7 @@ Var UpdateParentPid !macroend !macro customInstall + !insertmacro progressConfigure !insertmacro progressPhase "Configuring Farm Control" !insertmacro progressStatus "Registering farmcontrol URI handler..." DetailPrint "Register farmcontrol URI Handler" @@ -313,6 +360,7 @@ Var UpdateParentPid WriteRegStr HKCU "Software\Classes\farmcontrol\shell\Open" "" "" WriteRegStr HKCU "Software\Classes\farmcontrol\shell\Open\command" "" '"$FinalInstDir\bin\bun.exe" "$FinalInstDir\bin\deeplink.js" "%1"' + !insertmacro progressShortcuts !insertmacro progressStatus "Creating shortcuts..." DetailPrint "Creating shortcuts" !insertmacro createDesktopShortcut diff --git a/src/desktop/winappupdate.js b/src/desktop/winappupdate.js index d62da27..e725fe2 100644 --- a/src/desktop/winappupdate.js +++ b/src/desktop/winappupdate.js @@ -4,7 +4,9 @@ import os from 'os' import path from 'path' const PE_MZ_HEADER = Buffer.from([0x4d, 0x5a]) // "MZ" -const COPY_PROGRESS_PERCENT = 75 +const COPY_PROGRESS_START = 5 +const COPY_PROGRESS_END = 90 +const COPY_PROGRESS_RANGE = COPY_PROGRESS_END - COPY_PROGRESS_START const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms)) @@ -54,8 +56,11 @@ const parseWindowsInstallerProgress = (output) => { copiedBytes += fileBytes if (copyTotalBytes > 0) { percent = Math.min( - COPY_PROGRESS_PERCENT, - Math.round((copiedBytes / copyTotalBytes) * COPY_PROGRESS_PERCENT) + COPY_PROGRESS_END, + COPY_PROGRESS_START + + Math.round( + (copiedBytes / copyTotalBytes) * COPY_PROGRESS_RANGE + ) ) } }