Revert newest upgrade changes (need more work)
This commit is contained in:
parent
534ea2aa75
commit
c086842972
2 changed files with 50 additions and 72 deletions
52
app/main.js
52
app/main.js
|
@ -1,10 +1,9 @@
|
|||
const {app, BrowserWindow, ipcMain} = require('electron');
|
||||
const {app, BrowserWindow, ipcMain, shell} = require('electron');
|
||||
const path = require('path');
|
||||
const jayson = require('jayson');
|
||||
// tree-kill has better cross-platform handling of
|
||||
// killing a process. child-process.kill was unreliable
|
||||
const kill = require('tree-kill');
|
||||
const child_process = require('child_process');
|
||||
|
||||
|
||||
let client = jayson.client.http('http://localhost:5279/lbryapi');
|
||||
|
@ -38,7 +37,7 @@ function launchDaemon() {
|
|||
executable = path.join(__dirname, 'dist', 'lbrynet-daemon');
|
||||
}
|
||||
console.log('Launching daemon: ' + executable)
|
||||
subpy = child_process.spawn(executable)
|
||||
subpy = require('child_process').spawn(executable)
|
||||
// Need to handle the data event instead of attaching to
|
||||
// process.stdout because the latter doesn't work. I believe on
|
||||
// windows it buffers stdout and we don't get any meaningful output
|
||||
|
@ -87,31 +86,6 @@ function launchDaemonIfNotRunning() {
|
|||
);
|
||||
}
|
||||
|
||||
/*
|
||||
* Last resort for killing unresponsive daemon instances.
|
||||
* Looks for any processes called "lbrynet-daemon" and
|
||||
* tries to force kill them.
|
||||
*/
|
||||
function forceKillAllDaemons() {
|
||||
console.log("Attempting to force kill any running lbrynet-daemon instances...");
|
||||
|
||||
const fgrepOut = child_process.spawnSync('pgrep', ['-x', 'lbrynet-daemon'], {encoding: 'utf8'}).stdout;
|
||||
const daemonPids = fgrepOut.split(/[^\d]+/).filter((pid) => pid);
|
||||
if (!daemonPids) {
|
||||
console.log('No lbrynet-daemon found running.');
|
||||
} else {
|
||||
console.log(`Found ${daemonPids.length} running daemon instances. Attempting to force kill...`);
|
||||
|
||||
for (const pid of daemonPids) {
|
||||
kill(pid, 'SIGKILL', (err) => {
|
||||
if (err) {
|
||||
console.log(`Failed to force kill running daemon with pid ${pid}. Error message: ${err.message}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Quit when all windows are closed.
|
||||
app.on('window-all-closed', () => {
|
||||
|
@ -148,17 +122,10 @@ function shutdownDaemon(evenIfNotStartedByApp = false) {
|
|||
console.log('Killed lbrynet-daemon process');
|
||||
});
|
||||
} else if (evenIfNotStartedByApp) {
|
||||
console.log('Stopping lbrynet-daemon, even though app did not start it');
|
||||
client.request('daemon_stop', [], (err, res) => {
|
||||
if (err) {
|
||||
// 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}');
|
||||
forceKillAllDaemons();
|
||||
}
|
||||
});
|
||||
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')
|
||||
}
|
||||
|
@ -177,10 +144,7 @@ function shutdown() {
|
|||
|
||||
function upgrade(event, installerPath) {
|
||||
app.on('quit', () => {
|
||||
// shell.openItem doesn't reliably work from the app process, so run xdg-open directly
|
||||
child_process.spawn('xdg-open', [installerPath], {
|
||||
stdio: 'ignore',
|
||||
});
|
||||
shell.openItem(installerPath);
|
||||
});
|
||||
if (win) {
|
||||
win.loadURL(`file://${__dirname}/dist/upgrade.html`);
|
||||
|
@ -196,4 +160,4 @@ function upgrade(event, installerPath) {
|
|||
|
||||
ipcMain.on('upgrade', upgrade);
|
||||
|
||||
ipcMain.on('shutdown', shutdown);
|
||||
ipcMain.on('shutdown', shutdown);
|
70
ui/js/app.js
70
ui/js/app.js
|
@ -27,7 +27,6 @@ const {download} = remote.require('electron-dl');
|
|||
const os = require('os');
|
||||
const path = require('path');
|
||||
const app = require('electron').remote.app;
|
||||
const fs = remote.require('fs');
|
||||
|
||||
|
||||
var App = React.createClass({
|
||||
|
@ -43,17 +42,6 @@ var App = React.createClass({
|
|||
_upgradeDownloadItem: null,
|
||||
_version: null,
|
||||
|
||||
getUpdateUrl: function() {
|
||||
console.log('os.platform is', os.platform());
|
||||
switch (os.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'; // should now be msi
|
||||
}
|
||||
},
|
||||
// Temporary workaround since electron-dl throws errors when you try to get the filename
|
||||
getUpgradeFilename: function() {
|
||||
if (os.platform() == 'darwin') {
|
||||
|
@ -78,6 +66,8 @@ var App = React.createClass({
|
|||
pageArgs: typeof val !== 'undefined' ? val : null,
|
||||
errorInfo: null,
|
||||
modal: null,
|
||||
updateUrl: null,
|
||||
isOldOSX: null,
|
||||
downloadProgress: null,
|
||||
downloadComplete: false,
|
||||
};
|
||||
|
@ -100,20 +90,38 @@ var App = React.createClass({
|
|||
}
|
||||
});
|
||||
|
||||
if (!sessionStorage.getItem('upgradeSkipped')) {
|
||||
lbry.checkNewVersionAvailable(({isAvailable}) => {
|
||||
if (!isAvailable) {
|
||||
return;
|
||||
lbry.checkNewVersionAvailable((isAvailable) => {
|
||||
if (!isAvailable || sessionStorage.getItem('upgradeSkipped')) {
|
||||
return;
|
||||
}
|
||||
|
||||
lbry.getVersionInfo((versionInfo) => {
|
||||
this._version = versionInfo.lbrynet_version; // temp for building upgrade filename
|
||||
|
||||
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';
|
||||
}
|
||||
|
||||
lbry.getVersionInfo((versionInfo) => {
|
||||
this._version = versionInfo.lbrynet_version;
|
||||
this.setState({
|
||||
modal: 'upgrade',
|
||||
});
|
||||
});
|
||||
this.setState({
|
||||
modal: 'upgrade',
|
||||
isOldOSX: isOldOSX,
|
||||
updateUrl: updateUrl,
|
||||
})
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
openDrawer: function() {
|
||||
sessionStorage.setItem('drawerOpen', true);
|
||||
|
@ -129,14 +137,16 @@ var App = React.createClass({
|
|||
});
|
||||
},
|
||||
handleUpgradeClicked: function() {
|
||||
// Make a new directory within temp directory so the filename is guaranteed to be available
|
||||
const dir = fs.mkdtempSync(app.getPath('temp') + require('path').sep);
|
||||
|
||||
// TODO: create a callback for onProgress and have the UI
|
||||
// show download progress
|
||||
// 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 = {
|
||||
onProgress: (p) => this.setState({downloadProgress: Math.round(p * 100)}),
|
||||
directory: dir,
|
||||
};
|
||||
download(remote.getCurrentWindow(), this.getUpdateUrl(), options)
|
||||
download(remote.getCurrentWindow(), this.state.updateUrl, options)
|
||||
.then(downloadItem => {
|
||||
/**
|
||||
* TODO: get the download path directly from the download object. It should just be
|
||||
|
@ -279,7 +289,11 @@ var App = React.createClass({
|
|||
<Modal isOpen={this.state.modal == 'upgrade'} contentLabel="Update available"
|
||||
type="confirm" confirmButtonLabel="Upgrade" abortButtonLabel="Skip"
|
||||
onConfirmed={this.handleUpgradeClicked} onAborted={this.handleSkipClicked}>
|
||||
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.</p>
|
||||
{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 isOpen={this.state.modal == 'downloading'} contentLabel="Downloading Update" type="custom">
|
||||
Downloading Update{this.state.downloadProgress ? `: ${this.state.downloadProgress}%` : null}
|
||||
|
|
Loading…
Add table
Reference in a new issue