From 1e77d8aed1395cb25bd4c0f11cb5665ce5141a00 Mon Sep 17 00:00:00 2001 From: jean-emmanuel Date: Sun, 25 Feb 2018 10:02:10 +0100 Subject: [PATCH] editor: ask for confirmation when closing or refreshing a the page if the editor has been enabled at least once (issue #165) --- CHANGELOG.md | 4 ++++ app/main/electron-window.js | 19 +++++++++++++++++-- src/browser/js/app/editor/index.js | 7 +++++++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 814fe1d6..10e9c9fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ - bug fixes - property maths: variables names declared in a formula where replaced by their associated value if found in the formula's result +- ui + - add iOS fullscreen support via add-to-home feature +- editor + - ask for confirmation when closing or refreshing a the page if the editor has been enabled at least once ## 0.24.2 diff --git a/app/main/electron-window.js b/app/main/electron-window.js index 28a611b6..a1f4183f 100644 --- a/app/main/electron-window.js +++ b/app/main/electron-window.js @@ -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) { diff --git a/src/browser/js/app/editor/index.js b/src/browser/js/app/editor/index.js index cd53acd7..fbf2ccb8 100644 --- a/src/browser/js/app/editor/index.js +++ b/src/browser/js/app/editor/index.js @@ -13,12 +13,19 @@ var Editor = class Editor { this.defaults[k] = widgets[k].defaults() } + this.enabledOnce = false + window.onbeforeunload = ()=>{ + if (this.enabledOnce) return true + } + } enable() { EDITING = true + this.enabledOnce = true + DOM.get('.editor-root')[0].setAttribute('data-widget', DOM.get('.root-container')[0].getAttribute('data-widget')) DOM.get('.editor-root')[0].classList.remove('disabled') DOM.get('.disable-editor')[0].classList.remove('on')