From 0f8b11cbfdb31760ab3e8cbea25f24c88946e08e Mon Sep 17 00:00:00 2001 From: bordun Date: Mon, 30 Mar 2020 18:00:16 +0200 Subject: [PATCH] ipc: emit 'close' when closing/refreshing tab --- src/client/editor/index.js | 4 ---- src/client/index.js | 8 +++++++- src/client/ipc/callbacks.js | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/client/editor/index.js b/src/client/editor/index.js index a44db6df..d78acdd1 100644 --- a/src/client/editor/index.js +++ b/src/client/editor/index.js @@ -102,10 +102,6 @@ class Editor { this.grid = true this.unsavedSession = false - window.onbeforeunload = ()=>{ - if (this.unsavedSession) return true - } - this.history = [] this.historyState = -1 diff --git a/src/client/index.js b/src/client/index.js index 86e8a430..affb00ae 100644 --- a/src/client/index.js +++ b/src/client/index.js @@ -19,15 +19,21 @@ document.addEventListener('DOMContentLoaded', function(event) { var ipc = require('./ipc/'), backup = require('./backup') - ipc.init() + require('./ui/init') + var editor = require('./editor') document.title = TITLE ipc.send('open', {hotReload: backup.exists}) + window.onbeforeunload = ()=>{ + if (editor.unsavedSession) return true + ipc.send('close') + } + backup.load() diff --git a/src/client/ipc/callbacks.js b/src/client/ipc/callbacks.js index 58670ed3..ba881fbd 100644 --- a/src/client/ipc/callbacks.js +++ b/src/client/ipc/callbacks.js @@ -95,7 +95,7 @@ module.exports = { reload: function(){ backup.save() - window.onbeforeunload = null + editor.unsavedSession = false window.location.href = window.location.href },