Skip to content

Commit ec9c4a7

Browse files
committed
Cleanly handle Electron app quits
1 parent 2eb9187 commit ec9c4a7

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

overrides/js/prepend-electron.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ module.exports = function reconfigureElectron(params) {
1919

2020
electronWrapped = true;
2121

22-
console.log('wrapping');
2322
const app = loadedModule.app;
2423

2524
app.commandLine.appendSwitch('proxy-server', process.env.HTTP_PROXY);
@@ -29,6 +28,19 @@ module.exports = function reconfigureElectron(params) {
2928
'ignore-certificate-errors-spki-list', params.spkiFingerprint
3029
);
3130

31+
app.on('quit', () => {
32+
// This means the user has exited the app while HTTP Toolkit is still running. That's fine,
33+
// but it normally won't exit, since we still have a debugger attached. If we can, we use
34+
// the experimental node 8+ inspector API to disconnect it. If not, we just kill the process
35+
// after a brief delay to allow any other cleanup
36+
try {
37+
require('inspector').close();
38+
} catch (e) {
39+
console.log('Could not disconnect app via inspector, killing manually', e);
40+
setTimeout(() => process.exit(0), 1000);
41+
}
42+
});
43+
3244
app.on('certificate-error', (event, webContents, url, error, certificate, callback) => {
3345
if (
3446
certificate.issuerCert &&

0 commit comments

Comments
 (0)