From 505a63d742f9f695cf2bce0198f2d96cd1114cff Mon Sep 17 00:00:00 2001 From: develar Date: Sun, 29 Jan 2017 17:18:33 +0100 Subject: [PATCH] feat(nsis): Pass --update flag to uninstaller when auto updating an application Close #1162 --- packages/electron-builder-util/package.json | 2 +- .../templates/nsis/installSection.nsh | 17 +++++++++++------ .../templates/nsis/multiUserUi.nsh | 2 +- .../templates/nsis/oneClick.nsh | 4 ++-- packages/electron-updater/package.json | 2 +- packages/electron-updater/src/AppUpdater.ts | 5 +++-- .../electron-updater/src/GenericProvider.ts | 4 +--- yarn.lock | 4 ++-- 8 files changed, 22 insertions(+), 18 deletions(-) diff --git a/packages/electron-builder-util/package.json b/packages/electron-builder-util/package.json index 9681f7bbf00..9001b6622b6 100644 --- a/packages/electron-builder-util/package.json +++ b/packages/electron-builder-util/package.json @@ -19,7 +19,7 @@ "debug": "2.6.0", "node-emoji": "^1.5.1", "electron-builder-http": "~0.0.0-semantic-release", - "source-map-support": "^0.4.10", + "source-map-support": "^0.4.11", "7zip-bin": "^2.0.4" }, "typings": "./out/electron-builder-util.d.ts" diff --git a/packages/electron-builder/templates/nsis/installSection.nsh b/packages/electron-builder/templates/nsis/installSection.nsh index 63a294c8293..ee7eeee2f4f 100644 --- a/packages/electron-builder/templates/nsis/installSection.nsh +++ b/packages/electron-builder/templates/nsis/installSection.nsh @@ -30,15 +30,20 @@ ${endif} ClearErrors - ${GetParameters} $R4 - ${GetOptions} $R4 "--delete-app-data" $R5 + ${GetParameters} $R0 + ${GetOptions} $R0 "--update" $R2 ${ifNot} ${Errors} - StrCpy $1 "--delete-app-data" - ${else} - StrCpy $1 "" + StrCpy $0 "$0 --update" + ${endif} + + ClearErrors + ${GetParameters} $R0 + ${GetOptions} $R0 "--delete-app-data" $R2 + ${ifNot} ${Errors} + StrCpy $0 "$0 --delete-app-data" ${endif} - ExecWait '"$PLUGINSDIR\old-uninstaller.exe" /S /KEEP_APP_DATA $0 $1 _?=$R1' + ExecWait '"$PLUGINSDIR\old-uninstaller.exe" /S /KEEP_APP_DATA $0 _?=$R1' ${endif} ${endif} !macroend diff --git a/packages/electron-builder/templates/nsis/multiUserUi.nsh b/packages/electron-builder/templates/nsis/multiUserUi.nsh index 2270d478c64..0beb06b89a9 100755 --- a/packages/electron-builder/templates/nsis/multiUserUi.nsh +++ b/packages/electron-builder/templates/nsis/multiUserUi.nsh @@ -198,7 +198,7 @@ Var RadioButtonLabel1 StrCpy $7 "There is a per-user installation. ($perUserInstallationFolder)$\r$\nWill uninstall." !endif ${else} - StrCpy $7 "Fresh install for current user only" + StrCpy $7 "Fresh install for current user only." ${endif} SendMessage $0 ${BCM_SETSHIELD} 0 0 ; hide SHIELD ${else} ; all users diff --git a/packages/electron-builder/templates/nsis/oneClick.nsh b/packages/electron-builder/templates/nsis/oneClick.nsh index 9732e49133c..30fd3a46605 100644 --- a/packages/electron-builder/templates/nsis/oneClick.nsh +++ b/packages/electron-builder/templates/nsis/oneClick.nsh @@ -7,9 +7,9 @@ !else ${GetParameters} $R0 ${GetOptions} $R0 "--update" $R1 - ${IfNot} ${Errors} + ${ifNot} ${Errors} ExecShell "" "$SMPROGRAMS\${PRODUCT_FILENAME}.lnk" "--updated" - ${Else} + ${else} ExecShell "" "$SMPROGRAMS\${PRODUCT_FILENAME}.lnk" ${endif} !endif diff --git a/packages/electron-updater/package.json b/packages/electron-updater/package.json index cd8a3c6b0a9..15f6112654e 100644 --- a/packages/electron-updater/package.json +++ b/packages/electron-updater/package.json @@ -16,7 +16,7 @@ "fs-extra-p": "^3.1.0", "js-yaml": "^3.7.0", "semver": "^5.3.0", - "source-map-support": "^0.4.10", + "source-map-support": "^0.4.11", "electron-builder-http": "0.0.0-semantic-release" }, "typings": "./out/electron-updater.d.ts" diff --git a/packages/electron-updater/src/AppUpdater.ts b/packages/electron-updater/src/AppUpdater.ts index e5e46098862..cbd26f3fb7d 100644 --- a/packages/electron-updater/src/AppUpdater.ts +++ b/packages/electron-updater/src/AppUpdater.ts @@ -151,7 +151,8 @@ export abstract class AppUpdater extends EventEmitter { throw new Error(`Latest version (from update server) is not valid semver version: "${latestVersion}`) } - const currentVersion = parseVersion(this.app.getVersion()) + const currentVersionString = this.app.getVersion() + const currentVersion = parseVersion(currentVersionString) if (currentVersion == null) { throw new Error(`App version is not valid semver version: "${currentVersion}`) } @@ -159,7 +160,7 @@ export abstract class AppUpdater extends EventEmitter { if (!isVersionGreaterThan(latestVersion, currentVersion)) { this.updateAvailable = false if (this.logger != null) { - this.logger.info(`Update for version ${versionInfo.version} is not available`) + this.logger.info(`Update for version ${currentVersionString} is not available (latest version: ${versionInfo.version})`) } this.emit("update-not-available") return { diff --git a/packages/electron-updater/src/GenericProvider.ts b/packages/electron-updater/src/GenericProvider.ts index 4a5f304d7ca..cc99abc87ee 100644 --- a/packages/electron-updater/src/GenericProvider.ts +++ b/packages/electron-updater/src/GenericProvider.ts @@ -22,13 +22,11 @@ export class GenericProvider extends Provider { hostname: this.baseUrl.hostname, path: `${pathname}${this.baseUrl.search || ""}`, protocol: this.baseUrl.protocol, + headers: Object.assign({"Cache-Control": "no-cache, no-store, must-revalidate"}, this.requestHeaders) } if (this.baseUrl.port != null) { options.port = parseInt(this.baseUrl.port, 10) } - if (this.requestHeaders != null) { - options.headers = this.requestHeaders - } result = await request(options) } catch (e) { diff --git a/yarn.lock b/yarn.lock index 7db0c4ed2e7..28422333b17 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1483,8 +1483,8 @@ istanbul-lib-source-maps@^1.1.0: source-map "^0.5.3" istanbul-reports@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/istanbul-reports/-/istanbul-reports-1.0.0.tgz#24b4eb2b1d29d50f103b369bd422f6e640aa0777" + version "1.0.1" + resolved "https://registry.yarnpkg.com/istanbul-reports/-/istanbul-reports-1.0.1.tgz#9a17176bc4a6cbebdae52b2f15961d52fa623fbc" dependencies: handlebars "^4.0.3"