From d1d53b645dd5af6d7e8829b367f3279ce51b4630 Mon Sep 17 00:00:00 2001 From: Fedor Indutny <79877362+indutny-signal@users.noreply.github.com> Date: Tue, 18 May 2021 13:48:10 -0700 Subject: [PATCH] Ensure the app is closed before installing on Windows --- .github/workflows/benchmark.yml | 2 +- .github/workflows/ci.yml | 8 ++-- patches/app-builder-lib+22.10.5.patch | 61 +++++++++++++++++++++++++++ 3 files changed, 66 insertions(+), 5 deletions(-) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index 0fb8898f1..423dbb2b0 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -40,7 +40,7 @@ jobs: uses: actions/cache@v2 with: path: node_modules - key: ${{ runner.os }}-${{ hashFiles('yarn.lock') }} + key: ${{ runner.os }}-${{ hashFiles('yarn.lock', 'patches/**') }} - name: Install Desktop node_modules if: steps.cache-desktop-modules.outputs.cache-hit != 'true' diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 482d1f84d..477317781 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,7 +22,7 @@ jobs: uses: actions/cache@v2 with: path: node_modules - key: ${{ runner.os }}-${{ hashFiles('yarn.lock') }} + key: ${{ runner.os }}-${{ hashFiles('yarn.lock', 'patches/**') }} - name: Install Desktop node_modules if: steps.cache-desktop-modules.outputs.cache-hit != 'true' run: yarn install --frozen-lockfile @@ -51,7 +51,7 @@ jobs: uses: actions/cache@v2 with: path: node_modules - key: ${{ runner.os }}-${{ hashFiles('yarn.lock') }} + key: ${{ runner.os }}-${{ hashFiles('yarn.lock', 'patches/**') }} - name: Install Desktop node_modules if: steps.cache-desktop-modules.outputs.cache-hit != 'true' run: yarn install --frozen-lockfile @@ -84,7 +84,7 @@ jobs: uses: actions/cache@v2 with: path: node_modules - key: ${{ runner.os }}-${{ hashFiles('yarn.lock') }} + key: ${{ runner.os }}-${{ hashFiles('yarn.lock', 'patches/**') }} - name: Install Desktop node_modules if: steps.cache-desktop-modules.outputs.cache-hit != 'true' run: yarn install --frozen-lockfile @@ -120,7 +120,7 @@ jobs: uses: actions/cache@v2 with: path: node_modules - key: ${{ runner.os }}-${{ hashFiles('yarn.lock') }} + key: ${{ runner.os }}-${{ hashFiles('yarn.lock') }}-${{ hashFiles('patches/**') }} - name: Install Desktop node_modules if: steps.cache-desktop-modules.outputs.cache-hit != 'true' run: yarn install --frozen-lockfile diff --git a/patches/app-builder-lib+22.10.5.patch b/patches/app-builder-lib+22.10.5.patch index cfa184a62..454eaec29 100644 --- a/patches/app-builder-lib+22.10.5.patch +++ b/patches/app-builder-lib+22.10.5.patch @@ -24,3 +24,64 @@ index 16eab30..0077182 100644 - update-mime-database /usr/share/mime || true update-desktop-database /usr/share/applications || true +diff --git a/node_modules/app-builder-lib/templates/nsis/include/allowOnlyOneInstallerInstance.nsh b/node_modules/app-builder-lib/templates/nsis/include/allowOnlyOneInstallerInstance.nsh +index b52822068..3824c785f 100644 +--- a/node_modules/app-builder-lib/templates/nsis/include/allowOnlyOneInstallerInstance.nsh ++++ b/node_modules/app-builder-lib/templates/nsis/include/allowOnlyOneInstallerInstance.nsh +@@ -62,16 +62,34 @@ + # to ensure that files are not "in-use" + Sleep 300 + +- ${nsProcess::FindProcess} "${APP_EXECUTABLE_FILENAME}" $R0 +- ${if} $R0 == 0 +- # wait to give a chance to exit gracefully +- Sleep 1000 +- nsExec::Exec `taskkill /f /im "${APP_EXECUTABLE_FILENAME}" /fi "PID ne $pid"` $R0 +- ${If} $R0 != 0 +- DetailPrint `Waiting for "${PRODUCT_NAME}" to close (taskkill exit code $R0).` +- Sleep 2000 ++ # Retry counter ++ StrCpy $R1 0 ++ ++ loop: ++ IntOp $R1 $R1 + 1 ++ ++ ${nsProcess::FindProcess} "${APP_EXECUTABLE_FILENAME}" $R0 ++ ${if} $R0 == 0 ++ # wait to give a chance to exit gracefully ++ Sleep 1000 ++ nsExec::Exec `taskkill /f /im "${APP_EXECUTABLE_FILENAME}" /fi "PID ne $pid"` $R0 ++ ${If} $R0 != 0 ++ DetailPrint `Waiting for "${PRODUCT_NAME}" to close (taskkill exit code $R0).` ++ Sleep 2000 ++ ${endIf} ++ ${else} ++ Goto not_running + ${endIf} +- ${endIf} ++ ++ # 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 ++ Quit ++ ${else} ++ Goto loop ++ ${endIf} ++ not_running: + ${endIf} + ${endIf} + !macroend +diff --git a/node_modules/app-builder-lib/templates/nsis/messages.yml b/node_modules/app-builder-lib/templates/nsis/messages.yml +index c35df3573..94c8e9e0c 100644 +--- a/node_modules/app-builder-lib/templates/nsis/messages.yml ++++ b/node_modules/app-builder-lib/templates/nsis/messages.yml +@@ -66,6 +66,8 @@ appRunning: + fi: "${PRODUCT_NAME} on käynnissä. Napsauta OK sulkeaksesi sen." + es: "${PRODUCT_NAME} se está ejecutando. Haz clic en Aceptar para cerrarlo." + da: "${PRODUCT_NAME} er i gang. Klik OK for at lukke." ++appCannotBeClosed: ++ en: "${PRODUCT_NAME} cannot be closed. \nPlease close it manually and click Retry to continue" + installing: + en: Installing, please wait... + de: Installation läuft, bitte warten...