some progress, but needs more work

This commit is contained in:
Alex Grintsvayg 2017-03-17 18:05:25 -04:00
parent 3c2f3abe8e
commit 20064ee558
4 changed files with 64 additions and 24 deletions

View file

@ -115,16 +115,19 @@ app.on('activate', () => {
})
function shutdownDaemon() {
function shutdownDaemon(evenIfNotStartedByApp = false) {
if (subpy) {
console.log('Killing lbrynet-daemon process');
kill(subpy.pid, undefined, (err) => {
console.log('Killed lbrynet-daemon process');
});
} else {
client.request('stop', []);
} else if (evenIfNotStartedByApp) {
console.log('Killing lbrynet-daemon, even though app did not start it');
client.request('daemon_stop', []);
// TODO: If the daemon errors or times out when we make this request, find
// the process and force quit it.
} else {
console.log('Not killing lbrynet-daemon because app did not start it')
}
// Is it safe to start the installer before the daemon finishes running?
@ -132,13 +135,6 @@ function shutdownDaemon() {
}
function shutdown() {
/* if (!subpy) {
// TODO: In this case, we didn't start the process so I'm hesitant
// to shut it down. We might want to send a stop command
// though instead of just letting it run.
console.log('Not killing lbrynet daemon because we did not start it')
return
} */
if (win) {
win.loadURL(`file://${__dirname}/dist/quit.html`);
}
@ -148,15 +144,18 @@ function shutdown() {
function upgrade(event, installerPath) {
app.on('quit', () => {
console.log('installerPath is', installerPath);
shell.openItem(installerPath);
console.log('after installerPath');
});
if (win) {
win.loadURL(`file://${__dirname}/dist/upgrade.html`);
}
quitting = true;
shutdownDaemon();
shutdownDaemon(true);
// wait for daemon to shut down before upgrading
// what to do if no shutdown in a long time?
console.log('Update downloaded to ', installerPath);
console.log('The app will close, and you will be prompted to install the latest version of LBRY.');
console.log('After the install is complete, please reopen the app.');
}
ipcMain.on('upgrade', upgrade);

View file

@ -110,10 +110,7 @@ var App = React.createClass({
} else if (versionInfo.os_system == 'Linux') {
var updateUrl = 'https://lbry.io/get/lbry.deb';
} else if (versionInfo.os_system == 'Windows') {
// A little weird, but for electron, the installer is
// actually an exe. Maybe a better url would
// be something like /get/windows ?
var updateUrl = 'https://lbry.io/get/lbry.msi';
var updateUrl = 'https://lbry.io/get/lbry.exe';
} else {
var updateUrl = 'https://lbry.io/get';
}
@ -299,13 +296,21 @@ var App = React.createClass({
</Modal>
<Modal isOpen={this.state.modal == 'downloading'} contentLabel="Downloading Update" type="custom">
Downloading Update{this.state.downloadProgress ? `: ${this.state.downloadProgress}% Complete` : null}
Downloading Update{this.state.downloadProgress ? `: ${this.state.downloadProgress}%` : null}
<Line percent={this.state.downloadProgress} strokeWidth="4"/>
{this.state.downloadComplete ? (
<div>
<br />
<p>Click "Begin Upgrade" to start the upgrade process.</p>
<p>The app will close, and you will be prompted to install the latest version of LBRY.</p>
<p>After the install is complete, please reopen the app.</p>
</div>
) : null }
<div className="modal__buttons">
<Link button="alt" label="Cancel" className="modal__button" onClick={this.cancelUpgrade} />
{this.state.downloadComplete
{this.state.downloadComplete
? <Link button="primary" label="Begin Upgrade" className="modal__button" onClick={this.handleStartUpgradeClicked} />
: null}
<Link button="alt" label="Cancel" className="modal__button" onClick={this.cancelUpgrade} />
</div>
</Modal>
<ExpandableModal isOpen={this.state.modal == 'error'} contentLabel="Error" className="error-modal"

View file

@ -33,10 +33,10 @@ export const Modal = React.createClass({
{this.props.type == 'custom' // custom modals define their own buttons
? null
: <div className="modal__buttons">
{this.props.type == 'confirm'
? <Link button="alt" label={this.props.abortButtonLabel} className="modal__button" disabled={this.props.abortButtonDisabled} onClick={this.props.onAborted} />
: null}
<Link button="primary" label={this.props.confirmButtonLabel} className="modal__button" disabled={this.props.confirmButtonDisabled} onClick={this.props.onConfirmed} />
<Link button="primary" label={this.props.confirmButtonLabel} className="modal__button" disabled={this.props.confirmButtonDisabled} onClick={this.props.onConfirmed} />
{this.props.type == 'confirm'
? <Link button="alt" label={this.props.abortButtonLabel} className="modal__button" disabled={this.props.abortButtonDisabled} onClick={this.props.onAborted} />
: null}
</div>}
</ReactModal>
);

View file

@ -1,6 +1,10 @@
import lbry from '../lbry.js';
import React from 'react';
import FormField from '../component/form.js';
import {Link} from '../component/link.js';
const fs = require('fs');
const {ipcRenderer} = require('electron');
const DeveloperPage = React.createClass({
getInitialState: function() {
@ -8,6 +12,7 @@ const DeveloperPage = React.createClass({
showDeveloperMenu: lbry.getClientSetting('showDeveloperMenu'),
useCustomLighthouseServers: lbry.getClientSetting('useCustomLighthouseServers'),
customLighthouseServers: lbry.getClientSetting('customLighthouseServers').join('\n'),
upgradePath: '',
};
},
handleShowDeveloperMenuChange: function(event) {
@ -23,6 +28,30 @@ const DeveloperPage = React.createClass({
useCustomLighthouseServers: event.target.checked,
});
},
handleUpgradeFileChange: function(event) {
this.setState({
upgradePath: event.target.files[0].path,
});
},
handleForceUpgradeClick: function() {
let upgradeSent = false;
if (!this.state.upgradePath) {
alert('Please select a file to upgrade from');
} else {
try {
const stats = fs.lstatSync(this.state.upgradePath);
if (stats.isFile()) {
console.log('Starting upgrade using ' + this.state.upgradePath);
ipcRenderer.send('upgrade', this.state.upgradePath);
upgradeSent = true;
}
}
catch (e) {}
if (!upgradeSent) {
alert('Failed to start upgrade. Is "' + this.state.upgradePath.replace("C:\\fakepath\\", "") + '" a valid path to the upgrade?');
}
}
},
render: function() {
return (
<main>
@ -43,6 +72,13 @@ const DeveloperPage = React.createClass({
</div>
: null}
</section>
<section className="card">
<div className="form-row">
<FormField name="file" ref="file" type="file" onChange={this.handleUpgradeFileChange}/>
&nbsp;
<Link label="Force Upgrade" button="alt" onClick={this.handleForceUpgradeClick} />
</div>
</section>
</main>
);
}