-
Notifications
You must be signed in to change notification settings - Fork 563
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Auto format file * Replace auto-updater with electron-updater * Ignore `dev-app-update.yml` * Reset version * Format releaseNotes to markdown * Replace manual updater & refactoring * Trigger build * Fix downloadUrl * Retrigger build * Fix & in onConfirm button on Windows * Set `autoInstallOnAppQuit` to false * Update url to changelog Co-Authored-By: adlk <stefan@adlk.io> * Bring package-lock in sync * To revert: set version to 1.0.0 * Revert "To revert: set version to 1.0.0" This reverts commit 0edacd0. * Fix path * Fix changelog URL * Update electron-updater (fix macOS timing issue) * Remove appdmg as an optional dependency * Use npm ci
- Loading branch information
Showing
10 changed files
with
468 additions
and
562 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,4 @@ release/ | |
*.tgz | ||
.idea | ||
.DS_Store | ||
dev-app-update.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
const EventEmitter = require('events').EventEmitter; | ||
const { app, dialog, shell } = require('electron'); | ||
const platform = require('../../platform'); | ||
|
||
class Updater extends EventEmitter { | ||
constructor(changelogUrl, options) { | ||
super(); | ||
|
||
this.changelogUrl = changelogUrl; | ||
this.confirmLabel = options.confirmLabel || 'Update & Restart'; | ||
this.dialogTitle = | ||
options.dialogTitle || 'A new version of {name} is available!'; | ||
this.dialogMessage = | ||
options.dialogMessage || | ||
'{name} {newVersion} is now available — you have {currentVersion}. Would you like to update now?'; | ||
|
||
this._version = ''; | ||
this._hasPrompted = false; | ||
} | ||
|
||
ping() {} | ||
|
||
onDownloaded(event) { | ||
console.log('Update downloaded'); | ||
|
||
// electron-updater provides us with new version | ||
if (event.version) { | ||
this.setVersion(event.version); | ||
} | ||
|
||
this.notify(); | ||
} | ||
|
||
onNotAvailable() { | ||
console.log('Update is not available'); | ||
} | ||
|
||
onError(event) { | ||
console.log('Update error', event); | ||
} | ||
|
||
onConfirm() {} | ||
|
||
onCancel() {} | ||
|
||
onChangelog() { | ||
shell.openExternal(this.changelogUrl); | ||
} | ||
|
||
notify() { | ||
const updateDialogOptions = { | ||
buttons: [ | ||
this.sanitizeButtonLabel(this.confirmLabel), | ||
'Cancel', | ||
'Release notes', | ||
], | ||
title: 'Update Available', | ||
message: this.expandMacros(this.dialogTitle), | ||
detail: this.expandMacros(this.dialogMessage), | ||
}; | ||
|
||
if (!this._hasPrompted) { | ||
this._hasPrompted = true; | ||
|
||
dialog.showMessageBox(updateDialogOptions, button => { | ||
this._hasPrompted = false; | ||
|
||
if (button === 0) { | ||
// Confirm | ||
this.onConfirm(); | ||
} else if (button === 2) { | ||
// Open changelog | ||
this.onChangelog(); | ||
} else { | ||
this.onCancel(); | ||
} | ||
|
||
this.emit('end'); | ||
}); | ||
} | ||
} | ||
|
||
setVersion(version) { | ||
this._version = version; | ||
} | ||
|
||
expandMacros(originalText) { | ||
const macros = { | ||
name: app.getName(), | ||
currentVersion: app.getVersion(), | ||
newVersion: this._version, | ||
}; | ||
|
||
let text = originalText; | ||
|
||
for (const key in macros) { | ||
if (macros.hasOwnProperty(key)) { | ||
text = text.replace(new RegExp(`{${key}}`, 'ig'), macros[key]); | ||
} | ||
} | ||
|
||
return text; | ||
} | ||
|
||
sanitizeButtonLabel(value) { | ||
if (platform.isWindows()) { | ||
return value.replace('&', '&&'); | ||
} | ||
|
||
return value; | ||
} | ||
} | ||
|
||
module.exports = Updater; |
Oops, something went wrong.