Refactor Windows installer progress macros for improved clarity and functionality

- Introduced new macros for various installation progress stages, enhancing readability and maintainability of the installer script.
- Updated the progress reporting in the `farmcontrol.nsi` file to utilize the new macros, ensuring consistent progress tracking during installation.
- Adjusted the `winappupdate.js` file to align with the new progress constants, improving the accuracy of progress percentage calculations.
This commit is contained in:
Tom Butcher 2026-08-09 14:02:35 +01:00
parent 324a4a1e6f
commit ba5856c248
3 changed files with 69 additions and 8 deletions

View File

@ -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.

View File

@ -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

View File

@ -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
)
)
}
}