From 5e2e28365cb827c4b9631b4ac153f374d164479a Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sun, 27 Jun 2021 22:33:26 -0700 Subject: [PATCH] GUACAMOLE-724: Track client focus changes within tiled client directive, not just in changes to overall attached group. --- .../client/controllers/clientController.js | 51 +++++++------------ .../app/client/directives/guacTiledClients.js | 31 +++++++++++ 2 files changed, 48 insertions(+), 34 deletions(-) diff --git a/guacamole/src/main/frontend/src/app/client/controllers/clientController.js b/guacamole/src/main/frontend/src/app/client/controllers/clientController.js index f9adf304c..de806bc3b 100644 --- a/guacamole/src/main/frontend/src/app/client/controllers/clientController.js +++ b/guacamole/src/main/frontend/src/app/client/controllers/clientController.js @@ -145,12 +145,16 @@ angular.module('client').controller('clientController', ['$scope', '$routeParams /** * Applies any changes to connection parameters made by the user within the - * Guacamole menu. + * Guacamole menu to the given ManagedClient. If no client is supplied, + * this function has no effect. + * + * @param {ManagedClient} client + * The client to apply parameter changes to. */ - $scope.applyParameterChanges = function applyParameterChanges() { + $scope.applyParameterChanges = function applyParameterChanges(client) { angular.forEach($scope.menu.connectionParameters, function sendArgv(value, name) { - if ($scope.focusedClient) - ManagedClient.setArgument($scope.focusedClient, name, value); + if (client) + ManagedClient.setArgument(client, name, value); }); }; @@ -292,27 +296,6 @@ angular.module('client').controller('clientController', ['$scope', '$routeParams // reloading the route $scope.$on('$routeUpdate', updateAttachedClients); - /** - * Returns the currently-focused ManagedClient. If there is no such client, - * or multiple clients are focused, null is returned. - * - * @returns {ManagedClient} - * The currently-focused client, or null if there are no focused - * clients or if multiple clients are focused. - */ - $scope.getFocusedClient = function getFocusedClient() { - - var managedClientGroup = $scope.clientGroup; - if (managedClientGroup) { - var focusedClients = _.filter(managedClientGroup.clients, client => client.clientProperties.focused); - if (focusedClients.length === 1) - return focusedClients[0]; - } - - return null; - - }; - /** * The root connection groups of the connection hierarchy that should be * presented to the user for selecting a different connection, as a map of @@ -444,7 +427,7 @@ angular.module('client').controller('clientController', ['$scope', '$routeParams // Send any argument value data once menu is hidden if (!menuShown && menuShownPreviousState) - $scope.applyParameterChanges(); + $scope.applyParameterChanges($scope.focusedClient); // Disable client keyboard if the menu is shown angular.forEach($scope.clientGroup.clients, function updateKeyboardEnabled(client) { @@ -454,19 +437,19 @@ angular.module('client').controller('clientController', ['$scope', '$routeParams }); // Automatically track and cache the currently-focused client - $scope.$watch('getFocusedClient()', function focusedClientChanged(client) { + $scope.$on('guacClientFocused', function focusedClientChanged(event, newFocusedClient) { - // Apply any parameter changes when focus is changing (as - // applyParameterChanges() depends on the value of focusedClient, this - // must be called BEFORE updating focusedClient - $scope.applyParameterChanges(); + var oldFocusedClient = $scope.focusedClient; + $scope.focusedClient = newFocusedClient; - $scope.focusedClient = client; + // Apply any parameter changes when focus is changing + if (oldFocusedClient) + $scope.applyParameterChanges(oldFocusedClient); // Update available connection parameters, if there is a focused // client - $scope.menu.connectionParameters = $scope.focusedClient ? - ManagedClient.getArgumentModel($scope.focusedClient) : {}; + $scope.menu.connectionParameters = newFocusedClient ? + ManagedClient.getArgumentModel(newFocusedClient) : {}; }); diff --git a/guacamole/src/main/frontend/src/app/client/directives/guacTiledClients.js b/guacamole/src/main/frontend/src/app/client/directives/guacTiledClients.js index c9b332421..35b253650 100644 --- a/guacamole/src/main/frontend/src/app/client/directives/guacTiledClients.js +++ b/guacamole/src/main/frontend/src/app/client/directives/guacTiledClients.js @@ -56,6 +56,33 @@ angular.module('client').directive('guacTiledClients', [function guacTiledClient var ManagedClient = $injector.get('ManagedClient'); var ManagedClientGroup = $injector.get('ManagedClientGroup'); + /** + * Returns the currently-focused ManagedClient. If there is no such + * client, or multiple clients are focused, null is returned. + * + * @returns {ManagedClient} + * The currently-focused client, or null if there are no focused + * clients or if multiple clients are focused. + */ + var getFocusedClient = function getFocusedClient() { + + var managedClientGroup = $scope.clientGroup; + if (managedClientGroup) { + var focusedClients = _.filter(managedClientGroup.clients, client => client.clientProperties.focused); + if (focusedClients.length === 1) + return focusedClients[0]; + } + + return null; + + }; + + // Re-initialize the reference to the currently-focused client when a + // new client group is set + $scope.$watch('clientGroup', function clientGroupChanged() { + $scope.$emit('guacClientFocused', getFocusedClient()); + }); + /** * Returns a callback for guacClick that assigns or updates keyboard * focus to the given client, allowing that client to receive and @@ -110,6 +137,10 @@ angular.module('client').directive('guacTiledClients', [function guacTiledClient } + // Update reference to single focused client after focus has + // changed + $scope.$emit('guacClientFocused', getFocusedClient()); + }; };