Files
nicotine-less/vnc-clipboard-bridge.js
Claude 2742058a32 Disable Gitea workflows and stabilize VNC startup
Pause automated builds while updating the image, and improve VNC startup/logging with a one-way clipboard bridge for reliable browser sync.
2026-03-01 12:21:22 +01:00

66 lines
2.2 KiB
JavaScript

// VNC → Browser clipboard sync only (one-way)
(function() {
'use strict';
console.log('🔌 Clipboard sync initializing (VNC → Browser only)...');
const clipboardAvailable = navigator.clipboard && window.isSecureContext;
if (!clipboardAvailable) {
console.warn('⚠️ Clipboard API not available - requires HTTPS or localhost');
return;
}
console.log('✓ Clipboard API available (HTTPS detected)');
let lastPanelClipboard = '';
// Wait for clipboard panel to be available
function waitForPanel(callback) {
const panel = document.getElementById('noVNC_clipboard_text');
if (panel) {
console.log('✓ Found noVNC clipboard panel');
callback(panel);
} else {
setTimeout(() => waitForPanel(callback), 100);
}
}
waitForPanel(function(clipboardPanel) {
console.log('✓ Setting up VNC → Browser clipboard sync');
// Sync VNC clipboard to browser
function syncVNCToBrowser() {
const text = clipboardPanel.value;
if (text && text !== lastPanelClipboard) {
lastPanelClipboard = text;
console.log('📋 VNC → Browser: ' + text.substring(0, 50) + (text.length > 50 ? '... (' + text.length + ' chars)' : ''));
navigator.clipboard.writeText(text).then(() => {
console.log('✓ Synced to system clipboard');
}).catch(err => {
console.error('✗ Failed to write to clipboard:', err);
});
}
}
// Monitor changes to the clipboard panel
const observer = new MutationObserver(syncVNCToBrowser);
clipboardPanel.addEventListener('input', syncVNCToBrowser);
clipboardPanel.addEventListener('change', syncVNCToBrowser);
// Poll the panel periodically as fallback
setInterval(syncVNCToBrowser, 300);
observer.observe(clipboardPanel, {
attributes: true,
childList: true,
characterData: true,
subtree: true
});
console.log('✓ VNC → Browser clipboard sync ACTIVE');
});
})();