Skip to content

Commit

Permalink
feat(nsis): Pass --update flag to uninstaller when auto updating an a…
Browse files Browse the repository at this point in the history
…pplication

Close #1162
  • Loading branch information
develar committed Jan 29, 2017
1 parent 5d72c10 commit 505a63d
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 18 deletions.
2 changes: 1 addition & 1 deletion packages/electron-builder-util/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
17 changes: 11 additions & 6 deletions packages/electron-builder/templates/nsis/installSection.nsh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/electron-builder/templates/nsis/multiUserUi.nsh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions packages/electron-builder/templates/nsis/oneClick.nsh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/electron-updater/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 3 additions & 2 deletions packages/electron-updater/src/AppUpdater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,16 @@ 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}`)
}

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 {
Expand Down
4 changes: 1 addition & 3 deletions packages/electron-updater/src/GenericProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,11 @@ export class GenericProvider extends Provider<UpdateInfo> {
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<UpdateInfo>(options)
}
catch (e) {
Expand Down
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down

0 comments on commit 505a63d

Please sign in to comment.