From bd46bc18cca9618313a4624fb141de829578e24d Mon Sep 17 00:00:00 2001 From: Igor Gassmann Date: Mon, 29 Jan 2018 11:14:31 -0300 Subject: [PATCH] Check for running daemon --- src/main/index.js | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/src/main/index.js b/src/main/index.js index 965c0480e..6aeebe453 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -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'; @@ -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(); }