GUACAMOLE-526: Maintain full correct chain of promises for clipboard read attempts, including the "finally" used for cleanup. The "finally" handler creates a new promise with a potentially unhandled rejection otherwise.

This commit is contained in:
Michael Jumper
2018-04-24 14:43:54 -07:00
parent 670ec390b5
commit 01e19c19dc

View File

@@ -415,16 +415,8 @@ angular.module('clipboard').factory('clipboardService', ['$injector',
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() {
// Track the originally-focused element prior to changing focus
var originalElement = document.activeElement;
pushSelection();
/**
* Attempts to paste the clipboard contents into the
@@ -472,9 +464,9 @@ angular.module('clipboard').factory('clipboardService', ['$injector',
};
// Clean up event listener and selection once the paste attempt has
// completed
deferred.promise['finally'](function cleanupReadAttempt() {
// Mark read attempt as in progress, cleaning up event listener and
// selection once the paste attempt has completed
pendingRead = deferred.promise['finally'](function cleanupReadAttempt() {
// Do not use future changes in focus
clipboardContent.removeEventListener('focus', performPaste);
@@ -490,6 +482,12 @@ angular.module('clipboard').factory('clipboardService', ['$injector',
});
// 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() {
pushSelection();
// Ensure clipboard element is blurred (and that the "focus" event
// will fire)
clipboardContent.blur();
@@ -506,7 +504,8 @@ angular.module('clipboard').factory('clipboardService', ['$injector',
}, CLIPBOARD_READ_DELAY);
return deferred.promise;
return pendingRead;
};
return service;