KASM-3744 Fix copy/paste for files and folders (#53)

This commit is contained in:
Mariusz Marciniak 2023-01-10 14:26:53 +01:00 committed by GitHub
parent f223cfcafe
commit 31b1a93335
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 6 deletions

View File

@ -2881,16 +2881,23 @@ export default class RFB extends EventTargetMixin {
if (Object.keys(clipItemData).length > 0) { if (Object.keys(clipItemData).length > 0) {
if (this.clipboardBinary) { if (this.clipboardBinary) {
this._clipHash = 0; this._clipHash = 0;
navigator.clipboard.write([new ClipboardItem(clipItemData)]).then( navigator.clipboard.write([new ClipboardItem(clipItemData)]).then(
function() {}, () => {
function(err) { if (textdata) {
this._clipHash = hashUInt8Array(textdata);
}
},
(err) => {
Log.Error("Error writing to client clipboard: " + err); Log.Error("Error writing to client clipboard: " + err);
// Lets try writeText // Lets try writeText
if (textdata.length > 0) { if (textdata.length > 0) {
navigator.clipboard.writeText(textdata).then( navigator.clipboard.writeText(textdata).then(
function() {}, () => {
function(err2) { this._clipHash = hashUInt8Array(textdata);
Log.Error("Error writing text to client clipboard: " + err2); },
(err) => {
Log.Error("Error writing text to client clipboard: " + err);
} }
); );
} }

View File

@ -46,9 +46,15 @@ export function toSignedRelative16bit(toConvert) {
/* Fast hashing function with low entropy */ /* Fast hashing function with low entropy */
export function hashUInt8Array(data) { export function hashUInt8Array(data) {
let h; if (typeof data === "string") {
data = [...data].map(character => character.charCodeAt(0));
}
let h = 0;
for (let i = 0; i < data.length; i++) { for (let i = 0; i < data.length; i++) {
h = Math.imul(31, h) + data[i] | 0; h = Math.imul(31, h) + data[i] | 0;
} }
return h; return h;
} }