Skip to content

Commit 74aaaba

Browse files
committed
feat: prefs for zoom and confirm before close
1 parent cc1d342 commit 74aaaba

File tree

5 files changed

+290
-209
lines changed

5 files changed

+290
-209
lines changed

electron/main/app.ts

+23-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Event } from 'electron';
2-
import { BrowserWindow, app, shell } from 'electron';
2+
import { BrowserWindow, app, dialog, shell } from 'electron';
33
import * as path from 'node:path';
44
import serve from 'electron-serve';
55
import { runInBackground } from '../common/async';
@@ -89,9 +89,6 @@ const createMainWindow = async (): Promise<void> => {
8989
},
9090
});
9191

92-
const zoomFactor = await Preferences.get(PreferenceKey.WINDOW_ZOOM_FACTOR);
93-
mainWindow.webContents.setZoomFactor(zoomFactor ?? 1);
94-
9592
// Once the window has finished loading, show it.
9693
mainWindow.webContents.once('did-finish-load', () => {
9794
logger.debug('showing main window');
@@ -170,7 +167,7 @@ app.on('web-contents-created', (_, contents) => {
170167
});
171168

172169
app.on('window-all-closed', (): void => {
173-
logger.debug('windows all closed, quitting app');
170+
logger.debug('windows all closed');
174171
app.quit();
175172
});
176173

@@ -192,8 +189,29 @@ app.on('before-quit', (event: Event): void => {
192189
// don't quit yet, start our async before-quit operations instead
193190
event.preventDefault();
194191
beforeQuitActionStatus = BeforeQuitActionStatus.IN_PROGRESS;
192+
195193
runInBackground(async () => {
196194
logger.debug('performing before-quit operations');
195+
196+
const confirmBeforeClose = await Preferences.get(
197+
PreferenceKey.WINDOW_CONFIRM_ON_CLOSE
198+
);
199+
if (confirmBeforeClose) {
200+
const result = await dialog.showMessageBox({
201+
type: 'question',
202+
title: 'Quit DragonRealms Phoenix?',
203+
message: 'Are you sure you want to quit?',
204+
buttons: ['Yes', 'No'],
205+
defaultId: 1,
206+
cancelId: 1,
207+
});
208+
if (result.response === 1) {
209+
// user clicked No, don't quit yet
210+
beforeQuitActionStatus = BeforeQuitActionStatus.NOT_STARTED;
211+
return;
212+
}
213+
}
214+
197215
await ipcController?.destroy();
198216
beforeQuitActionStatus = BeforeQuitActionStatus.COMPLETED;
199217
app.quit();

0 commit comments

Comments
 (0)