mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 13:17:41 +00:00
GUAC-1480: Do not poll - just hook into events where the clipboard may have changed.
This commit is contained in:
@@ -104,21 +104,30 @@ angular.module('client').factory('clipboardService', ['$injector',
|
|||||||
|
|
||||||
var deferred = $q.defer();
|
var deferred = $q.defer();
|
||||||
|
|
||||||
// Clear and select the clipboard DOM element
|
// Wait for the next event queue run before attempting to read
|
||||||
clipboardContent.value = '';
|
// clipboard data (in case the copy/cut has not yet completed)
|
||||||
clipboardContent.select();
|
window.setTimeout(function deferredClipboardRead() {
|
||||||
|
|
||||||
// Attempt paste local clipboard into clipboard DOM element
|
// Clear and select the clipboard DOM element
|
||||||
if (document.execCommand('paste'))
|
clipboardContent.value = '';
|
||||||
deferred.resolve(clipboardContent.value);
|
clipboardContent.select();
|
||||||
else
|
|
||||||
deferred.reject();
|
// Attempt paste local clipboard into clipboard DOM element
|
||||||
|
if (document.execCommand('paste'))
|
||||||
|
deferred.resolve(clipboardContent.value);
|
||||||
|
else
|
||||||
|
deferred.reject();
|
||||||
|
|
||||||
|
}, 10);
|
||||||
|
|
||||||
return deferred.promise;
|
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) {
|
service.getLocalClipboard().then(function clipboardRead(data) {
|
||||||
|
|
||||||
// Fire clipboard event if the data has changed
|
// 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;
|
return service;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user