Improve updates download

- create progress bar modal
- trigger app shutdown on successful download
- move update url logic to the website
This commit is contained in:
jobevers 2017-02-20 12:56:15 -06:00
parent 5b454a3837
commit 86351d1736
2 changed files with 17 additions and 14 deletions

View file

@ -1,4 +1,6 @@
import React from 'react'; import React from 'react';
import {Line} from 'rc-progress';
import lbry from './lbry.js'; import lbry from './lbry.js';
import SettingsPage from './page/settings.js'; import SettingsPage from './page/settings.js';
import HelpPage from './page/help.js'; import HelpPage from './page/help.js';
@ -20,9 +22,10 @@ import Modal from './component/modal.js';
import {Link} from './component/link.js'; import {Link} from './component/link.js';
const remote = require('electron').remote; const {remote, ipcRenderer} = require('electron');
const {download} = remote.require('electron-dl'); const {download} = remote.require('electron-dl');
const UPDATE_URL = 'https://lbry.io/get/latest';
var App = React.createClass({ var App = React.createClass({
_error_key_labels: { _error_key_labels: {
@ -48,8 +51,8 @@ var App = React.createClass({
pageArgs: typeof val !== 'undefined' ? val : null, pageArgs: typeof val !== 'undefined' ? val : null,
errorInfo: null, errorInfo: null,
modal: null, modal: null,
updateUrl: null,
isOldOSX: null, isOldOSX: null,
downloadProgress: null,
}; };
}, },
componentWillMount: function() { componentWillMount: function() {
@ -65,25 +68,15 @@ var App = React.createClass({
lbry.getVersionInfo((versionInfo) => { lbry.getVersionInfo((versionInfo) => {
var isOldOSX = false; var isOldOSX = false;
if (versionInfo.os_system == 'Darwin') { if (versionInfo.os_system == 'Darwin') {
var updateUrl = 'https://lbry.io/get/lbry.dmg';
var maj, min, patch; var maj, min, patch;
[maj, min, patch] = versionInfo.lbrynet_version.split('.'); [maj, min, patch] = versionInfo.lbrynet_version.split('.');
if (maj == 0 && min <= 2 && patch <= 2) { if (maj == 0 && min <= 2 && patch <= 2) {
isOldOSX = true; isOldOSX = true;
} }
} else if (versionInfo.os_system == 'Linux') {
var updateUrl = 'https://lbry.io/get/lbry.deb';
} else if (versionInfo.os_system == 'Windows') {
var updateUrl = 'https://lbry.io/get/lbry.msi';
} else {
var updateUrl = 'https://lbry.io/get';
} }
this.setState({ this.setState({
modal: 'upgrade', modal: 'upgrade',
isOldOSX: isOldOSX, isOldOSX: isOldOSX,
updateUrl: versionInfo.lbrynet_update_url,
}) })
}); });
}); });
@ -108,8 +101,12 @@ var App = React.createClass({
// some indication that the download is happening // some indication that the download is happening
// TODO: calling lbry.stop() ends up displaying the "daemon // TODO: calling lbry.stop() ends up displaying the "daemon
// unexpectedly stopped" page. Have a better way of shutting down // unexpectedly stopped" page. Have a better way of shutting down
download(remote.getCurrentWindow(), this.state.updateUrl, {saveAs: true}) let options = {
.then(dl => lbry.stop()) onProgress: (p) => this.setState({downloadProgress: Math.round(p * 100)}),
}
download(remote.getCurrentWindow(), UPDATE_URL, options)
.then(dl => ipcRenderer.send('shutdown'));
this.setState({modal: 'downloading'});
}, },
handleSkipClicked: function() { handleSkipClicked: function() {
sessionStorage.setItem('upgradeSkipped', true); sessionStorage.setItem('upgradeSkipped', true);
@ -222,6 +219,11 @@ var App = React.createClass({
: null} : null}
</Modal> </Modal>
// TODO: have color refence css color-primary
<Modal isOpen={this.state.modal == 'downloading'} contentLabel="Downloading Update" type="custom">
Downloading Update: {this.state.downloadProgress}% Complete
<Line percent={this.state.downloadProgress} strokeWidth="4"/>
</Modal>
<Modal isOpen={this.state.modal == 'error'} contentLabel="Error" type="custom" <Modal isOpen={this.state.modal == 'error'} contentLabel="Error" type="custom"
className="error-modal" overlayClassName="error-modal-overlay" > className="error-modal" overlayClassName="error-modal-overlay" >
<h3 className="modal__header">Error</h3> <h3 className="modal__header">Error</h3>

View file

@ -25,6 +25,7 @@
"clamp-js-main": "^0.11.1", "clamp-js-main": "^0.11.1",
"mediaelement": "^2.23.4", "mediaelement": "^2.23.4",
"node-sass": "^3.8.0", "node-sass": "^3.8.0",
"rc-progress": "^2.0.6",
"react": "^15.4.0", "react": "^15.4.0",
"react-dom": "^15.4.0", "react-dom": "^15.4.0",
"react-modal": "^1.5.2", "react-modal": "^1.5.2",