public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Dominik Csapak <d.csapak@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH xtermjs v3 4/4] ui: prevent accidental closing of terminal window
Date: Tue, 21 Jul 2020 11:00:48 +0200	[thread overview]
Message-ID: <20200721090048.28632-5-d.csapak@proxmox.com> (raw)
In-Reply-To: <20200721090048.28632-1-d.csapak@proxmox.com>

this prevents closing the window e.g. when pressing ctrl+w

most browsers have a function to block a website from doing that,
so users that do not want that, simply have to click that option

also, the message will (at least in chrome) not be displayed,
instead a fixed message will appear

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
 src/www/main.js | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/src/www/main.js b/src/www/main.js
index bb71812..39aef11 100644
--- a/src/www/main.js
+++ b/src/www/main.js
@@ -35,6 +35,7 @@ function updateState(newState, msg, code) {
 	    severity = severities.warning;
 	    break;
 	case states.connected:
+	    window.onbeforeunload = windowUnload;
 	    message = "Connected";
 	    break;
 	case states.disconnecting:
@@ -48,6 +49,7 @@ function updateState(newState, msg, code) {
 	    severity = severities.warning;
 	    break;
 	case states.disconnected:
+	    window.onbeforeunload = undefined;
 	    switch (state) {
 		case states.start:
 		case states.connecting:
@@ -143,7 +145,6 @@ function createTerminal() {
 	    socket.onopen = runTerminal;
 	    socket.onclose = tryReconnect;
 	    socket.onerror = tryReconnect;
-	    window.onbeforeunload = stopTerminal;
 	    updateState(states.connecting);
 	},
 	failure: function(msg) {
@@ -303,6 +304,17 @@ function clearEvents() {
     term.onData(() => {});
 }
 
+function windowUnload(e) {
+    let message = "Are you sure you want to leave this page?";
+
+    e = e || window.event;
+    if (e) {
+	e.returnValue = message;
+    }
+
+    return message;
+}
+
 function stopTerminal(event) {
     event = event || {};
     clearEvents();
-- 
2.20.1





  parent reply	other threads:[~2020-07-21  9:01 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-21  9:00 [pbs-devel] [PATCH xtermjs v3 0/4] rewrite in rust Dominik Csapak
2020-07-21  9:00 ` [pbs-devel] [PATCH xtermjs v3 1/4] termproxy: " Dominik Csapak
2020-07-21  9:00 ` [pbs-devel] [PATCH xtermjs v3 2/4] add handlebars template Dominik Csapak
2020-07-21  9:00 ` [pbs-devel] [PATCH xtermjs v3 3/4] ui: improve error message handling Dominik Csapak
2020-07-21  9:00 ` Dominik Csapak [this message]
2020-07-23 10:29 ` [pbs-devel] applied-series: [PATCH xtermjs v3 0/4] rewrite in rust Thomas Lamprecht

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200721090048.28632-5-d.csapak@proxmox.com \
    --to=d.csapak@proxmox.com \
    --cc=pbs-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal