Merge branch 'master' into fast_pages

This commit is contained in:
Jeremy Kauffman 2017-03-27 09:46:47 -04:00 committed by GitHub
commit 2a0cf1d6db
7 changed files with 200 additions and 112 deletions

View file

@ -1,5 +1,5 @@
[bumpversion] [bumpversion]
current_version = 0.9.2rc1 current_version = 0.9.2rc2
commit = True commit = True
tag = True tag = True
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)((?P<release>[a-z]+)(?P<candidate>\d+))? parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)((?P<release>[a-z]+)(?P<candidate>\d+))?

View file

@ -1,20 +1,64 @@
const {app, BrowserWindow, ipcMain, shell} = require('electron'); const {app, BrowserWindow, ipcMain} = require('electron');
const path = require('path'); const path = require('path');
const jayson = require('jayson'); const jayson = require('jayson');
// tree-kill has better cross-platform handling of // tree-kill has better cross-platform handling of
// killing a process. child-process.kill was unreliable // killing a process. child-process.kill was unreliable
const kill = require('tree-kill'); const kill = require('tree-kill');
const child_process = require('child_process');
const assert = require('assert');
let client = jayson.client.http('http://localhost:5279/lbryapi'); let client = jayson.client.http('http://localhost:5279/lbryapi');
// Keep a global reference of the window object, if you don't, the window will // Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected. // be closed automatically when the JavaScript object is garbage collected.
let win let win;
// Also keep the daemon subprocess alive // Also keep the daemon subprocess alive
let subpy let daemonSubprocess;
// set to true when the quitting sequence has started
let quitting = false;
// This is set to true right before we try to shut the daemon subprocess --
// if it dies when we didn't ask it to shut down, we want to alert the user.
let daemonSubprocessKillRequested = false;
// When a quit is attempted, we cancel the quit, do some preparations, then
// this is set to true and app.quit() is called again to quit for real.
let readyToQuit = false;
/*
* Replacement for Electron's shell.openItem. The Electron version doesn't
* reliably work from the main process, and we need to be able to run it
* when no windows are open.
*/
function openItem(fullPath) {
const subprocOptions = {
detached: true,
stdio: 'ignore',
};
let child;
if (process.platform == 'darwin') {
child = child_process.spawn('open', [fullPath], subprocOptions);
} else if (process.platform == 'linux') {
child = child_process.spawn('xdg-open', [fullPath], subprocOptions);
} else if (process.platform == 'win32') {
child = child_process.execSync('start', [fullPath], subprocOptions);
}
// Causes child process reference to be garbage collected, allowing main process to exit
child.unref();
}
function getPidsForProcessName(name) {
if (process.platform == 'windows') {
const tasklistOut = child_process.execSync('tasklist',
['/fi', `Imagename eq ${name}.exe`, '/nh'],
{encoding: 'utf8'}
).stdout;
return tasklistOut.match(/[^\n]+/g).map((line) => line.split(/\s+/)[1]); // Second column of every non-empty line
} else {
const pgrepOut = child_process.spawnSync('pgrep', ['-x', name], {encoding: 'utf8'}).stdout;
return pgrepOut.match(/\d+/g);
}
}
function createWindow () { function createWindow () {
win = new BrowserWindow({backgroundColor: '#155B4A'}) //$color-primary win = new BrowserWindow({backgroundColor: '#155B4A'}) //$color-primary
@ -26,49 +70,61 @@ function createWindow () {
}) })
}; };
function handleDaemonSubprocessExited() {
console.log('The daemon has exited.');
daemonSubprocess = null;
if (!daemonSubprocessKillRequested) {
// We didn't stop the daemon subprocess on purpose, so display a
// warning and schedule a quit.
//
// TODO: maybe it would be better to restart the daemon?
if (win) {
console.log('Did not request daemon stop, so quitting in 5 seconds.');
win.loadURL(`file://${__dirname}/dist/warning.html`);
setTimeout(quitNow, 5000);
} else {
console.log('Did not request daemon stop, so quitting.');
quitNow();
}
}
}
function launchDaemon() { function launchDaemon() {
if (subpy) { assert(!daemonSubprocess, 'Tried to launch daemon twice');
return;
}
if (process.env.LBRY_DAEMON) { if (process.env.LBRY_DAEMON) {
executable = process.env.LBRY_DAEMON; executable = process.env.LBRY_DAEMON;
} else { } else {
executable = path.join(__dirname, 'dist', 'lbrynet-daemon'); executable = path.join(__dirname, 'dist', 'lbrynet-daemon');
} }
console.log('Launching daemon: ' + executable) console.log('Launching daemon:', executable)
subpy = require('child_process').spawn(executable) daemonSubprocess = child_process.spawn(executable)
// Need to handle the data event instead of attaching to // Need to handle the data event instead of attaching to
// process.stdout because the latter doesn't work. I believe on // process.stdout because the latter doesn't work. I believe on
// windows it buffers stdout and we don't get any meaningful output // windows it buffers stdout and we don't get any meaningful output
subpy.stdout.on('data', (buf) => {console.log(String(buf).trim());}); daemonSubprocess.stdout.on('data', (buf) => {console.log(String(buf).trim());});
subpy.stderr.on('data', (buf) => {console.log(String(buf).trim());}); daemonSubprocess.stderr.on('data', (buf) => {console.log(String(buf).trim());});
subpy.on('exit', () => { daemonSubprocess.on('exit', handleDaemonSubprocessExited);
console.log('The daemon has exited. Quitting the app');
subpy = null;
if (quitting) {
// If quitting is True it means that we were expecting the daemon
// to be shutdown so we can quit right away
app.quit();
} else {
// Otherwise, this shutdown was a surprise so display a warning
// and schedule a quit
//
// TODO: maybe it would be better to restart the daemon?
win.loadURL(`file://${__dirname}/dist/warning.html`);
setTimeout(app.quit, 5000)
}
});
console.log('lbrynet daemon has launched') console.log('lbrynet daemon has launched')
} }
/*
* Quits without any preparation. When a quit is requested (either through the
* interface or through app.quit()), we abort the quit, try to shut down the daemon,
* and then call this to quit for real.
*/
function quitNow() {
readyToQuit = true;
app.quit();
}
app.on('ready', function(){ app.on('ready', function(){
launchDaemonIfNotRunning(); launchDaemonIfNotRunning();
createWindow(); createWindow();
}); });
function launchDaemonIfNotRunning() { function launchDaemonIfNotRunning() {
// Check if the daemon is already running. If we get // Check if the daemon is already running. If we get
// an error its because its not running // an error its because its not running
@ -86,6 +142,36 @@ function launchDaemonIfNotRunning() {
); );
} }
/*
* Last resort for killing unresponsive daemon instances.
* Looks for any processes called "lbrynet-daemon" and
* tries to force kill them.
*/
function forceKillAllDaemonsAndQuit() {
console.log('Attempting to force kill any running lbrynet-daemon instances...');
const daemonPids = getPidsForProcessName('lbrynet-daemon');
if (!daemonPids) {
console.log('No lbrynet-daemon found running.');
quitNow();
} else {
console.log(`Found ${daemonPids.length} running daemon instances. Attempting to force kill...`);
for (const pid of daemonPids) {
const daemonKillAttemptsComplete = 0;
kill(pid, 'SIGKILL', (err) => {
daemonKillAttemptsComplete++;
if (err) {
console.log(`Failed to force kill running daemon with pid ${pid}. Error message: ${err.message}`);
}
if (daemonKillAttemptsComplete >= daemonPids.length) {
quitNow();
}
});
}
}
}
// Quit when all windows are closed. // Quit when all windows are closed.
app.on('window-all-closed', () => { app.on('window-all-closed', () => {
@ -98,12 +184,15 @@ app.on('window-all-closed', () => {
app.on('before-quit', (event) => { app.on('before-quit', (event) => {
if (subpy == null) { if (!readyToQuit) {
return // We need to shutdown the daemon before we're ready to actually quit. This
} // event will be triggered re-entrantly once preparation is done.
event.preventDefault(); event.preventDefault();
shutdownDaemon(); shutdownDaemonAndQuit();
}) } else {
console.log('Quitting.')
}
});
app.on('activate', () => { app.on('activate', () => {
@ -112,45 +201,55 @@ app.on('activate', () => {
if (win === null) { if (win === null) {
createWindow() createWindow()
} }
}) });
// When a quit is attempted, this is called. It attempts to shutdown the daemon,
function shutdownDaemon(evenIfNotStartedByApp = false) { // then calls quitNow() to quit for real.
if (subpy) { function shutdownDaemonAndQuit(evenIfNotStartedByApp = false) {
if (daemonSubprocess) {
console.log('Killing lbrynet-daemon process'); console.log('Killing lbrynet-daemon process');
kill(subpy.pid, undefined, (err) => { kill(daemonSubprocess.pid, undefined, (err) => {
console.log('Killed lbrynet-daemon process'); console.log('Killed lbrynet-daemon process');
requestedDaemonSubprocessKilled = true;
quitNow();
}); });
} else if (evenIfNotStartedByApp) { } else if (evenIfNotStartedByApp) {
console.log('Killing lbrynet-daemon, even though app did not start it'); console.log('Stopping lbrynet-daemon, even though app did not start it');
client.request('daemon_stop', []); client.request('daemon_stop', [], (err, res) => {
// TODO: If the daemon errors or times out when we make this request, find if (err) {
// the process and force quit it. // We could get an error because the daemon is already stopped (good)
// or because it's running but not responding properly (bad).
// So try to force kill any daemons that are still running.
console.log(`received error when stopping lbrynet-daemon. Error message: ${err.message}`);
forceKillAllDaemonsAndQuit();
} else { } else {
console.log('Not killing lbrynet-daemon because app did not start it') console.log('Successfully stopped daemon via RPC call.')
quitNow();
}
});
} else {
console.log('Not killing lbrynet-daemon because app did not start it');
quitNow();
} }
// Is it safe to start the installer before the daemon finishes running? // Is it safe to start the installer before the daemon finishes running?
// If not, we should wait until the daemon is closed before we start the install. // If not, we should wait until the daemon is closed before we start the install.
} }
function shutdown() {
if (win) {
win.loadURL(`file://${__dirname}/dist/quit.html`);
}
quitting = true;
shutdownDaemon();
}
function upgrade(event, installerPath) { function upgrade(event, installerPath) {
app.on('quit', () => { app.on('quit', () => {
shell.openItem(installerPath); console.log('Launching upgrade installer at', installerPath);
// This gets triggered called after *all* other quit-related events, so
// we'll only get here if we're fully prepared and quitting for real.
openItem(installerPath);
}); });
if (win) { if (win) {
win.loadURL(`file://${__dirname}/dist/upgrade.html`); win.loadURL(`file://${__dirname}/dist/upgrade.html`);
} }
quitting = true;
shutdownDaemon(true); app.quit();
// wait for daemon to shut down before upgrading // wait for daemon to shut down before upgrading
// what to do if no shutdown in a long time? // what to do if no shutdown in a long time?
console.log('Update downloaded to', installerPath); console.log('Update downloaded to', installerPath);
@ -159,5 +258,3 @@ function upgrade(event, installerPath) {
} }
ipcMain.on('upgrade', upgrade); ipcMain.on('upgrade', upgrade);
ipcMain.on('shutdown', shutdown);

View file

@ -1,6 +1,6 @@
{ {
"name": "LBRY", "name": "LBRY",
"version": "0.9.2rc1", "version": "0.9.2rc2",
"main": "main.js", "main": "main.js",
"description": "LBRY is a fully decentralized, open-source protocol facilitating the discovery, access, and (sometimes) purchase of data.", "description": "LBRY is a fully decentralized, open-source protocol facilitating the discovery, access, and (sometimes) purchase of data.",
"author": { "author": {

2
lbry

@ -1 +1 @@
Subproject commit e8e2a0d353928f01746a275c38faf3cd8f072d28 Subproject commit b04455f9c733575b5191f1711d6d065ea5195ebb

View file

@ -24,9 +24,9 @@ import {Link} from './component/link.js';
const {remote, ipcRenderer, shell} = require('electron'); const {remote, ipcRenderer, shell} = require('electron');
const {download} = remote.require('electron-dl'); const {download} = remote.require('electron-dl');
const os = require('os');
const path = require('path'); const path = require('path');
const app = require('electron').remote.app; const app = require('electron').remote.app;
const fs = remote.require('fs');
var App = React.createClass({ var App = React.createClass({
@ -49,13 +49,30 @@ var App = React.createClass({
address: window.location.search address: window.location.search
}; };
}, },
getUpdateUrl: function() {
switch (process.platform) {
case 'darwin':
return 'https://lbry.io/get/lbry.dmg';
case 'linux':
return 'https://lbry.io/get/lbry.deb';
case 'win32':
return 'https://lbry.io/get/lbry.exe';
default:
throw 'Unknown platform';
}
},
// Hard code the filenames as a temporary workaround, because
// electron-dl throws errors when you try to get the filename
getUpgradeFilename: function() { getUpgradeFilename: function() {
if (os.platform() == 'darwin') { switch (process.platform) {
case 'darwin':
return `LBRY-${this._version}.dmg`; return `LBRY-${this._version}.dmg`;
} else if (os.platform() == 'linux') { case 'linux':
return `LBRY_${this._version}_amd64.deb`; return `LBRY_${this._version}_amd64.deb`;
} else { case 'windows':
return `LBRY.Setup.${this._version}.exe`; return `LBRY.Setup.${this._version}.exe`;
default:
throw 'Unknown platform';
} }
}, },
getViewingPageAndArgs: function(address) { getViewingPageAndArgs: function(address) {
@ -74,8 +91,6 @@ var App = React.createClass({
drawerOpen: drawerOpenRaw !== null ? JSON.parse(drawerOpenRaw) : true, drawerOpen: drawerOpenRaw !== null ? JSON.parse(drawerOpenRaw) : true,
errorInfo: null, errorInfo: null,
modal: null, modal: null,
updateUrl: null,
isOldOSX: null,
downloadProgress: null, downloadProgress: null,
downloadComplete: false, downloadComplete: false,
}); });
@ -104,38 +119,20 @@ var App = React.createClass({
} }
}); });
lbry.checkNewVersionAvailable((isAvailable) => { if (!sessionStorage.getItem('upgradeSkipped')) {
if (!isAvailable || sessionStorage.getItem('upgradeSkipped')) { lbry.checkNewVersionAvailable(({isAvailable}) => {
if (!isAvailable) {
return; return;
} }
lbry.getVersionInfo((versionInfo) => { lbry.getVersionInfo((versionInfo) => {
this._version = versionInfo.lbrynet_version; // temp for building upgrade filename this._version = versionInfo.lbrynet_version;
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.exe';
} else {
var updateUrl = 'https://lbry.io/get';
}
this.setState({ this.setState({
modal: 'upgrade', modal: 'upgrade',
isOldOSX: isOldOSX,
updateUrl: updateUrl,
})
}); });
}); });
});
}
}, },
openDrawer: function() { openDrawer: function() {
sessionStorage.setItem('drawerOpen', true); sessionStorage.setItem('drawerOpen', true);
@ -157,16 +154,14 @@ var App = React.createClass({
this._isMounted = false; this._isMounted = false;
}, },
handleUpgradeClicked: function() { handleUpgradeClicked: function() {
// TODO: create a callback for onProgress and have the UI // Make a new directory within temp directory so the filename is guaranteed to be available
// show download progress const dir = fs.mkdtempSync(app.getPath('temp') + require('path').sep);
// TODO: calling lbry.stop() ends up displaying the "daemon
// unexpectedly stopped" page. Have a better way of shutting down
let dir = app.getPath('temp');
let options = { let options = {
onProgress: (p) => this.setState({downloadProgress: Math.round(p * 100)}), onProgress: (p) => this.setState({downloadProgress: Math.round(p * 100)}),
directory: dir, directory: dir,
}; };
download(remote.getCurrentWindow(), this.state.updateUrl, options) download(remote.getCurrentWindow(), this.getUpdateUrl(), options)
.then(downloadItem => { .then(downloadItem => {
/** /**
* TODO: get the download path directly from the download object. It should just be * TODO: get the download path directly from the download object. It should just be
@ -309,11 +304,7 @@ var App = React.createClass({
<Modal isOpen={this.state.modal == 'upgrade'} contentLabel="Update available" <Modal isOpen={this.state.modal == 'upgrade'} contentLabel="Update available"
type="confirm" confirmButtonLabel="Upgrade" abortButtonLabel="Skip" type="confirm" confirmButtonLabel="Upgrade" abortButtonLabel="Skip"
onConfirmed={this.handleUpgradeClicked} onAborted={this.handleSkipClicked}> onConfirmed={this.handleUpgradeClicked} onAborted={this.handleSkipClicked}>
<p>Your version of LBRY is out of date and may be unreliable or insecure.</p> Your version of LBRY is out of date and may be unreliable or insecure.
{this.state.isOldOSX
? <p>Before installing the new version, make sure to exit LBRY. If you started the app, click the LBRY icon in your status bar and choose "Quit."</p>
: null}
</Modal> </Modal>
<Modal isOpen={this.state.modal == 'downloading'} contentLabel="Downloading Update" type="custom"> <Modal isOpen={this.state.modal == 'downloading'} contentLabel="Downloading Update" type="custom">
Downloading Update{this.state.downloadProgress ? `: ${this.state.downloadProgress}%` : null} Downloading Update{this.state.downloadProgress ? `: ${this.state.downloadProgress}%` : null}

View file

@ -91,7 +91,7 @@ var SendToAddressSection = React.createClass({
} }
}, (error) => { }, (error) => {
this.setState({ this.setState({
results: "Something went wrong: " + error.faultString + " " + error.faultCode results: "Something went wrong: " + error.message
}) })
}); });
}, },

View file

@ -1,6 +1,6 @@
{ {
"name": "lbry-web-ui", "name": "lbry-web-ui",
"version": "0.9.2rc1", "version": "0.9.2rc2",
"description": "LBRY UI", "description": "LBRY UI",
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1" "test": "echo \"Error: no test specified\" && exit 1"