Seed Support #56

Closed
ocnios wants to merge 173 commits from master into build
Showing only changes of commit 8614276f0c - Show all commits

View file

@ -17,7 +17,7 @@ let daemonSubprocess;
// This is set to true right before we try to shut the daemon subprocess -- // 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. // if it dies when we didn't ask it to shut down, we want to alert the user.
let daemonSubprocessKillRequested = false; let daemonStopRequested = false;
// When a quit is attempted, we cancel the quit, do some preparations, then // 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. // this is set to true and app.quit() is called again to quit for real.
@ -74,8 +74,8 @@ function createWindow () {
function handleDaemonSubprocessExited() { function handleDaemonSubprocessExited() {
console.log('The daemon has exited.'); console.log('The daemon has exited.');
daemonSubprocess = null; daemonSubprocess = null;
if (!daemonSubprocessKillRequested) { if (!daemonStopRequested) {
// We didn't stop the daemon subprocess on purpose, so display a // We didn't request to stop the daemon, so display a
// warning and schedule a quit. // warning and schedule a quit.
// //
// TODO: maybe it would be better to restart the daemon? // TODO: maybe it would be better to restart the daemon?
@ -209,31 +209,27 @@ app.on('activate', () => {
// When a quit is attempted, this is called. It attempts to shutdown the daemon, // When a quit is attempted, this is called. It attempts to shutdown the daemon,
// then calls quitNow() to quit for real. // then calls quitNow() to quit for real.
function shutdownDaemonAndQuit(evenIfNotStartedByApp = false) { function shutdownDaemonAndQuit(evenIfNotStartedByApp = false) {
if (daemonSubprocess) { function doShutdown() {
console.log('Killing lbrynet-daemon process'); console.log('Asking daemon to shut down down');
daemonSubprocessKillRequested = true; daemonStopRequested = true;
kill(daemonSubprocess.pid, undefined, (err) => {
console.log('Killed lbrynet-daemon process');
quitNow();
});
} else if (evenIfNotStartedByApp) {
console.log('Stopping lbrynet-daemon, even though app did not start it');
client.request('daemon_stop', [], (err, res) => { client.request('daemon_stop', [], (err, res) => {
if (err) { if (err) {
// We could get an error because the daemon is already stopped (good) console.log(`received error when stopping lbrynet-daemon. Error message: ${err.message}\n`);
// or because it's running but not responding properly (bad). console.log('You will need to manually kill the daemon.');
// 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('Successfully stopped daemon via RPC call.') console.log('Successfully stopped daemon via RPC call.')
quitNow(); quitNow();
} }
}); });
} else { }
if (daemonSubprocess) {
doShutdown();
} else if (!evenIfNotStartedByApp) {
console.log('Not killing lbrynet-daemon because app did not start it'); console.log('Not killing lbrynet-daemon because app did not start it');
quitNow(); quitNow();
} else {
doShutdown();
} }
// Is it safe to start the installer before the daemon finishes running? // Is it safe to start the installer before the daemon finishes running?