Browse Source

Implement auto-update

master
meriadec 7 years ago
parent
commit
5fa8ba37c0
No known key found for this signature in database GPG Key ID: 1D2FC2305E2CB399
  1. 8
      package.json
  2. 21
      src/main/app.js
  3. 24
      src/main/autoUpdate.js
  4. 20
      src/renderer/initEvents.js
  5. 24
      yarn.lock

8
package.json

@ -1,13 +1,17 @@
{ {
"name": "ledger-wallet-desktop", "name": "ledger-wallet-desktop",
"description": "Ledger Wallet Desktop", "description": "Ledger Wallet Desktop",
"version": "0.0.0", "repository": "https://github.com/meriadec/ledger-wallet-desktop-releases-DEV",
"version": "0.1.0",
"author": "Ledger", "author": "Ledger",
"license": "BSD-2-Clause", "license": "BSD-2-Clause",
"build": { "build": {
"appId": "com.electron.ledger", "appId": "com.electron.ledger",
"mac": { "mac": {
"category": "public.app-category.utilities" "category": "public.app-category.utilities"
},
"linux": {
"target": "appImage"
} }
}, },
"scripts": { "scripts": {
@ -17,6 +21,7 @@
"dist:dir": "yarn dist --dir -c.compression=store -c.mac.identity=null", "dist:dir": "yarn dist --dir -c.compression=store -c.mac.identity=null",
"prettier": "prettier --write \"{src,webpack}/**/*.js\"", "prettier": "prettier --write \"{src,webpack}/**/*.js\"",
"postinstall": "bash ./scripts/postinstall.sh", "postinstall": "bash ./scripts/postinstall.sh",
"release": "build",
"flow": "flow", "flow": "flow",
"lint": "eslint src webpack" "lint": "eslint src webpack"
}, },
@ -32,6 +37,7 @@
"@ledgerhq/hw-transport-node-hid": "^1.0.8", "@ledgerhq/hw-transport-node-hid": "^1.0.8",
"color": "^2.0.1", "color": "^2.0.1",
"electron-devtools-installer": "^2.2.3", "electron-devtools-installer": "^2.2.3",
"electron-updater": "^2.18.2",
"history": "^4.7.2", "history": "^4.7.2",
"i18next": "^10.2.2", "i18next": "^10.2.2",
"i18next-node-fs-backend": "^1.0.0", "i18next-node-fs-backend": "^1.0.0",

21
src/main/app.js

@ -2,16 +2,18 @@
import { app, BrowserWindow } from 'electron' // eslint-disable-line import/no-extraneous-dependencies import { app, BrowserWindow } from 'electron' // eslint-disable-line import/no-extraneous-dependencies
// Global reference to mainWindow import setupAutoUpdater from './autoUpdate'
// Necessary to prevent win from being garbage collected
// wait a bit before launching update check, to let js initialize on the
// renderer (listen to events...)
const CHECK_UPDATE_TIMEOUT = 1e3
// necessary to prevent win from being garbage collected
let mainWindow let mainWindow
function createMainWindow() { function createMainWindow() {
const window = new BrowserWindow() const window = new BrowserWindow()
// Set url for `win`
// points to `webpack-dev-server` in development
// points to `index.html` in production
const url = __DEV__ const url = __DEV__
? `http://localhost:${process.env.ELECTRON_WEBPACK_WDS_PORT || ''}` ? `http://localhost:${process.env.ELECTRON_WEBPACK_WDS_PORT || ''}`
: `file://${__dirname}/index.html` : `file://${__dirname}/index.html`
@ -36,7 +38,6 @@ function createMainWindow() {
return window return window
} }
// Quit application when all windows are closed
app.on('window-all-closed', () => { app.on('window-all-closed', () => {
// On macOS it is common for applications to stay open // On macOS it is common for applications to stay open
// until the user explicitly quits // until the user explicitly quits
@ -46,7 +47,9 @@ app.on('window-all-closed', () => {
app.on('activate', () => { app.on('activate', () => {
// On macOS it is common to re-create a window // On macOS it is common to re-create a window
// even after all windows have been closed // even after all windows have been closed
if (mainWindow === null) mainWindow = createMainWindow() if (mainWindow === null) {
mainWindow = createMainWindow()
}
}) })
const installExtensions = async () => { const installExtensions = async () => {
@ -64,4 +67,8 @@ app.on('ready', async () => {
} }
mainWindow = createMainWindow() mainWindow = createMainWindow()
if (__PROD__) {
setTimeout(() => setupAutoUpdater(mainWindow), CHECK_UPDATE_TIMEOUT)
}
}) })

24
src/main/autoUpdate.js

@ -0,0 +1,24 @@
// @flow
import { autoUpdater } from 'electron-updater'
type ElectronWindow = {
webContents: {
send: (string, *) => void,
},
}
export default (win: ElectronWindow) => {
function notify(type: string, data: * = null) {
win.webContents.send('msg', { type, data })
}
autoUpdater.on('checking-for-update', () => notify('updater.checking'))
autoUpdater.on('update-available', info => notify('updater.updateAvailable', info))
autoUpdater.on('update-not-available', () => notify('updater.updateNotAvailable'))
autoUpdater.on('error', err => notify('updater.error', err))
autoUpdater.on('download-progress', progress => notify('updater.downloadProgress', progress))
autoUpdater.on('update-downloaded', () => notify('updater.downloaded'))
autoUpdater.checkForUpdatesAndNotify()
}

20
src/renderer/initEvents.js

@ -44,6 +44,26 @@ export default (store: Object) => {
}, },
}, },
}, },
updater: {
checking: () => {
console.log('[UPDATER] checking for updates')
},
updateAvailable: info => {
console.log('[UPDATER] update available', info)
},
updateNotAvailable: () => {
console.log('[UPDATER] no update available')
},
error: err => {
console.log('[UPDATER] update error', err)
},
downloadProgress: progress => {
console.log('[UPDATER] download in progress...', progress.percent)
},
downloaded: () => {
console.log('[UPDATER] update downloaded')
},
},
} }
ipcRenderer.on('msg', (e: *, payload: MsgPayload) => { ipcRenderer.on('msg', (e: *, payload: MsgPayload) => {

24
yarn.lock

@ -1597,7 +1597,7 @@ builder-util-runtime@4.0.0:
fs-extra-p "^4.5.0" fs-extra-p "^4.5.0"
sax "^1.2.4" sax "^1.2.4"
builder-util-runtime@^4.0.0, builder-util-runtime@^4.0.1: builder-util-runtime@^4.0.0, builder-util-runtime@^4.0.1, builder-util-runtime@~4.0.0:
version "4.0.1" version "4.0.1"
resolved "https://registry.yarnpkg.com/builder-util-runtime/-/builder-util-runtime-4.0.1.tgz#d8423190a21e8c7cec185d589cb0cb888cc8e731" resolved "https://registry.yarnpkg.com/builder-util-runtime/-/builder-util-runtime-4.0.1.tgz#d8423190a21e8c7cec185d589cb0cb888cc8e731"
dependencies: dependencies:
@ -2685,6 +2685,10 @@ electron-download@^3.0.1:
semver "^5.3.0" semver "^5.3.0"
sumchecker "^1.2.0" sumchecker "^1.2.0"
electron-is-dev@^0.3.0:
version "0.3.0"
resolved "https://registry.yarnpkg.com/electron-is-dev/-/electron-is-dev-0.3.0.tgz#14e6fda5c68e9e4ecbeff9ccf037cbd7c05c5afe"
electron-osx-sign@0.4.7: electron-osx-sign@0.4.7:
version "0.4.7" version "0.4.7"
resolved "https://registry.yarnpkg.com/electron-osx-sign/-/electron-osx-sign-0.4.7.tgz#1d75647a82748eacd48bea70616ec83ffade3ee5" resolved "https://registry.yarnpkg.com/electron-osx-sign/-/electron-osx-sign-0.4.7.tgz#1d75647a82748eacd48bea70616ec83ffade3ee5"
@ -2732,6 +2736,20 @@ electron-to-chromium@^1.2.7, electron-to-chromium@^1.3.30:
dependencies: dependencies:
electron-releases "^2.1.0" electron-releases "^2.1.0"
electron-updater@^2.18.2:
version "2.18.2"
resolved "https://registry.yarnpkg.com/electron-updater/-/electron-updater-2.18.2.tgz#776b50389b849535425e9e2893d7943ee61e8e3f"
dependencies:
bluebird-lst "^1.0.5"
builder-util-runtime "~4.0.0"
electron-is-dev "^0.3.0"
fs-extra-p "^4.5.0"
js-yaml "^3.10.0"
lazy-val "^1.0.3"
lodash.isequal "^4.5.0"
semver "^5.4.1"
source-map-support "^0.5.0"
electron-webpack-js@~1.1.0: electron-webpack-js@~1.1.0:
version "1.1.0" version "1.1.0"
resolved "https://registry.yarnpkg.com/electron-webpack-js/-/electron-webpack-js-1.1.0.tgz#c7c1cf375f6d32638ba62f46e1bd31445b7f1018" resolved "https://registry.yarnpkg.com/electron-webpack-js/-/electron-webpack-js-1.1.0.tgz#c7c1cf375f6d32638ba62f46e1bd31445b7f1018"
@ -4754,6 +4772,10 @@ lodash.cond@^4.3.0:
version "4.5.2" version "4.5.2"
resolved "https://registry.yarnpkg.com/lodash.cond/-/lodash.cond-4.5.2.tgz#f471a1da486be60f6ab955d17115523dd1d255d5" resolved "https://registry.yarnpkg.com/lodash.cond/-/lodash.cond-4.5.2.tgz#f471a1da486be60f6ab955d17115523dd1d255d5"
lodash.isequal@^4.5.0:
version "4.5.0"
resolved "https://registry.yarnpkg.com/lodash.isequal/-/lodash.isequal-4.5.0.tgz#415c4478f2bcc30120c22ce10ed3226f7d3e18e0"
lodash.isplainobject@^4.0.6: lodash.isplainobject@^4.0.6:
version "4.0.6" version "4.0.6"
resolved "https://registry.yarnpkg.com/lodash.isplainobject/-/lodash.isplainobject-4.0.6.tgz#7c526a52d89b45c45cc690b88163be0497f550cb" resolved "https://registry.yarnpkg.com/lodash.isplainobject/-/lodash.isplainobject-4.0.6.tgz#7c526a52d89b45c45cc690b88163be0497f550cb"

Loading…
Cancel
Save