From 0d74223888a9ec3956ed4fa839332d4365da3cd3 Mon Sep 17 00:00:00 2001 From: DomenGaber Date: Wed, 5 Feb 2020 11:35:54 +0100 Subject: [PATCH] Add buttons to copy and clear interaction stack --- app/styles/base.css | 10 ++++++++++ app/ui.js | 33 +++++++++++++++++++++++++++++++++ vnc.html | 4 +++- 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/app/styles/base.css b/app/styles/base.css index 49d8c09b..1dc1e0cf 100644 --- a/app/styles/base.css +++ b/app/styles/base.css @@ -888,6 +888,7 @@ select:active { .noVNC_info_item_label { display: inline-block; + width: 100%; margin-bottom: 15px; font-weight: 600; font-size: 14px; @@ -895,6 +896,15 @@ select:active { color: rgba(0, 0, 0, .5); } +.noVNC_info_item button { + display: inline-block; + padding: 4px 4px; + margin: 10px 5px 20px 0; + vertical-align: middle; + border: 1px solid rgba(0, 0, 0, 0.2); + border-radius: 6px; +} + #noVNC_mouse_coordinates, #noVNC_click_stack { width: 100%; diff --git a/app/ui.js b/app/ui.js index 4cac0341..0a0f3923 100644 --- a/app/ui.js +++ b/app/ui.js @@ -720,6 +720,39 @@ const UI = { }, trackClicks() { + document.getElementById('noVNC_click_stack_copy').addEventListener('click', function() { + let text = JSON.stringify(UI.canvasInteractionEvents); + if (!navigator.clipboard) { + var textArea = document.createElement("textarea"); + textArea.value = text; + textArea.style.position="fixed"; //avoid scrolling to bottom + document.body.appendChild(textArea); + textArea.focus(); + textArea.select(); + + try { + var successful = document.execCommand('copy'); + var msg = successful ? 'successful' : 'unsuccessful'; + console.log('Fallback: Copying text command was ' + msg); + } catch (err) { + console.error('Fallback: Oops, unable to copy', err); + } + + document.body.removeChild(textArea); + return; + } + navigator.clipboard.writeText(text).then(function() { + console.log('Async: Copying to clipboard was successful!'); + }, function(err) { + console.error('Async: Could not copy text: ', err); + }); + }); + + document.getElementById('noVNC_click_stack_clear').addEventListener('click', function() { + UI.canvasInteractionEvents = Array(); + UI.updateInteractionStackUI(); + }); + UI.rfb.canvas.addEventListener('mouseup', function(e) { let scaleRatioX = UI.rfb.canvas.width / UI.rfb.canvas.clientWidth; let scaleRatioY = UI.rfb.canvas.height / UI.rfb.canvas.clientHeight; diff --git a/vnc.html b/vnc.html index 8101661b..841b48c8 100644 --- a/vnc.html +++ b/vnc.html @@ -335,8 +335,10 @@ (0, 0) -
+
Interaction stack + +