GUACAMOLE-559: Add support for reading/writing clipboard contents using the Asynchronous Clipboard API.

This commit is contained in:
Michael Jumper
2018-05-02 22:44:04 -07:00
parent 8181a96060
commit 619963277d

View File

@@ -179,6 +179,23 @@ angular.module('clipboard').factory('clipboardService', ['$injector',
var deferred = $q.defer(); var deferred = $q.defer();
try {
// Attempt to read the clipboard using the Asynchronous Clipboard
// API, if it's available
if (navigator.clipboard && navigator.clipboard.writeText) {
if (data.type === 'text/plain') {
navigator.clipboard.writeText(data.data).then(deferred.resolve, deferred.reject);
return deferred.promise;
}
}
}
// Ignore any hard failures to use Asynchronous Clipboard API, falling
// back to traditional document.execCommand()
catch (ignore) {}
// Track the originally-focused element prior to changing focus // Track the originally-focused element prior to changing focus
var originalElement = document.activeElement; var originalElement = document.activeElement;
pushSelection(); pushSelection();
@@ -415,6 +432,29 @@ angular.module('clipboard').factory('clipboardService', ['$injector',
var deferred = $q.defer(); var deferred = $q.defer();
try {
// Attempt to read the clipboard using the Asynchronous Clipboard
// API, if it's available
if (navigator.clipboard && navigator.clipboard.readText) {
navigator.clipboard.readText().then(function textRead(text) {
deferred.resolve(new ClipboardData({
type : 'text/plain',
data : text
}));
}, deferred.reject);
return deferred.promise;
}
}
// Ignore any hard failures to use Asynchronous Clipboard API, falling
// back to traditional document.execCommand()
catch (ignore) {}
// Track the originally-focused element prior to changing focus // Track the originally-focused element prior to changing focus
var originalElement = document.activeElement; var originalElement = document.activeElement;