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 {Line} from 'rc-progress';
import lbry from './lbry.js';
import SettingsPage from './page/settings.js';
import HelpPage from './page/help.js';
@ -20,9 +22,10 @@ import Modal from './component/modal.js';
import {Link} from './component/link.js';
const remote = require('electron').remote;
const {remote, ipcRenderer} = require('electron');
const {download} = remote.require('electron-dl');
const UPDATE_URL = 'https://lbry.io/get/latest';
var App = React.createClass({
_error_key_labels: {
@ -48,8 +51,8 @@ var App = React.createClass({
pageArgs: typeof val !== 'undefined' ? val : null,
errorInfo: null,
modal: null,
updateUrl: null,
isOldOSX: null,
downloadProgress: null,
};
},
componentWillMount: function() {
@ -65,25 +68,15 @@ var App = React.createClass({
lbry.getVersionInfo((versionInfo) => {
var isOldOSX = false;
if (versionInfo.os_system == 'Darwin') {
var updateUrl = 'https://lbry.io/get/lbry.dmg';
var maj, min, patch;
[maj, min, patch] = versionInfo.lbrynet_version.split('.');
if (maj == 0 && min <= 2 && patch <= 2) {
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({
modal: 'upgrade',
isOldOSX: isOldOSX,
updateUrl: versionInfo.lbrynet_update_url,
})
});
});
@ -108,8 +101,12 @@ var App = React.createClass({
// some indication that the download is happening
// TODO: calling lbry.stop() ends up displaying the "daemon
// unexpectedly stopped" page. Have a better way of shutting down
download(remote.getCurrentWindow(), this.state.updateUrl, {saveAs: true})
.then(dl => lbry.stop())
let options = {
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() {
sessionStorage.setItem('upgradeSkipped', true);
@ -222,6 +219,11 @@ var App = React.createClass({
: null}
</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"
className="error-modal" overlayClassName="error-modal-overlay" >
<h3 className="modal__header">Error</h3>

View file

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