feat: Prompt for quitting session on desktop quit

This commit is contained in:
Susmitha Girumala committed 2021-05-12 12:45:05 -04:00
1 parent 4e13ea56c3
commit ce7cdba0bc
2 files changed
+36 -2

No files matched your search

+26 -1
View File
@@ -7,9 +7,9 @@ const {
const {
session,
app,
dialog,
protocol,
BrowserWindow,
ipcMain,
Menu,
MenuItem,
} = require('electron');
@@ -17,6 +17,7 @@ require('./ipc/handlers.js');
const origin = require('./origin/index.js');
const { generateCSPHeader } = require('./config/content-security-policy.js');
const sessionManager = require('./session/manager.js');
const menu = require('./config/menu.js');
const appUpdater = require('./helpers/app-updater.js');
@@ -183,6 +184,30 @@ app.on('ready', async () => {
});
});
/**
* Prompt for closing spawned processes
*/
app.on('before-quit', (event) => {
if (sessionManager.hasActiveSessions) {
const dialogOpts = {
type: 'question',
buttons: ['Close & Quit', 'Ignore & Quit', 'Cancel'],
detail: 'Close sessions before quitting?',
};
dialog.showMessageBox(dialogOpts).then((returnValue) => {
switch (returnValue.response) {
case 0:
sessionManager.stopAll();
break;
case 2:
event.preventDefault();
break;
}
});
}
});
// Handle an unhandled error in the main thread
//
// Note that 'uncaughtException' is a crude mechanism for exception handling intended to
+10 -1
View File
@@ -7,6 +7,14 @@ class SessionManager {
this.#sessions = [];
}
/**
* Checks for active sessions
* @returns {boolean}
*/
get hasActiveSessions() {
return Boolean(this.#sessions.find((session) => session.isActive));
}
/**
* Start a session and track it.
* Returns session proxy details if successfully started.
@@ -27,10 +35,11 @@ class SessionManager {
*/
async stopById(session_id) {
const session = this.#sessions.find((session) => session.id === session_id);
return session.stop();
return session && session.stop();
}
stopAll() {
this.#sessions.forEach((session) => session.stop());
}
}