Skip to content

Commit d307c21

Browse files
authored
fix(nsis): retry closing the app until success (#5902)
Do not continue installation while the app is running. If app cannot be quit forcibly - ask user to close it manually and retry the app check in the loop until success.
1 parent 16e7ddd commit d307c21

File tree

2 files changed

+29
-9
lines changed

2 files changed

+29
-9
lines changed

packages/app-builder-lib/templates/nsis/include/allowOnlyOneInstallerInstance.nsh

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,34 @@
6262
# to ensure that files are not "in-use"
6363
Sleep 300
6464

65-
${nsProcess::FindProcess} "${APP_EXECUTABLE_FILENAME}" $R0
66-
${if} $R0 == 0
67-
# wait to give a chance to exit gracefully
68-
Sleep 1000
69-
nsExec::Exec `taskkill /f /im "${APP_EXECUTABLE_FILENAME}" /fi "PID ne $pid"` $R0
70-
${If} $R0 != 0
71-
DetailPrint `Waiting for "${PRODUCT_NAME}" to close (taskkill exit code $R0).`
72-
Sleep 2000
65+
# Retry counter
66+
StrCpy $R1 0
67+
68+
loop:
69+
IntOp $R1 $R1 + 1
70+
71+
${nsProcess::FindProcess} "${APP_EXECUTABLE_FILENAME}" $R0
72+
${if} $R0 == 0
73+
# wait to give a chance to exit gracefully
74+
Sleep 1000
75+
nsExec::Exec `taskkill /f /im "${APP_EXECUTABLE_FILENAME}" /fi "PID ne $pid"` $R0
76+
${If} $R0 != 0
77+
DetailPrint `Waiting for "${PRODUCT_NAME}" to close (taskkill exit code $R0).`
78+
Sleep 2000
79+
${endIf}
80+
${else}
81+
Goto not_running
7382
${endIf}
74-
${endIf}
83+
84+
# App likely running with elevated permissions.
85+
# Ask user to close it manually
86+
${if} $R1 > 1
87+
MessageBox MB_RETRYCANCEL|MB_ICONEXCLAMATION "$(appCannotBeClosed)" /SD IDCANCEL IDRETRY loop
88+
Quit
89+
${else}
90+
Goto loop
91+
${endIf}
92+
not_running:
7593
${endIf}
7694
${endIf}
7795
!macroend

packages/app-builder-lib/templates/nsis/messages.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ appRunning:
6666
fi: "${PRODUCT_NAME} on käynnissä. Napsauta OK sulkeaksesi sen."
6767
es: "${PRODUCT_NAME} se está ejecutando. Haz clic en Aceptar para cerrarlo."
6868
da: "${PRODUCT_NAME} er i gang. Klik OK for at lukke."
69+
appCannotBeClosed:
70+
en: "${PRODUCT_NAME} cannot be closed. \nPlease close it manually and click Retry to continue"
6971
installing:
7072
en: Installing, please wait...
7173
de: Installation läuft, bitte warten...

0 commit comments

Comments
 (0)