clipboard WIP
This commit is contained in:
parent
34bfdddab5
commit
e7c601efc0
10
app/ui.js
10
app/ui.js
|
@ -22,7 +22,7 @@ window.addEventListener("load", function() {
|
|||
|
||||
import * as Log from '../core/util/logging.js';
|
||||
import _, { l10n } from './localization.js';
|
||||
import { isTouchDevice, isSafari, hasScrollbarGutter, dragThreshold }
|
||||
import { isTouchDevice, isSafari, hasScrollbarGutter, dragThreshold, supportsBinaryClipboard, isFirefox }
|
||||
from '../core/util/browser.js';
|
||||
import { setCapture, getPointerEvent } from '../core/util/events.js';
|
||||
import KeyTable from "../core/input/keysym.js";
|
||||
|
@ -1132,6 +1132,7 @@ const UI = {
|
|||
if (UI.rfb && UI.rfb.clipboardUp && UI.rfb.clipboardSeamless) {
|
||||
navigator.clipboard.read().then((data) => {
|
||||
UI.rfb.clipboardPasteDataFrom(data);
|
||||
UI.needToCheckClipboardChange = false;
|
||||
});
|
||||
|
||||
/*UI.readClipboard(function (text) {
|
||||
|
@ -1294,10 +1295,15 @@ const UI = {
|
|||
UI.rfb.videoQuality = UI.getSetting('video_quality');
|
||||
UI.rfb.clipboardUp = UI.getSetting('clipboard_up');
|
||||
UI.rfb.clipboardDown = UI.getSetting('clipboard_down');
|
||||
UI.rfb.clipboardBinary = supportsBinaryClipboard();
|
||||
UI.rfb.clipboardSeamless = UI.getSetting('clipboard_seamless');
|
||||
if (UI.rfb.clipboardSeamless) {
|
||||
// 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
|
||||
if (/^((?!chrome|android).)*safari/i.test(navigator.userAgent))
|
||||
|
|
22
core/rfb.js
22
core/rfb.js
|
@ -142,6 +142,7 @@ export default class RFB extends EventTargetMixin {
|
|||
this._frameRate = 30;
|
||||
this._maxVideoResolutionX = 960;
|
||||
this._maxVideoResolutionY = 540;
|
||||
this._clipboardBinary = true;
|
||||
|
||||
this._trackFrameStats = false;
|
||||
|
||||
|
@ -353,6 +354,9 @@ export default class RFB extends EventTargetMixin {
|
|||
|
||||
// ===== PROPERTIES =====
|
||||
|
||||
get clipboardBinary() { return this._clipboardMode; }
|
||||
set clipboardBinary(val) { this._clipboardMode = val; }
|
||||
|
||||
get videoQuality() { return this._videoQuality; }
|
||||
set videoQuality(quality) { this._videoQuality = quality; }
|
||||
|
||||
|
@ -807,7 +811,6 @@ export default class RFB extends EventTargetMixin {
|
|||
case 'image/png':
|
||||
case 'text/plain':
|
||||
case 'text/html':
|
||||
mimes.push(mime);
|
||||
let blob = await clipdata[i].getType(mime);
|
||||
let buff = await blob.arrayBuffer();
|
||||
let data = new Uint8Array(buff);
|
||||
|
@ -821,6 +824,12 @@ export default class RFB extends EventTargetMixin {
|
|||
this._clipHash = h;
|
||||
}
|
||||
}
|
||||
|
||||
if (mimes.includes(mime)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
mimes.push(mime);
|
||||
dataset.push(data);
|
||||
console.log('Sending mime type: ' + mime);
|
||||
break;
|
||||
|
@ -2454,6 +2463,8 @@ export default class RFB extends EventTargetMixin {
|
|||
let num = this._sock.rQshift8(); // how many different mime types
|
||||
let blobs = [];
|
||||
let clipdata = [];
|
||||
let mimes = [];
|
||||
console.log('Clipboard items recieved.');
|
||||
|
||||
for (let i = 0; i < num; i++) {
|
||||
let mimelen = this._sock.rQshift8();
|
||||
|
@ -2463,13 +2474,16 @@ export default class RFB extends EventTargetMixin {
|
|||
|
||||
const data = this._sock.rQshiftBytes(len);
|
||||
|
||||
// TODO, what do we do with this?
|
||||
console.log("Mime " + mime + ", len ", len);
|
||||
|
||||
switch(mime) {
|
||||
case "image/png":
|
||||
case "text/html":
|
||||
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 });
|
||||
clipdata.push(new ClipboardItem({ [mime]: blob }));
|
||||
break;
|
||||
|
|
|
@ -101,3 +101,7 @@ export function isFirefox() {
|
|||
return navigator && !!(/firefox/i).exec(navigator.userAgent);
|
||||
}
|
||||
|
||||
export function supportsBinaryClipboard() {
|
||||
return (typeof navigator.clipboard.read === "function");
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue