From cadcb533995bc957f58f2625531b0fc9508f0753 Mon Sep 17 00:00:00 2001 From: Sean Yesmunt Date: Thu, 9 Jul 2020 00:01:10 -0400 Subject: [PATCH] add better logging and prevent LbryFirst from trying to start multiple times --- electron/index.js | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/electron/index.js b/electron/index.js index a7e30ba8b..4834f989c 100644 --- a/electron/index.js +++ b/electron/index.js @@ -89,45 +89,48 @@ const startDaemon = async () => { } }; +let isLbryFirstRunning = false; const startLbryFirst = async () => { - let isLbryFirstRunning = false; - console.log(`LbryFirst: Start LBRY First App`); - try { - await LbryFirst.status(); - isLbryFirstRunning = true; - console.log('LbryFirst: Already running'); - handleLbryFirstLaunched(); - } catch (e) { - console.log('status fails', e); - console.log('Starting LbryFirst'); + if (isLbryFirstRunning) { + console.log('LbryFirst already running'); + return; } - if (!isLbryFirstRunning) { - console.log('start process...'); + console.log('LbryFirst: Starting...'); + + try { lbryFirst = new LbryFirstInstance(); - lbryFirst.on('exit', () => { + lbryFirst.on('exit', e => { if (!isDev) { lbryFirst = null; + isLbryFirstRunning = false; if (!appState.isQuitting) { dialog.showErrorBox( 'LbryFirst has Exited', - 'The lbryFirst may have encountered an unexpected error, or another lbryFirst instance is already running. \n\n' + 'The lbryFirst may have encountered an unexpected error, or another lbryFirst instance is already running. \n\n', + e ); } app.quit(); } }); + } catch (e) { + console.log('LbryFirst: Failed to create new instance\n\n', e); + } - try { - await lbryFirst.launch(); - handleLbryFirstLaunched(); - } catch (e) { - console.log('e', e); - } + console.log('LbryFirst: Running...'); + + try { + await lbryFirst.launch(); + handleLbryFirstLaunched(); + } catch (e) { + isLbryFirstRunning = false; + console.log('LbryFirst: Failed to start\n', e); } }; const handleLbryFirstLaunched = () => { + isLbryFirstRunning = true; rendererWindow.webContents.send('lbry-first-launched'); };