diff --git a/package.json b/package.json index ac374797..1ab9ce4e 100644 --- a/package.json +++ b/package.json @@ -1,13 +1,17 @@ { "name": "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", "license": "BSD-2-Clause", "build": { "appId": "com.electron.ledger", "mac": { "category": "public.app-category.utilities" + }, + "linux": { + "target": "appImage" } }, "scripts": { @@ -17,6 +21,7 @@ "dist:dir": "yarn dist --dir -c.compression=store -c.mac.identity=null", "prettier": "prettier --write \"{src,webpack}/**/*.js\"", "postinstall": "bash ./scripts/postinstall.sh", + "release": "build", "flow": "flow", "lint": "eslint src webpack" }, @@ -32,6 +37,7 @@ "@ledgerhq/hw-transport-node-hid": "^1.0.8", "color": "^2.0.1", "electron-devtools-installer": "^2.2.3", + "electron-updater": "^2.18.2", "history": "^4.7.2", "i18next": "^10.2.2", "i18next-node-fs-backend": "^1.0.0", diff --git a/src/main/app.js b/src/main/app.js index 138765ea..247a4bef 100644 --- a/src/main/app.js +++ b/src/main/app.js @@ -2,16 +2,18 @@ import { app, BrowserWindow } from 'electron' // eslint-disable-line import/no-extraneous-dependencies -// Global reference to mainWindow -// Necessary to prevent win from being garbage collected +import setupAutoUpdater from './autoUpdate' + +// 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 function createMainWindow() { const window = new BrowserWindow() - // Set url for `win` - // points to `webpack-dev-server` in development - // points to `index.html` in production const url = __DEV__ ? `http://localhost:${process.env.ELECTRON_WEBPACK_WDS_PORT || ''}` : `file://${__dirname}/index.html` @@ -36,7 +38,6 @@ function createMainWindow() { return window } -// Quit application when all windows are closed app.on('window-all-closed', () => { // On macOS it is common for applications to stay open // until the user explicitly quits @@ -46,7 +47,9 @@ app.on('window-all-closed', () => { app.on('activate', () => { // On macOS it is common to re-create a window // even after all windows have been closed - if (mainWindow === null) mainWindow = createMainWindow() + if (mainWindow === null) { + mainWindow = createMainWindow() + } }) const installExtensions = async () => { @@ -64,4 +67,8 @@ app.on('ready', async () => { } mainWindow = createMainWindow() + + if (__PROD__) { + setTimeout(() => setupAutoUpdater(mainWindow), CHECK_UPDATE_TIMEOUT) + } }) diff --git a/src/main/autoUpdate.js b/src/main/autoUpdate.js new file mode 100644 index 00000000..c60e58cc --- /dev/null +++ b/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() +} diff --git a/src/renderer/initEvents.js b/src/renderer/initEvents.js index 092f3c48..36a7e893 100644 --- a/src/renderer/initEvents.js +++ b/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) => { diff --git a/yarn.lock b/yarn.lock index 27dead84..55e2f334 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1597,7 +1597,7 @@ builder-util-runtime@4.0.0: fs-extra-p "^4.5.0" 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" resolved "https://registry.yarnpkg.com/builder-util-runtime/-/builder-util-runtime-4.0.1.tgz#d8423190a21e8c7cec185d589cb0cb888cc8e731" dependencies: @@ -2685,6 +2685,10 @@ electron-download@^3.0.1: semver "^5.3.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: version "0.4.7" 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: 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: version "1.1.0" 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" 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: version "4.0.6" resolved "https://registry.yarnpkg.com/lodash.isplainobject/-/lodash.isplainobject-4.0.6.tgz#7c526a52d89b45c45cc690b88163be0497f550cb"