Skip to content

Commit

Permalink
Added checkbox for keeping service running background after GUI closes (
Browse files Browse the repository at this point in the history
#670)

* Added checkbox to keep services running background

* Minor wording tweak

---------

Co-authored-by: Jeff <[email protected]>
  • Loading branch information
ChiaMineJP and paninaro authored Dec 11, 2023
1 parent 8cc1be2 commit 481690a
Showing 1 changed file with 30 additions and 6 deletions.
36 changes: 30 additions & 6 deletions packages/gui/src/electron/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -478,16 +478,26 @@ if (ensureSingleInstance() && ensureCorrectEnvironment()) {
// if (!guessPackaged()) {
// mainWindow.webContents.openDevTools();
// }
mainWindow.on('close', (e) => {
mainWindow.on('close', async (e) => {
// if the daemon isn't local we aren't going to try to start/stop it
if (decidedToClose || !manageDaemonLifetime(NET)) {
return;
}
if (!mainWindow) {
throw new Error('`mainWindow` is empty');
}
e.preventDefault();

if (!isClosing) {
isClosing = true;
let keepBackgroundRunning: boolean | undefined;
const p = readPrefs();
if (typeof p.keepBackgroundRunning === 'boolean') {
keepBackgroundRunning = p.keepBackgroundRunning;
}

if (promptOnQuit) {
const choice = dialog.showMessageBoxSync({
const choice = await dialog.showMessageBox({
type: 'question',
buttons: [i18n._(/* i18n */ { id: 'No' }), i18n._(/* i18n */ { id: 'Yes' })],
title: i18n._(/* i18n */ { id: 'Confirm' }),
Expand All @@ -496,22 +506,36 @@ if (ensureSingleInstance() && ensureCorrectEnvironment()) {
id: 'Are you sure you want to quit?',
}
),
checkboxChecked: keepBackgroundRunning ?? false,
checkboxLabel: i18n._(/* i18n */ { id: 'Keep service running in the background' }),
});
if (choice === 0) {
if (keepBackgroundRunning !== choice.checkboxChecked) {
savePrefs({ ...p, keepBackgroundRunning: choice.checkboxChecked });
}
if (choice.response === 0) {
isClosing = false;
return;
}
keepBackgroundRunning = choice.checkboxChecked;
}
isClosing = false;
decidedToClose = true;
mainWindow.webContents.send('exit-daemon');

// save the window state and unmange so we don't restore the mini exiting state
mainWindowState.saveState(mainWindow);
mainWindowState.unmanage(mainWindow);
mainWindowState.unmanage();

if (keepBackgroundRunning) {
mainWindow.close();
openedWindows.forEach((win) => win.close());
return;
}

mainWindow.webContents.send('exit-daemon');
mainWindow.setBounds({ height: 500, width: 500 });
mainWindow.center();
ipcMain.on('daemon-exited', () => {
mainWindow.close();
mainWindow?.close();

openedWindows.forEach((win) => win.close());
});
Expand Down

0 comments on commit 481690a

Please sign in to comment.