Electron updater (#2817)

* Add autoUpdater

* Fix electron auto updater

* Remove unused dependency

* Remove unused async in createWindow function

* fix yarn.lock

* Move updater and createWindow into single func

* Add dialogs

* Reconcile package.json with master.

* Reorder imports.

* Add toggle to control the autoupdate feature.

* Apply suggestions from code review

Co-authored-by: Jaco Greeff <jacogr@gmail.com>

* Fix linting errors.

* Remove eslint-disables

* yarn.lock

Co-authored-by: Krzysztof Jelski <krzysztof@ethworks.io>
Co-authored-by: Jaco Greeff <jacogr@gmail.com>
Co-authored-by: Krzysztof Jelski <kjelski@gmail.com>
This commit is contained in:
Jakub Jóźwiak 2020-06-01 17:55:11 +02:00 committed by GitHub
parent cb0b0c8130
commit a7e2a3b313
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 92 additions and 5 deletions

View File

@ -6,7 +6,8 @@
"dependencies": {
"@babel/polyfill": "^7.10.1",
"@polkadot/dev": "^0.55.6",
"@polkadot/react-components": "0.44.0-beta.35"
"@polkadot/react-components": "0.44.0-beta.35",
"electron-updater": "^4.3.1"
},
"devDependencies": {
"@types/react": "^16.9.35",

View File

@ -2,10 +2,13 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { BrowserWindow, app, screen } from 'electron';
import { app, BrowserWindow, dialog, screen } from 'electron';
import { autoUpdater } from 'electron-updater';
import path from 'path';
import { features } from './featureToggles';
const environment = process.env.NODE_ENV || 'production';
const ENV = process.env.NODE_ENV || 'production';
const isDev = ENV === 'development';
function createWindow (): Promise<unknown> {
const { height, width } = screen.getPrimaryDisplay().workAreaSize;
@ -19,7 +22,7 @@ function createWindow (): Promise<unknown> {
width
});
if (environment === 'development') {
if (isDev) {
win.webContents.openDevTools();
return win.loadURL('http://0.0.0.0:3000/');
@ -30,4 +33,31 @@ function createWindow (): Promise<unknown> {
return win.loadFile(mainFilePath);
}
app.whenReady().then(createWindow).catch(console.error);
const onReady = async () => {
await createWindow();
if (features.autoUpdater) {
await autoUpdater.checkForUpdatesAndNotify();
}
};
app.whenReady().then(onReady).catch(console.error);
if (features.autoUpdater) {
autoUpdater.on('update-not-available', () => {
dialog.showMessageBox({
message: 'Current version is up-to-date.',
title: 'No Updates'
}).catch(console.error);
});
autoUpdater.on('error', (error) => {
if (!error) {
return;
}
const err: Error = error as Error;
dialog.showErrorBox('Auto update error: ', (err.stack || err).toString());
});
}

View File

@ -0,0 +1,11 @@
// Copyright 2017-2020 @polkadot/apps authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
function getBoolEnv (env: string | undefined, fallback: boolean) {
return env ? (env) !== 'false' : fallback;
}
export const features = {
autoUpdater: getBoolEnv(process.env.POLKADOT_APPS_FEATURE_AUTOUPDATER, false)
};

View File

@ -41,6 +41,9 @@ function createWebpack () {
filename: 'electron.js',
path: path.join(__dirname, '/build')
},
resolve: {
extensions: ['.js', '.jsx', '.json', '.ts', '.tsx']
},
target: 'electron-main'
}
];

View File

@ -3220,6 +3220,7 @@ __metadata:
"@types/react-dom": ^16.9.8
babel-loader: ^8.1.0
copy-webpack-plugin: ^5.1.1
electron-updater: ^4.3.1
html-webpack-plugin: ^4.3.0
react: ^16.13.1
react-dom: ^16.13.1
@ -4224,6 +4225,15 @@ __metadata:
languageName: node
linkType: hard
"@types/semver@npm:^7.2.0":
version: 7.2.0
resolution: "@types/semver@npm:7.2.0"
dependencies:
"@types/node": "*"
checksum: 3/f72d56e80bc382e16e20e2370be4dc1d776fb67db91afcb88f7069f57450f8f1b282075d33ccb23d2455881c2e4279f31cd69e3d2f6f5f75d58a0d510e48bb6f
languageName: node
linkType: hard
"@types/source-list-map@npm:*":
version: 0.1.2
resolution: "@types/source-list-map@npm:0.1.2"
@ -6495,6 +6505,16 @@ __metadata:
languageName: node
linkType: hard
"builder-util-runtime@npm:8.7.0":
version: 8.7.0
resolution: "builder-util-runtime@npm:8.7.0"
dependencies:
debug: ^4.1.1
sax: ^1.2.4
checksum: 3/acaef149866a840c134029ad9b6fa5acfae3398d3a5eabac34dc34a75e211b17dada89ebde6aec73885c813a1779c5b114a5638e93695bcfd2a5b3bc56e4574a
languageName: node
linkType: hard
"builder-util-runtime@npm:8.7.1":
version: 8.7.1
resolution: "builder-util-runtime@npm:8.7.1"
@ -9452,6 +9472,21 @@ __metadata:
languageName: node
linkType: hard
"electron-updater@npm:^4.3.1":
version: 4.3.2
resolution: "electron-updater@npm:4.3.2"
dependencies:
"@types/semver": ^7.2.0
builder-util-runtime: 8.7.0
fs-extra: ^9.0.0
js-yaml: ^3.13.1
lazy-val: ^1.0.4
lodash.isequal: ^4.5.0
semver: ^7.3.2
checksum: 3/b0fefb08ead43139b56ad9e18f5c951e14e99e9a6798a315218db24b47263bf68ee30873e22d510215abe130f993b14f9cf648f95218095b853400be08c6a852
languageName: node
linkType: hard
"electron@npm:8.3.0":
version: 8.3.0
resolution: "electron@npm:8.3.0"
@ -15081,6 +15116,13 @@ __metadata:
languageName: node
linkType: hard
"lodash.isequal@npm:^4.5.0":
version: 4.5.0
resolution: "lodash.isequal@npm:4.5.0"
checksum: 3/5b47e094641c18a915497343894c66f7da6aebb9aaa2a3fcc5643455aaf29d19df60ebbed664c8374fb959c8b4ce96810ee6becd8a71ac58c6c2ca8d29762947
languageName: node
linkType: hard
"lodash.ismatch@npm:^4.4.0":
version: 4.4.0
resolution: "lodash.ismatch@npm:4.4.0"