Skip to content

Commit

Permalink
Merge pull request #973 from lbryio/issue/298
Browse files Browse the repository at this point in the history
Do not kill an existing daemon, but check if one exists
  • Loading branch information
IGassmann authored Jan 31, 2018
2 parents d537334 + fdb074f commit 8b9144c
Show file tree
Hide file tree
Showing 4 changed files with 216 additions and 284 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
"electron-dl": "^1.6.0",
"electron-log": "^2.2.12",
"electron-publisher-s3": "^19.47.0",
"electron-updater": "^2.16.1",
"electron-updater": "^2.18.2",
"find-process": "^1.1.0",
"formik": "^0.10.4",
"from2": "^2.3.0",
"install": "^0.10.2",
Expand Down Expand Up @@ -80,7 +81,7 @@
"babel-preset-stage-2": "^6.18.0",
"devtron": "^1.4.0",
"electron": "^1.7.11",
"electron-builder": "^19.49.0",
"electron-builder": "^19.55.2",
"electron-devtools-installer": "^2.2.1",
"electron-webpack": "^1.11.0",
"eslint": "^4.13.1",
Expand Down
15 changes: 0 additions & 15 deletions src/main/Daemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,6 @@ export default class Daemon {
}

launch() {
// Kill any running daemon
if (process.platform === 'win32') {
try {
execSync('taskkill /im lbrynet-daemon.exe /t /f');
} catch (error) {
console.warn(error.message);
}
} else {
try {
execSync('pkill lbrynet-daemon');
} catch (error) {
console.warn(error.message);
}
}

console.log('Launching daemon:', Daemon.path);
this.subprocess = spawn(Daemon.path);

Expand Down
60 changes: 37 additions & 23 deletions src/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Module imports
import keytar from 'keytar-prebuild';
import SemVer from 'semver';
import findProcess from 'find-process';
import url from 'url';
import https from 'https';
import { shell, app, ipcMain, dialog } from 'electron';
Expand Down Expand Up @@ -57,18 +58,22 @@ app.setAsDefaultProtocolClient('lbry');
app.setName('LBRY');

app.on('ready', async () => {
daemon = new Daemon();
daemon.on('exit', () => {
daemon = null;
if (!isQuitting) {
dialog.showErrorBox(
'Daemon has Exited',
'The daemon may have encountered an unexpected error, or another daemon instance is already running.'
);
app.quit();
}
});
daemon.launch();
const processList = await findProcess('name', 'lbrynet-daemon');
const isDaemonRunning = processList.length > 0;
if (!isDaemonRunning) {
daemon = new Daemon();
daemon.on('exit', () => {
daemon = null;
if (!isQuitting) {
dialog.showErrorBox(
'Daemon has Exited',
'The daemon may have encountered an unexpected error, or another daemon instance is already running.'
);
app.quit();
}
});
daemon.launch();
}
if (process.env.NODE_ENV === 'development') {
await installExtensions();
}
Expand All @@ -83,21 +88,30 @@ app.on('activate', () => {
if (!rendererWindow) rendererWindow = createWindow();
});

app.on('will-quit', (event) => {
if (process.platform === 'win32' && autoUpdateDownloaded && !autoUpdateAccepted && !showingAutoUpdateCloseAlert) {
app.on('will-quit', event => {
if (
process.platform === 'win32' &&
autoUpdateDownloaded &&
!autoUpdateAccepted &&
!showingAutoUpdateCloseAlert
) {
// We're on Win and have an update downloaded, but the user declined it (or closed
// the app without accepting it). Now the user is closing the app, so the new update
// will install. On Mac this is silent, but on Windows they get a confusing permission
// escalation dialog, so we show Windows users a warning dialog first.

showingAutoUpdateCloseAlert = true;
dialog.showMessageBox({
type: 'info',
title: 'LBRY Will Upgrade',
message: 'LBRY has a pending upgrade. Please select "Yes" to install it on the prompt shown after this one.',
}, () => {
app.quit();
});
dialog.showMessageBox(
{
type: 'info',
title: 'LBRY Will Upgrade',
message:
'LBRY has a pending upgrade. Please select "Yes" to install it on the prompt shown after this one.',
},
() => {
app.quit();
}
);

event.preventDefault();
return;
Expand Down Expand Up @@ -144,7 +158,7 @@ ipcMain.on('upgrade', (event, installerPath) => {

autoUpdater.on('update-downloaded', () => {
autoUpdateDownloaded = true;
})
});

ipcMain.on('autoUpdateAccepted', () => {
autoUpdateAccepted = true;
Expand Down Expand Up @@ -238,4 +252,4 @@ const isSecondInstance = app.makeSingleInstance(argv => {

if (isSecondInstance) {
app.exit();
}
}
Loading

0 comments on commit 8b9144c

Please sign in to comment.