Skip to content

Commit

Permalink
win kill (particl#310)
Browse files Browse the repository at this point in the history
* Gracefully stop daemon

* win kill
  • Loading branch information
kewde authored and rynomster committed Nov 10, 2017
1 parent 7957a17 commit 2bece4d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
21 changes: 16 additions & 5 deletions modules/rpc/daemon.js
Expand Up @@ -136,24 +136,35 @@ function getOptions() {

function stopDaemon() {
return new Promise((resolve, reject) => {
rpcCall('stop', null, null, (error, response) => {
rpc.rpcCall('stop', null, null, (error, response) => {
if (error) {
log.error('Calling SIGINT!');
reject();
} else {
log.debug('Daemon stopped gracefully');
resolve();
}
});
});
}

electron.app.on('quit', function (event, exitCode) {
console.log('stopping')
electron.app.on('before-quit', function beforeQuit(event, exitCode) {
electron.ipcMain.removeAllListeners(['rpc-channel']); // Remove all ipc listeners
// kill the particl daemon if initiated on launch

// stop the particl daemon if initiated on launch
if (daemon && !daemon.exitCode) {
event.preventDefault();
electron.app.removeListener('before-quit', beforeQuit);
stopDaemon()
.catch(() => daemon.kill('SIGINT'));
.then(electron.app.quit)
.catch(() => {
daemon.kill('SIGINT');
electron.app.quit();
});
}
});

electron.app.on('quit', function(event, exitCode) {
if (exitCode === 991) {
throw Error('Could not connect to daemon.');
}
Expand Down
3 changes: 2 additions & 1 deletion modules/rpc/rpc.js
Expand Up @@ -147,4 +147,5 @@ function checkDaemon(options) {
}

exports.init = init;
exports.checkDaemon = checkDaemon;
exports.checkDaemon = checkDaemon;
exports.rpcCall = rpcCall;

0 comments on commit 2bece4d

Please sign in to comment.