Merge pull request #11 from cwillisf/fix-quit-confirmation

Fix quit confirmation
This commit is contained in:
Chris Willis-Ford 2018-12-13 10:38:21 -08:00 committed by GitHub
commit 505d7cc7e7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 6 deletions

View file

@ -1,4 +1,4 @@
import {app, BrowserWindow} from 'electron';
import {BrowserWindow, app, dialog} from 'electron';
import * as path from 'path';
import {format as formatUrl} from 'url';
@ -67,4 +67,18 @@ app.on('activate', () => {
// create main BrowserWindow when electron is ready
app.on('ready', () => {
mainWindow = createMainWindow();
mainWindow.webContents.on('will-prevent-unload', ev => {
const choice = dialog.showMessageBox(mainWindow, {
type: 'question',
buttons: ['Stay', 'Leave'],
message: 'Leave Scratch?',
cancelId: 0, // closing the dialog means "stay"
defaultId: 0, // pressing enter or space without explicitly selecting something means "stay"
detail: 'Any unsaved changes will be lost.'
});
const shouldQuit = (choice === 1);
if (shouldQuit) {
ev.preventDefault();
}
});
});

View file

@ -18,11 +18,6 @@ document.body.appendChild(appTarget);
GUI.setAppElement(appTarget);
const WrappedGui = AppStateHOC(GUI);
if (process.env.NODE_ENV === 'production' && typeof window === 'object') {
// Warn before navigating away
window.onbeforeunload = () => true;
}
const onStorageInit = storageInstance => {
storageInstance.addHelper(new ElectronStorageHelper(storageInstance));
// storageInstance.addOfficialScratchWebStores(); // TODO: do we want this?