mirror of
https://github.com/scratchfoundation/scratch-desktop.git
synced 2025-01-08 21:51:55 -05:00
Merge pull request #11 from cwillisf/fix-quit-confirmation
Fix quit confirmation
This commit is contained in:
commit
505d7cc7e7
2 changed files with 15 additions and 6 deletions
|
@ -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();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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?
|
||||
|
|
Loading…
Reference in a new issue