GUAC-1480: Do not poll - just hook into events where the clipboard may have changed.

This commit is contained in:
Michael Jumper
2016-02-04 17:33:26 -08:00
parent 8740d365eb
commit 31eb5ec73f

View File

@@ -104,6 +104,10 @@ angular.module('client').factory('clipboardService', ['$injector',
var deferred = $q.defer();
// 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() {
// Clear and select the clipboard DOM element
clipboardContent.value = '';
clipboardContent.select();
@@ -114,11 +118,16 @@ angular.module('client').factory('clipboardService', ['$injector',
else
deferred.reject();
}, 10);
return deferred.promise;
};
// Periodically attempt to read the clipboard, firing an event if successful
window.setInterval(function periodicallyReadClipboard() {
/**
* Checks whether the clipboard data has changed, firing a new
* "guacClipboard" event if it has.
*/
var checkClipboard = function checkClipboard() {
service.getLocalClipboard().then(function clipboardRead(data) {
// Fire clipboard event if the data has changed
@@ -128,7 +137,12 @@ angular.module('client').factory('clipboardService', ['$injector',
}
});
}, 100);
};
// Attempt to read the clipboard if it may have changed
window.addEventListener('copy', checkClipboard, true);
window.addEventListener('cut', checkClipboard, true);
window.addEventListener('focus', checkClipboard, true);
return service;