diff --git a/app/main.dev.js b/app/main.dev.js index 7cd5e7b4..1bea9506 100644 --- a/app/main.dev.js +++ b/app/main.dev.js @@ -10,6 +10,7 @@ import { app, BrowserWindow, session } from 'electron' import { mainLog } from './utils/log' import MenuBuilder from './menu' import ZapController from './zap' +import ZapUpdater from './updater' import lnd from './lnd' // Set up a couple of timers to track the app startup progress. @@ -47,6 +48,10 @@ app.on('ready', () => { backgroundColor: '#1c1e26' }) + // Initialise the updater. + const updater = new ZapUpdater(mainWindow) + updater.init() + // Initialise the application. const zap = new ZapController(mainWindow, zapMode) zap.init() diff --git a/app/updater.js b/app/updater.js new file mode 100644 index 00000000..cb9bb714 --- /dev/null +++ b/app/updater.js @@ -0,0 +1,49 @@ +import { dialog } from 'electron' +import { autoUpdater } from 'electron-updater' +import { updaterLog } from './utils/log' + +autoUpdater.logger = updaterLog + +/** + * @class ZapController + * + * The ZapUpdater class manages the electron auto update process. + */ +class ZapUpdater { + /** + * Create a new ZapUpdater instance. + * @param {BrowserWindow} mainWindow BrowserWindow instance to interact with + */ + constructor(mainWindow) { + this.mainWindow = mainWindow + } + + init() { + autoUpdater.on('update-downloaded', () => { + const opt = { + type: 'question', + buttons: ['Install', 'Later'], + title: 'Update available', + message: 'An update is available. Restart the app and install?' + } + dialog.showMessageBox(this.mainWindow, opt, choice => { + if (choice !== 0) { + return + } + setTimeout(() => { + autoUpdater.quitAndInstall() + }, 100) + }) + }) + + this.initAutoUpdate() + } + + initAutoUpdate() { + autoUpdater.checkForUpdates() + const oneHour = 60 * 60 * 1000 + setInterval(() => autoUpdater.checkForUpdates(), oneHour) + } +} + +export default ZapUpdater diff --git a/app/utils/log.js b/app/utils/log.js index ca38f74f..80676dac 100644 --- a/app/utils/log.js +++ b/app/utils/log.js @@ -51,9 +51,10 @@ const logConfig = name => ({ } }) -// Create 2 logs for use in the app. +// Create logs for use in the app. export const mainLog = debugLogger.config(logConfig('main'))('zap') export const lndLog = debugLogger.config(logConfig('lnd '))('zap') +export const updaterLog = debugLogger.config(logConfig('updater'))('zap') let lndLogLevel = null // stored most recent log level for continuity export const lndLogGetLevel = msg => { diff --git a/package.json b/package.json index 0417115f..8fafd1c9 100644 --- a/package.json +++ b/package.json @@ -189,8 +189,9 @@ "cross-spawn": "^6.0.5", "csp-html-webpack-plugin": "^2.3.0", "css-loader": "^0.28.11", - "electron-builder": "^20.24.5", + "electron-builder": "^20.26.0", "electron-devtools-installer": "^2.2.4", + "electron-updater": "^3.0.3", "enzyme": "^2.9.1", "enzyme-to-json": "^1.5.1", "eslint": "^5.0.1", diff --git a/yarn.lock b/yarn.lock index 50b394e2..3dacca7c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -660,25 +660,56 @@ anymatch@^2.0.0: micromatch "^3.1.4" normalize-path "^2.1.1" -app-builder-bin@1.11.4: - version "1.11.4" - resolved "https://registry.yarnpkg.com/app-builder-bin/-/app-builder-bin-1.11.4.tgz#5e6fe03654e91aa5339a221b6d0811c55a09480b" +app-builder-bin@2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/app-builder-bin/-/app-builder-bin-2.0.0.tgz#bda985bee14370b254841a9982753b8f383415c5" + +app-builder-lib@20.26.0: + version "20.26.0" + resolved "https://registry.yarnpkg.com/app-builder-lib/-/app-builder-lib-20.26.0.tgz#551667e1924f43da48399703f492ca8a35666a9e" + dependencies: + "7zip-bin" "~4.0.2" + app-builder-bin "2.0.0" + async-exit-hook "^2.0.1" + bluebird-lst "^1.0.5" + builder-util "5.20.0" + builder-util-runtime "4.4.1" + chromium-pickle-js "^0.2.0" + debug "^3.1.0" + ejs "^2.6.1" + electron-osx-sign "0.4.10" + electron-publish "20.26.0" + env-paths "^1.0.0" + fs-extra-p "^4.6.1" + hosted-git-info "^2.7.1" + is-ci "^1.1.0" + isbinaryfile "^3.0.2" + js-yaml "^3.12.0" + lazy-val "^1.0.3" + minimatch "^3.0.4" + normalize-package-data "^2.4.0" + plist "^3.0.1" + read-config-file "3.1.0" + sanitize-filename "^1.6.1" + semver "^5.5.0" + sumchecker "^2.0.2" + temp-file "^3.1.3" -app-builder-lib@20.24.5, app-builder-lib@~20.24.5: - version "20.24.5" - resolved "https://registry.yarnpkg.com/app-builder-lib/-/app-builder-lib-20.24.5.tgz#f1468e9ce5db16bbdcae23148e2bc1e5183d0e4e" +app-builder-lib@~20.26.0: + version "20.26.1" + resolved "https://registry.yarnpkg.com/app-builder-lib/-/app-builder-lib-20.26.1.tgz#5165875e23436244a287594676235a25f8d15bd9" dependencies: "7zip-bin" "~4.0.2" - app-builder-bin "1.11.4" + app-builder-bin "2.0.0" async-exit-hook "^2.0.1" bluebird-lst "^1.0.5" - builder-util "5.18.1" + builder-util "5.20.1" builder-util-runtime "4.4.1" chromium-pickle-js "^0.2.0" debug "^3.1.0" ejs "^2.6.1" electron-osx-sign "0.4.10" - electron-publish "20.24.2" + electron-publish "20.26.0" env-paths "^1.0.0" fs-extra-p "^4.6.1" hosted-git-info "^2.7.1" @@ -2326,7 +2357,7 @@ buffers@~0.1.1: version "0.1.1" resolved "https://registry.yarnpkg.com/buffers/-/buffers-0.1.1.tgz#b24579c3bed4d6d396aeee6d9a8ae7f5482ab7bb" -builder-util-runtime@4.4.1, builder-util-runtime@^4.4.1: +builder-util-runtime@4.4.1, builder-util-runtime@^4.4.1, builder-util-runtime@~4.4.1: version "4.4.1" resolved "https://registry.yarnpkg.com/builder-util-runtime/-/builder-util-runtime-4.4.1.tgz#2770d03241e51fde46acacc7ed3ed8a9f45f02cb" dependencies: @@ -2335,12 +2366,31 @@ builder-util-runtime@4.4.1, builder-util-runtime@^4.4.1: fs-extra-p "^4.6.1" sax "^1.2.4" -builder-util@5.18.1, builder-util@~5.18.0, builder-util@~5.18.1: - version "5.18.1" - resolved "https://registry.yarnpkg.com/builder-util/-/builder-util-5.18.1.tgz#fe6d3a22a55ef8b7be38ae19a7fa9172e4e929e9" +builder-util@5.20.0: + version "5.20.0" + resolved "https://registry.yarnpkg.com/builder-util/-/builder-util-5.20.0.tgz#dadce32c57036eb9f9c6f1139a76cbc63f6d7582" + dependencies: + "7zip-bin" "~4.0.2" + app-builder-bin "2.0.0" + bluebird-lst "^1.0.5" + builder-util-runtime "^4.4.1" + chalk "^2.4.1" + debug "^3.1.0" + fs-extra-p "^4.6.1" + is-ci "^1.1.0" + js-yaml "^3.12.0" + lazy-val "^1.0.3" + semver "^5.5.0" + source-map-support "^0.5.6" + stat-mode "^0.2.2" + temp-file "^3.1.3" + +builder-util@5.20.1, builder-util@~5.20.0: + version "5.20.1" + resolved "https://registry.yarnpkg.com/builder-util/-/builder-util-5.20.1.tgz#64544def24a9fbbdc77ac0c027661bb3dbb520a2" dependencies: "7zip-bin" "~4.0.2" - app-builder-bin "1.11.4" + app-builder-bin "2.0.0" bluebird-lst "^1.0.5" builder-util-runtime "^4.4.1" chalk "^2.4.1" @@ -3697,13 +3747,13 @@ dir-glob@^2.0.0: arrify "^1.0.1" path-type "^3.0.0" -dmg-builder@5.0.3: - version "5.0.3" - resolved "https://registry.yarnpkg.com/dmg-builder/-/dmg-builder-5.0.3.tgz#0196e9b9fa422cee3cf22ff39482a779b4ef6c78" +dmg-builder@5.1.0: + version "5.1.0" + resolved "https://registry.yarnpkg.com/dmg-builder/-/dmg-builder-5.1.0.tgz#fc8528ab3b053e6e4d42087ed63f613894466271" dependencies: - app-builder-lib "~20.24.5" + app-builder-lib "~20.26.0" bluebird-lst "^1.0.5" - builder-util "~5.18.1" + builder-util "~5.20.0" fs-extra-p "^4.6.1" iconv-lite "^0.4.23" js-yaml "^3.12.0" @@ -3862,16 +3912,16 @@ ejs@~2.5.6: version "2.5.6" resolved "https://registry.yarnpkg.com/ejs/-/ejs-2.5.6.tgz#479636bfa3fe3b1debd52087f0acb204b4f19c88" -electron-builder@^20.24.5: - version "20.24.5" - resolved "https://registry.yarnpkg.com/electron-builder/-/electron-builder-20.24.5.tgz#7e256153bc41f6d21d1858d68611feaf5374b510" +electron-builder@^20.26.0: + version "20.26.0" + resolved "https://registry.yarnpkg.com/electron-builder/-/electron-builder-20.26.0.tgz#8ae1ff1b8265423a6dd6d8e904a32ab00a61e8f4" dependencies: - app-builder-lib "20.24.5" + app-builder-lib "20.26.0" bluebird-lst "^1.0.5" - builder-util "5.18.1" + builder-util "5.20.0" builder-util-runtime "4.4.1" chalk "^2.4.1" - dmg-builder "5.0.3" + dmg-builder "5.1.0" fs-extra-p "^4.6.1" is-ci "^1.1.0" lazy-val "^1.0.3" @@ -3959,12 +4009,12 @@ electron-osx-sign@0.4.10: minimist "^1.2.0" plist "^2.1.0" -electron-publish@20.24.2: - version "20.24.2" - resolved "https://registry.yarnpkg.com/electron-publish/-/electron-publish-20.24.2.tgz#ecce2f09158e9281d7423969d2a34bd62f192fb6" +electron-publish@20.26.0: + version "20.26.0" + resolved "https://registry.yarnpkg.com/electron-publish/-/electron-publish-20.26.0.tgz#406f9ccc10d09925492497cb4bee869f664a5945" dependencies: bluebird-lst "^1.0.5" - builder-util "~5.18.0" + builder-util "~5.20.0" builder-util-runtime "^4.4.1" chalk "^2.4.1" fs-extra-p "^4.6.1" @@ -3993,6 +4043,20 @@ electron-to-chromium@^1.3.50: version "1.3.51" resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.51.tgz#6a42b49daaf7f22a5b37b991daf949f34dbdb9b5" +electron-updater@^3.0.3: + version "3.0.3" + resolved "https://registry.yarnpkg.com/electron-updater/-/electron-updater-3.0.3.tgz#67f7edd578d260f9351ccd46ff23c2789c2a5a4f" + dependencies: + bluebird-lst "^1.0.5" + builder-util-runtime "~4.4.1" + electron-is-dev "^0.3.0" + fs-extra-p "^4.6.1" + js-yaml "^3.12.0" + lazy-val "^1.0.3" + lodash.isequal "^4.5.0" + semver "^5.5.0" + source-map-support "^0.5.6" + electron@^2.0.5: version "2.0.5" resolved "https://registry.yarnpkg.com/electron/-/electron-2.0.5.tgz#6045db011e2547062a36e8c5da84d4982f434fc0" @@ -7413,6 +7477,10 @@ lodash.isarray@^3.0.0: version "3.0.4" resolved "https://registry.yarnpkg.com/lodash.isarray/-/lodash.isarray-3.0.4.tgz#79e4eb88c36a8122af86f844aa9bcd851b5fbb55" +lodash.isequal@^4.5.0: + version "4.5.0" + resolved "https://registry.yarnpkg.com/lodash.isequal/-/lodash.isequal-4.5.0.tgz#415c4478f2bcc30120c22ce10ed3226f7d3e18e0" + lodash.isnil@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/lodash.isnil/-/lodash.isnil-4.0.0.tgz#49e28cd559013458c814c5479d3c663a21bfaa6c"