From fc22f2e2ea3d12ac36096e1ec3ab4fe36f59b66f Mon Sep 17 00:00:00 2001 From: purocean Date: Wed, 12 Jan 2022 09:36:39 +0800 Subject: [PATCH] upd: handle onbeforeunload on electron for drawio editor --- src/renderer/plugins/markdown-drawio.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/renderer/plugins/markdown-drawio.ts b/src/renderer/plugins/markdown-drawio.ts index 8aa6f1d7..5e926eb2 100644 --- a/src/renderer/plugins/markdown-drawio.ts +++ b/src/renderer/plugins/markdown-drawio.ts @@ -276,6 +276,12 @@ function buildEditorSrcdoc (file: Doc) { iframe.style.border = 'none' iframe.setAttribute('frameborder', '0') + ${isElectron ? ` + window.onbeforeunload = evt => { + iframe.contentWindow.postMessage(JSON.stringify({ action: 'exit' }), '*'); + } + ` : ''} + const asPng = doc.path.endsWith('.png') const receive = async function (evt) {