GUACAMOLE-55: Automatically fire guacClipboard events from index controller when local clipboard has changed.

This commit is contained in:
Michael Jumper
2016-06-29 19:57:01 -07:00
parent b55c4c0211
commit a4019b7f82
2 changed files with 24 additions and 0 deletions

View File

@@ -26,6 +26,7 @@ angular.module('index').controller('indexController', ['$scope', '$injector',
// Required services
var $document = $injector.get('$document');
var $window = $injector.get('$window');
var clipboardService = $injector.get('clipboardService');
var guacNotification = $injector.get('guacNotification');
/**
@@ -124,6 +125,28 @@ angular.module('index').controller('indexController', ['$scope', '$injector',
keyboard.reset();
};
/**
* Checks whether the clipboard data has changed, firing a new
* "guacClipboard" event if it has.
*/
var checkClipboard = function checkClipboard() {
clipboardService.getLocalClipboard().then(function clipboardRead(data) {
$scope.$broadcast('guacClipboard', data);
});
};
// Attempt to read the clipboard if it may have changed
$window.addEventListener('load', checkClipboard, true);
$window.addEventListener('copy', checkClipboard, true);
$window.addEventListener('cut', checkClipboard, true);
$window.addEventListener('focus', function focusGained(e) {
// Only recheck clipboard if it's the window itself that gained focus
if (e.target === $window)
checkClipboard();
}, true);
// Display login screen if a whole new set of credentials is needed
$scope.$on('guacInvalidCredentials', function loginInvalid(event, parameters, error) {
$scope.page.title = 'APP.NAME';

View File

@@ -23,6 +23,7 @@
angular.module('index', [
'auth',
'client',
'clipboard',
'home',
'login',
'manage',