GUACAMOLE-55: Move local clipboad sync logic back into clientController. Keep the guacClipboard directive lean and with a single purpose.

This commit is contained in:
Michael Jumper
2016-06-29 18:40:35 -07:00
parent b9a57897c5
commit 0679c10187
2 changed files with 54 additions and 108 deletions

View File

@@ -32,6 +32,7 @@ angular.module('client').controller('clientController', ['$scope', '$routeParams
// Required services
var $location = $injector.get('$location');
var authenticationService = $injector.get('authenticationService');
var clipboardService = $injector.get('clipboardService');
var guacClientManager = $injector.get('guacClientManager');
var guacNotification = $injector.get('guacNotification');
var preferenceService = $injector.get('preferenceService');
@@ -244,6 +245,15 @@ angular.module('client').controller('clientController', ['$scope', '$routeParams
*/
var keysCurrentlyPressed = {};
/**
* Map of all currently pressed keys (by keysym) to the clipboard contents
* received from the remote desktop while those keys were pressed. All keys
* not currently pressed will not have entries within this map.
*
* @type Object.<Number, ClipboardData>
*/
var clipboardDataFromKey = {};
/*
* Check to see if all currently pressed keys are in the set of menu keys.
*/
@@ -374,11 +384,24 @@ angular.module('client').controller('clientController', ['$scope', '$routeParams
$scope.$watch('menu.shown', function menuVisibilityChanged(menuShown, menuShownPreviousState) {
// Send clipboard data if menu is hidden
if (!menuShown && menuShownPreviousState)
$scope.$broadcast('guacClipboard', $scope.client.clipboardData);
// Disable client keyboard if the menu is shown
$scope.client.clientProperties.keyboardEnabled = !menuShown;
});
// Watch clipboard for new data, associating it with any pressed keys
$scope.$watch('client.clipboardData', function clipboardChanged(data) {
// Associate new clipboard data with any currently-pressed key
for (var keysym in keysCurrentlyPressed)
clipboardDataFromKey[keysym] = data;
});
// Track pressed keys, opening the Guacamole menu after Ctrl+Alt+Shift
$scope.$on('guacKeydown', function keydownListener(event, keysym, keyboard) {
@@ -414,9 +437,18 @@ angular.module('client').controller('clientController', ['$scope', '$routeParams
});
// Update pressed keys as they are released
// Update pressed keys as they are released, synchronizing the clipboard
// with any data that appears to have come from those key presses
$scope.$on('guacKeyup', function keyupListener(event, keysym, keyboard) {
// Sync local clipboard with any clipboard data received while this
// key was pressed (if any)
var clipboardData = clipboardDataFromKey[keysym];
if (clipboardData) {
clipboardService.setLocalClipboard(clipboardData);
delete clipboardDataFromKey[keysym];
}
// Mark key as released
delete keysCurrentlyPressed[keysym];
@@ -529,6 +561,19 @@ angular.module('client').controller('clientController', ['$scope', '$routeParams
});
}
// Hide status and sync local clipboard once connected
else if (connectionState === ManagedClientState.ConnectionState.CONNECTED) {
// Sync with local clipboard
clipboardService.getLocalClipboard().then(function clipboardRead(data) {
$scope.$broadcast('guacClipboard', data);
});
// Hide status notification
guacNotification.showStatus(false);
}
// Hide status for all other states
else
guacNotification.showStatus(false);