t3-code-android-nightly/patches/app-builder-lib@26.16.1.patch
Dara Adedeji 62adefa2c3
fix(desktop): Windows on ARM updates no longer hang in the installer's PowerShell check (#45719)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-30 02:08:29 -06:00

155 lines
7.5 KiB
Diff

diff --git a/out/targets/nsis/NsisTarget.js b/out/targets/nsis/NsisTarget.js
index 8a3462b185b078a260483635e6d774e2ece6e269..105778c145ab63a26444179215c643a7f22148a0 100644
--- a/out/targets/nsis/NsisTarget.js
+++ b/out/targets/nsis/NsisTarget.js
@@ -366,7 +366,9 @@ class NsisTarget extends core_1.Target {
await this.executeMakensis(defines, commands, sharedHeader + (await this.computeFinalScript(script, false, archs)));
// http://forums.winamp.com/showthread.php?p=3078545
// TODO: remove workaround when wine is fully upgraded to 11
- if ((0, macosVersion_1.isMacOsCatalina)()) {
+ // T3 Code builds Windows installers on Linux without wine; read the
+ // uninstaller out of the stub the way macOS hosts already do.
+ if ((0, macosVersion_1.isMacOsCatalina)() || process.platform === "linux") {
try {
await nsisUtil_1.UninstallerReader.exec(installerPath, uninstallerPath);
}
diff --git a/templates/nsis/include/allowOnlyOneInstallerInstance.nsh b/templates/nsis/include/allowOnlyOneInstallerInstance.nsh
index 7d08e55f5ddf70e51ebd965803d001561bca6d71..d26a9ddd9e3496f60f44d466aab7385872aa65d2 100644
--- a/templates/nsis/include/allowOnlyOneInstallerInstance.nsh
+++ b/templates/nsis/include/allowOnlyOneInstallerInstance.nsh
@@ -2,6 +2,9 @@
!include "nsProcess.nsh"
!endif
+# Every PowerShell call is bounded: a hung one would hold the single-instance mutex forever.
+!define /ifndef POWERSHELL_TIMEOUT_MS 30000
+
!ifmacrondef customCheckAppRunning
!include "getProcessInfo.nsh"
Var pid
@@ -34,6 +37,12 @@
Var /GLOBAL PowerShellPath
StrCpy $CmdPath "$SYSDIR\cmd.exe"
StrCpy $PowerShellPath "$SYSDIR\WindowsPowerShell\v1.0\powershell.exe"
+ # NSIS binaries are x86, so on ARM64 $SYSDIR is SysWOW64. Its emulated PowerShell
+ # can spin forever in Get-CimInstance; run the native one instead.
+ ${if} ${IsNativeARM64}
+ ${andIf} ${FileExists} "$WINDIR\Sysnative\WindowsPowerShell\v1.0\powershell.exe"
+ StrCpy $PowerShellPath "$WINDIR\Sysnative\WindowsPowerShell\v1.0\powershell.exe"
+ ${endIf}
!ifmacrodef customCheckAppRunning
!insertmacro customCheckAppRunning
!else
@@ -45,12 +54,12 @@
!macro IS_POWERSHELL_AVAILABLE
Var /GLOBAL IsPowerShellAvailable ; 0 = available, 1 = not available
# Try running PowerShell with a simple command to check if it's available
- nsExec::Exec `"$PowerShellPath" -NoProfile -NonInteractive -C "if (Get-Command Get-CimInstance -ErrorAction SilentlyContinue) { exit 0 } else { exit 1 }"`
+ nsExec::Exec /TIMEOUT=${POWERSHELL_TIMEOUT_MS} `"$PowerShellPath" -NoProfile -NonInteractive -C "if (Get-Command Get-CimInstance -ErrorAction SilentlyContinue) { exit 0 } else { exit 1 }"`
Pop $0 # Return code (0 = success, other = error)
${if} $0 == 0
# PowerShell is available, check if it's not blocked by policies
- nsExec::Exec `"$PowerShellPath" -NoProfile -NonInteractive -C "if ((Get-ExecutionPolicy -Scope Process) -eq 'Restricted') { exit 1 } else { exit 0 }"`
+ nsExec::Exec /TIMEOUT=${POWERSHELL_TIMEOUT_MS} `"$PowerShellPath" -NoProfile -NonInteractive -C "if ((Get-ExecutionPolicy -Scope Process) -eq 'Restricted') { exit 1 } else { exit 0 }"`
Pop $0
${endIf}
@@ -63,9 +72,13 @@
!macro FIND_PROCESS _FILE _RETURN
${if} $IsPowerShellAvailable == 0
- nsExec::Exec `"$PowerShellPath" -NoProfile -NonInteractive -C "if ((Get-CimInstance -ClassName Win32_Process | ? {$$_.Path -and $$_.Path.StartsWith('$INSTDIR', 'CurrentCultureIgnoreCase')}).Count -gt 0) { exit 0 } else { exit 1 }"`
+ nsExec::Exec /TIMEOUT=${POWERSHELL_TIMEOUT_MS} `"$PowerShellPath" -NoProfile -NonInteractive -C "if ((Get-CimInstance -ClassName Win32_Process | ? {$$_.Path -and $$_.Path.StartsWith('$INSTDIR', 'CurrentCultureIgnoreCase')}).Count -gt 0) { exit 0 } else { exit 1 }"`
Pop ${_RETURN}
- ${else}
+ ${if} ${_RETURN} == "timeout"
+ StrCpy $IsPowerShellAvailable 1
+ ${endIf}
+ ${endIf}
+ ${if} $IsPowerShellAvailable != 0
!ifdef INSTALL_MODE_PER_ALL_USERS
# exact match via findstr anchored to the start of each CSV line
nsExec::Exec `"$CmdPath" /C tasklist /FI "IMAGENAME eq ${_FILE}" /FO CSV /NH | "$SYSDIR\findstr.exe" /B /I /C:"\"${_FILE}\""`
@@ -91,7 +104,7 @@
${endIf}
${if} $IsPowerShellAvailable == 0
- nsExec::Exec `"$PowerShellPath" -NoProfile -NonInteractive -C "Get-CimInstance -ClassName Win32_Process | ? {$$_.Path -and $$_.Path.StartsWith('$INSTDIR', 'CurrentCultureIgnoreCase')} | % { Stop-Process -Id $$_.ProcessId $0 }"`
+ nsExec::Exec /TIMEOUT=${POWERSHELL_TIMEOUT_MS} `"$PowerShellPath" -NoProfile -NonInteractive -C "Get-CimInstance -ClassName Win32_Process | ? {$$_.Path -and $$_.Path.StartsWith('$INSTDIR', 'CurrentCultureIgnoreCase')} | % { Stop-Process -Id $$_.ProcessId $0 }"`
${else}
!ifdef INSTALL_MODE_PER_ALL_USERS
nsExec::Exec `taskkill /IM "${_FILE}" /FI "PID ne $pid"`
@@ -103,6 +116,9 @@
!macroend
!macro _CHECK_APP_RUNNING
+ Var /GLOBAL appRunningMessage
+ Var /GLOBAL appClosingMessage
+ Var /GLOBAL appCannotBeClosedMessage
${GetProcessInfo} 0 $pid $1 $2 $3 $4
${if} $3 != "${APP_EXECUTABLE_FILENAME}"
${if} ${isUpdated}
@@ -112,17 +128,23 @@
!insertmacro FIND_PROCESS "${APP_EXECUTABLE_FILENAME}" $R0
${if} $R0 == 0
+ StrCpy $appRunningMessage "$(appRunning)"
+ StrCpy $appClosingMessage "$(appClosing)"
+ StrCpy $appCannotBeClosedMessage "$(appCannotBeClosed)"
+ !ifmacrodef customAppRunningMessages
+ !insertmacro customAppRunningMessages
+ !endif
${if} ${isUpdated}
# allow app to exit without explicit kill
Sleep 1000
Goto doStopProcess
${endIf}
- MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION "$(appRunning)" /SD IDOK IDOK doStopProcess
+ MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION "$appRunningMessage" /SD IDOK IDOK doStopProcess
Quit
doStopProcess:
- DetailPrint "$(appClosing)"
+ DetailPrint "$appClosingMessage"
!insertmacro KILL_PROCESS "${APP_EXECUTABLE_FILENAME}" 0
# to ensure that files are not "in-use"
@@ -153,7 +175,7 @@
# App likely running with elevated permissions.
# Ask user to close it manually
${if} $R1 > 1
- MessageBox MB_RETRYCANCEL|MB_ICONEXCLAMATION "$(appCannotBeClosed)" /SD IDCANCEL IDRETRY loop
+ MessageBox MB_RETRYCANCEL|MB_ICONEXCLAMATION "$appCannotBeClosedMessage" /SD IDCANCEL IDRETRY loop
Quit
${else}
Goto loop
diff --git a/templates/nsis/installSection.nsh b/templates/nsis/installSection.nsh
index 053772f55ca6ece52f0a34c4fa0f05c9a5f07bd2..3f603a3719be36ed3a9fb96bb2f3aacea54352ff 100644
--- a/templates/nsis/installSection.nsh
+++ b/templates/nsis/installSection.nsh
@@ -49,6 +49,12 @@ ${if} $isTryToKeepShortcuts == "true"
${endIf}
${endif}
+# An installed uninstaller from before the ARM64 fix runs emulated PowerShell, which can hang in
+# Get-CimInstance. A Restricted process policy sends its app-running check to the tasklist fallback.
+${if} ${IsNativeARM64}
+ System::Call 'kernel32::SetEnvironmentVariable(t "PSExecutionPolicyPreference", t "Restricted")'
+${endIf}
+
!insertmacro uninstallOldVersion SHELL_CONTEXT
!insertmacro handleUninstallResult SHELL_CONTEXT
@@ -57,6 +63,10 @@ ${if} $installMode == "all"
!insertmacro handleUninstallResult HKEY_CURRENT_USER
${endIf}
+${if} ${IsNativeARM64}
+ System::Call 'kernel32::SetEnvironmentVariable(t "PSExecutionPolicyPreference", p 0)'
+${endIf}
+
SetOutPath $INSTDIR
!ifdef UNINSTALLER_ICON