editor: ask for confirmation when closing or refreshing a the page if the editor has been enabled at least once (issue #165)
This commit is contained in:
parent
d9ed3d4853
commit
fc88b086c3
3 changed files with 28 additions and 2 deletions
|
|
@ -1,5 +1,5 @@
|
|||
var path = require('path'),
|
||||
{BrowserWindow, Menu} = require('electron'),
|
||||
{BrowserWindow, Menu, dialog} = require('electron'),
|
||||
shortcut = require('electron-localshortcut'),
|
||||
settings = require('./settings')
|
||||
|
||||
|
|
@ -23,12 +23,27 @@ module.exports = function(options={}) {
|
|||
}
|
||||
})
|
||||
|
||||
window.loadURL(options.address)
|
||||
window.webContents.on('will-prevent-unload', (event) => {
|
||||
var choice = dialog.showMessageBox(window, {
|
||||
type: 'question',
|
||||
buttons: ['Yes', 'No'],
|
||||
title: 'Are you sure ?',
|
||||
message: 'Unsaved data will be lost. Are you sure you want to quit?',
|
||||
defaultId: 0,
|
||||
cancelId: 1
|
||||
})
|
||||
if (choice === 0) {
|
||||
event.preventDefault()
|
||||
}
|
||||
})
|
||||
|
||||
window.on('closed', function() {
|
||||
window = null
|
||||
})
|
||||
|
||||
window.loadURL(options.address)
|
||||
|
||||
|
||||
window.setMenuBarVisibility(false)
|
||||
|
||||
if (options.shortcuts) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue