mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 13:17:41 +00:00
GUACAMOLE-128: Do not allow overlapping clipboard read attempts.
This commit is contained in:
@@ -44,6 +44,14 @@ angular.module('clipboard').factory('clipboardService', ['$injector',
|
||||
*/
|
||||
var CLIPBOARD_READ_DELAY = 100;
|
||||
|
||||
/**
|
||||
* The promise associated with the current pending clipboard read attempt.
|
||||
* If no clipboard read is active, this will be null.
|
||||
*
|
||||
* @type Promise.<ClipboardData>
|
||||
*/
|
||||
var pendingRead = null;
|
||||
|
||||
/**
|
||||
* Reference to the window.document object.
|
||||
*
|
||||
@@ -398,8 +406,16 @@ angular.module('clipboard').factory('clipboardService', ['$injector',
|
||||
*/
|
||||
service.getLocalClipboard = function getLocalClipboard() {
|
||||
|
||||
// If the clipboard is already being read, do not overlap the read
|
||||
// attempts; instead share the result across all requests
|
||||
if (pendingRead)
|
||||
return pendingRead;
|
||||
|
||||
var deferred = $q.defer();
|
||||
|
||||
// Mark read attempt as in progress
|
||||
pendingRead = deferred.promise;
|
||||
|
||||
// Wait for the next event queue run before attempting to read
|
||||
// clipboard data (in case the copy/cut has not yet completed)
|
||||
$window.setTimeout(function deferredClipboardRead() {
|
||||
@@ -467,6 +483,9 @@ angular.module('clipboard').factory('clipboardService', ['$injector',
|
||||
originalElement.focus();
|
||||
popSelection();
|
||||
|
||||
// No read is pending any longer
|
||||
pendingRead = null;
|
||||
|
||||
});
|
||||
|
||||
// Ensure clipboard element is blurred (and that the "focus" event
|
||||
|
Reference in New Issue
Block a user