Skip to content

Commit 537600d

Browse files
committed
Update notification when clipboard is updated
- use existing UI/API - add 'noVNC_setting_notify_clipboard_received' - add support for Clipboard module introduced with fb7e891 (PR novnc#1993)
1 parent 817c1de commit 537600d

File tree

3 files changed

+25
-37
lines changed

3 files changed

+25
-37
lines changed

app/styles/base.css

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -902,30 +902,6 @@ html {
902902
#noVNC_bell {
903903
display: none;
904904
}
905-
/* ----------------------------------------
906-
*
907-
* Styles for Showing the Clipboard updated
908-
*/
909-
.notification {
910-
position: fixed;
911-
top: 20px;
912-
right: 20px;
913-
background-color: grey;
914-
color: white;
915-
padding: 10px 20px;
916-
border-radius: 8px;
917-
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.2);
918-
font-family: sans-serif;
919-
font-size: 16px;
920-
opacity: 1;
921-
transition: opacity 0.5s ease;
922-
z-index: 9999;
923-
}
924-
925-
.fade-out {
926-
opacity: 0;
927-
}
928-
929905

930906
/* ----------------------------------------
931907
* Media sizing

app/ui.js

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ const UI = {
185185
UI.initSetting('bell', 'on');
186186
UI.initSetting('view_only', false);
187187
UI.initSetting('show_dot', false);
188+
UI.initSetting('notify_clipboard_received', false);
188189
UI.initSetting('path', 'websockify');
189190
UI.initSetting('repeaterID', '');
190191
UI.initSetting('reconnect', false);
@@ -371,6 +372,8 @@ const UI = {
371372
UI.addSettingChangeHandler('view_only', UI.updateViewOnly);
372373
UI.addSettingChangeHandler('show_dot');
373374
UI.addSettingChangeHandler('show_dot', UI.updateShowDotCursor);
375+
UI.addSettingChangeHandler('notify_clipboard_received');
376+
UI.addSettingChangeHandler('notify_clipboard_received', UI.updateNotifyClipboardReceived);
374377
UI.addSettingChangeHandler('host');
375378
UI.addSettingChangeHandler('port');
376379
UI.addSettingChangeHandler('path');
@@ -892,6 +895,7 @@ const UI = {
892895
UI.updateSetting('logging');
893896
UI.updateSetting('reconnect');
894897
UI.updateSetting('reconnect_delay');
898+
UI.updateSetting('notify_clipboard_received');
895899

896900
document.getElementById('noVNC_settings')
897901
.classList.add("noVNC_open");
@@ -993,25 +997,17 @@ const UI = {
993997
UI.openClipboardPanel();
994998
}
995999
},
996-
showCopiedNotification() {
997-
// This is responsible for showing the notification when text is updated in the clipboard.
998-
const notificationBox = document.createElement("div");
999-
notificationBox.className = "notification";
1000-
notificationBox.innerText = "Clipboard updated";
1001-
document.body.appendChild(notificationBox);
10021000

1003-
setTimeout(() => {
1004-
notificationBox.classList.add("fade-out");
1005-
setTimeout(() => {
1006-
notificationBox.remove();
1007-
}, 500); // Wait for fade-out transition
1008-
}, 3000); // Display for 3 seconds
1001+
notifyClipboardReceived() {
1002+
// When enabled with setting 'notify_clipboard_received', shows
1003+
// notification when a 'clipboard-received'-event is fired by
1004+
// the RFB instance.
1005+
UI.showStatus(_('Clipboard updated'), 3000);
10091006
},
10101007

10111008
clipboardReceive(e) {
10121009
Log.Debug(">> UI.clipboardReceive: " + e.detail.text.substr(0, 40) + "...");
10131010
document.getElementById('noVNC_clipboard_text').value = e.detail.text;
1014-
UI.showCopiedNotification();
10151011
Log.Debug("<< UI.clipboardReceive");
10161012
},
10171013

@@ -1119,6 +1115,7 @@ const UI = {
11191115

11201116
UI.updateViewOnly(); // requires UI.rfb
11211117
UI.updateClipboard();
1118+
UI.updateNotifyClipboardReceived();
11221119
},
11231120

11241121
disconnect() {
@@ -1824,6 +1821,14 @@ const UI = {
18241821
UI.rfb.showDotCursor = UI.getSetting('show_dot');
18251822
},
18261823

1824+
updateNotifyClipboardReceived() {
1825+
if (!UI.rfb) return;
1826+
UI.rfb.removeEventListener('clipboardreceived', UI.notifyClipboardReceived);
1827+
if (UI.getSetting('notify_clipboard_received')) {
1828+
UI.rfb.addEventListener('clipboardreceived', UI.notifyClipboardReceived);
1829+
}
1830+
},
1831+
18271832
updateLogging() {
18281833
WebUtil.initLogging(UI.getSetting('logging'));
18291834
},

vnc.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,13 @@ <h1 class="noVNC_logo" translate="no"><span>no</span><br>VNC</h1>
296296
Show dot when no cursor
297297
</label>
298298
</li>
299+
<li>
300+
<label>
301+
<input id="noVNC_setting_notify_clipboard_received" type="checkbox"
302+
class="toggle">
303+
Show clipboard notification
304+
</label>
305+
</li>
299306
<li><hr></li>
300307
<!-- Logging selection dropdown -->
301308
<li>

0 commit comments

Comments
 (0)