Skip to content
This repository was archived by the owner on Feb 23, 2021. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions public/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ const lndArgs = process.argv.filter(a =>
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let win;
let lndProcess;
let btcdProcess;

log.transports.console.level = 'info';
Expand Down Expand Up @@ -111,6 +110,13 @@ function createWindow() {
);
}

win.on('close', e => {
if (win) {
e.preventDefault();
win.webContents.send('app-close');
}
});

// Emitted when the window is closed.
win.on('closed', () => {
// Dereference the window object, usually you would store windows
Expand All @@ -135,7 +141,7 @@ const startLnd = async () => {
btcdSettingsDir,
miningAddress: BTCD_MINING_ADDRESS,
});
lndProcess = await startLndProcess({
startLndProcess({
isDev,
lndSettingsDir,
lndPort: LND_PORT,
Expand Down Expand Up @@ -179,13 +185,6 @@ app.on('ready', () => {
startLnd();
});

// Quit when all windows are closed.
app.on('window-all-closed', () => {
// On macOS it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
app.quit();
});

app.on('activate', () => {
// On macOS it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
Expand All @@ -194,8 +193,12 @@ app.on('activate', () => {
}
});

ipcMain.on('app-close', () => {
win = null;
app.quit();
});

app.on('quit', () => {
lndProcess && lndProcess.kill();
btcdProcess && btcdProcess.kill();
});

Expand Down
18 changes: 17 additions & 1 deletion public/grpc-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,10 @@ module.exports.init = async function({
});

ipcMain.on('lndClose', event => {
lnd['stopDaemon']({}, (err, response) => {
event.sender.send('lndClosed', { err, response });
});
lnd.close();
event.sender.send('lndClosed', {});
});

ipcMain.on('unlockRequest', (event, { method, body }) => {
Expand Down Expand Up @@ -122,4 +124,18 @@ module.exports.init = async function({
if (!stream) return;
stream.write(data);
});

ipcMain.on('app-close', () => {
if (lnd) {
const errorCheck = err => {
if (err) {
console.log(`Errored stopping lnd daemon: ${JSON.stringify(err)}`);
}
};
lnd['stopDaemon']({}, errorCheck);
lnd.close();
} else if (unlocker) {
unlocker.close();
}
});
};
2 changes: 2 additions & 0 deletions public/preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ window.ipcRenderer = {
_ipcRenderer.once(filter(event), callback);
},
};

_ipcRenderer.on('app-close', () => _ipcRenderer.send('app-close'));
6 changes: 3 additions & 3 deletions test/integration/action/action-integration.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const {
startBtcdProcess,
mineBlocks,
} = require('../../../public/lnd-child-process');
const grcpClient = require('../../../public/grpc-client');
const grpcClient = require('../../../public/grpc-client');

/* eslint-disable no-unused-vars */

Expand Down Expand Up @@ -129,13 +129,13 @@ describe('Action Integration Tests', function() {
lndProcess1 = await lndProcess1Promise;
lndProcess2 = await lndProcess2Promise;

await grcpClient.init({
await grpcClient.init({
ipcMain: ipcMainStub1,
lndPort: LND_PORT_1,
lndSettingsDir: LND_SETTINGS_DIR_1,
network: NETWORK,
});
await grcpClient.init({
await grpcClient.init({
ipcMain: ipcMainStub2,
lndPort: LND_PORT_2,
lndSettingsDir: LND_SETTINGS_DIR_2,
Expand Down