clipboard WIP

This commit is contained in:
matt 2021-10-01 09:03:03 +00:00
parent 34bfdddab5
commit e7c601efc0
3 changed files with 30 additions and 6 deletions

View File

@ -22,7 +22,7 @@ window.addEventListener("load", function() {
import * as Log from '../core/util/logging.js'; import * as Log from '../core/util/logging.js';
import _, { l10n } from './localization.js'; import _, { l10n } from './localization.js';
import { isTouchDevice, isSafari, hasScrollbarGutter, dragThreshold } import { isTouchDevice, isSafari, hasScrollbarGutter, dragThreshold, supportsBinaryClipboard, isFirefox }
from '../core/util/browser.js'; from '../core/util/browser.js';
import { setCapture, getPointerEvent } from '../core/util/events.js'; import { setCapture, getPointerEvent } from '../core/util/events.js';
import KeyTable from "../core/input/keysym.js"; import KeyTable from "../core/input/keysym.js";
@ -1132,6 +1132,7 @@ const UI = {
if (UI.rfb && UI.rfb.clipboardUp && UI.rfb.clipboardSeamless) { if (UI.rfb && UI.rfb.clipboardUp && UI.rfb.clipboardSeamless) {
navigator.clipboard.read().then((data) => { navigator.clipboard.read().then((data) => {
UI.rfb.clipboardPasteDataFrom(data); UI.rfb.clipboardPasteDataFrom(data);
UI.needToCheckClipboardChange = false;
}); });
/*UI.readClipboard(function (text) { /*UI.readClipboard(function (text) {
@ -1294,10 +1295,15 @@ const UI = {
UI.rfb.videoQuality = UI.getSetting('video_quality'); UI.rfb.videoQuality = UI.getSetting('video_quality');
UI.rfb.clipboardUp = UI.getSetting('clipboard_up'); UI.rfb.clipboardUp = UI.getSetting('clipboard_up');
UI.rfb.clipboardDown = UI.getSetting('clipboard_down'); UI.rfb.clipboardDown = UI.getSetting('clipboard_down');
UI.rfb.clipboardBinary = supportsBinaryClipboard();
UI.rfb.clipboardSeamless = UI.getSetting('clipboard_seamless'); UI.rfb.clipboardSeamless = UI.getSetting('clipboard_seamless');
if (UI.rfb.clipboardSeamless) { if (UI.rfb.clipboardSeamless) {
// explicitly request permission to the clipboard // explicitly request permission to the clipboard
navigator.permissions.query({ name: "clipboard-read" }).then((result) => { console.log('binary clipboard enabled') }); if (UI.rfb.clipboardBinary) {
navigator.permissions.query({ name: "clipboard-read" }).then((result) => { console.log('binary clipboard enabled') });
} else {
navigator.permissions.query({ name: "clipboardRead" }).then((result) => { console.log('binary clipboard enabled') });
}
} }
// KASM-960 workaround, disable seamless on Safari // KASM-960 workaround, disable seamless on Safari
if (/^((?!chrome|android).)*safari/i.test(navigator.userAgent)) if (/^((?!chrome|android).)*safari/i.test(navigator.userAgent))

View File

@ -142,6 +142,7 @@ export default class RFB extends EventTargetMixin {
this._frameRate = 30; this._frameRate = 30;
this._maxVideoResolutionX = 960; this._maxVideoResolutionX = 960;
this._maxVideoResolutionY = 540; this._maxVideoResolutionY = 540;
this._clipboardBinary = true;
this._trackFrameStats = false; this._trackFrameStats = false;
@ -353,6 +354,9 @@ export default class RFB extends EventTargetMixin {
// ===== PROPERTIES ===== // ===== PROPERTIES =====
get clipboardBinary() { return this._clipboardMode; }
set clipboardBinary(val) { this._clipboardMode = val; }
get videoQuality() { return this._videoQuality; } get videoQuality() { return this._videoQuality; }
set videoQuality(quality) { this._videoQuality = quality; } set videoQuality(quality) { this._videoQuality = quality; }
@ -807,7 +811,6 @@ export default class RFB extends EventTargetMixin {
case 'image/png': case 'image/png':
case 'text/plain': case 'text/plain':
case 'text/html': case 'text/html':
mimes.push(mime);
let blob = await clipdata[i].getType(mime); let blob = await clipdata[i].getType(mime);
let buff = await blob.arrayBuffer(); let buff = await blob.arrayBuffer();
let data = new Uint8Array(buff); let data = new Uint8Array(buff);
@ -821,6 +824,12 @@ export default class RFB extends EventTargetMixin {
this._clipHash = h; this._clipHash = h;
} }
} }
if (mimes.includes(mime)) {
continue;
}
mimes.push(mime);
dataset.push(data); dataset.push(data);
console.log('Sending mime type: ' + mime); console.log('Sending mime type: ' + mime);
break; break;
@ -2454,6 +2463,8 @@ export default class RFB extends EventTargetMixin {
let num = this._sock.rQshift8(); // how many different mime types let num = this._sock.rQshift8(); // how many different mime types
let blobs = []; let blobs = [];
let clipdata = []; let clipdata = [];
let mimes = [];
console.log('Clipboard items recieved.');
for (let i = 0; i < num; i++) { for (let i = 0; i < num; i++) {
let mimelen = this._sock.rQshift8(); let mimelen = this._sock.rQshift8();
@ -2463,13 +2474,16 @@ export default class RFB extends EventTargetMixin {
const data = this._sock.rQshiftBytes(len); const data = this._sock.rQshiftBytes(len);
// TODO, what do we do with this?
console.log("Mime " + mime + ", len ", len);
switch(mime) { switch(mime) {
case "image/png": case "image/png":
case "text/html": case "text/html":
case "text/plain": case "text/plain":
if (mimes.includes(mime)){
continue;
}
mimes.push(mime);
console.log("Mime " + mime + ", len ", len);
console.log(data);
let blob = new Blob([data], { type: mime }); let blob = new Blob([data], { type: mime });
clipdata.push(new ClipboardItem({ [mime]: blob })); clipdata.push(new ClipboardItem({ [mime]: blob }));
break; break;

View File

@ -101,3 +101,7 @@ export function isFirefox() {
return navigator && !!(/firefox/i).exec(navigator.userAgent); return navigator && !!(/firefox/i).exec(navigator.userAgent);
} }
export function supportsBinaryClipboard() {
return (typeof navigator.clipboard.read === "function");
}