-
Notifications
You must be signed in to change notification settings - Fork 724
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GUACAMOLE-1292: prompt when closing the window/tab to avoid accidents with ctrl-w #592
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -33,6 +33,7 @@ angular.module('client').controller('clientController', ['$scope', '$routeParams | |||||
|
||||||
// Required services | ||||||
var $location = $injector.get('$location'); | ||||||
var $window = $injector.get('$window'); | ||||||
var authenticationService = $injector.get('authenticationService'); | ||||||
var connectionGroupService = $injector.get('connectionGroupService'); | ||||||
var clipboardService = $injector.get('clipboardService'); | ||||||
|
@@ -219,6 +220,26 @@ angular.module('client').controller('clientController', ['$scope', '$routeParams | |||||
remaining: 15 | ||||||
}; | ||||||
|
||||||
/** | ||||||
* Catch window or tab closing (ctrl-w) and prompt the user if there is an active connection | ||||||
* | ||||||
* @param {Event} e | ||||||
* @returns {undefined} | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this function returns nothing, there's no need to include an |
||||||
*/ | ||||||
var windowCloseListener = function onBeforeUnload(e) { | ||||||
var managedClient = $scope.client; | ||||||
if (managedClient) { | ||||||
|
||||||
// Get current connection state | ||||||
var connectionState = managedClient.clientState.connectionState; | ||||||
|
||||||
// If connected, prompt to close | ||||||
if (connectionState === ManagedClientState.ConnectionState.CONNECTED) | ||||||
e.preventDefault(); | ||||||
e.returnValue = ''; | ||||||
necouchman marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
} | ||||||
}; | ||||||
|
||||||
/** | ||||||
* Menu-specific properties. | ||||||
*/ | ||||||
|
@@ -776,6 +797,8 @@ angular.module('client').controller('clientController', ['$scope', '$routeParams | |||||
|
||||||
// Client error | ||||||
else if (connectionState === ManagedClientState.ConnectionState.CLIENT_ERROR) { | ||||||
// Stop intercepting window close | ||||||
$window.removeEventListener('beforeunload', ctrlwlistener, false); | ||||||
phreakocious marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
// Determine translation name of error | ||||||
var errorName = (status in CLIENT_ERRORS) ? status.toString(16).toUpperCase() : "DEFAULT"; | ||||||
|
@@ -798,7 +821,6 @@ angular.module('client').controller('clientController', ['$scope', '$routeParams | |||||
|
||||||
// Tunnel error | ||||||
else if (connectionState === ManagedClientState.ConnectionState.TUNNEL_ERROR) { | ||||||
|
||||||
// Determine translation name of error | ||||||
var errorName = (status in TUNNEL_ERRORS) ? status.toString(16).toUpperCase() : "DEFAULT"; | ||||||
|
||||||
|
@@ -831,6 +853,8 @@ angular.module('client').controller('clientController', ['$scope', '$routeParams | |||||
|
||||||
// Hide status and sync local clipboard once connected | ||||||
else if (connectionState === ManagedClientState.ConnectionState.CONNECTED) { | ||||||
// Start intercepting ctrl-w / window close | ||||||
$window.addEventListener('beforeunload', windowCloseListener, false); | ||||||
Comment on lines
+856
to
+857
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this will be problematic. Since the event listener is being added conditionally depending on whether the current client has connected (and removing it upon error), there will be issues if:
I think this instead needs to be at the root level, outside the handling of a connection. If there were a single
In fact, guacamole-client/guacamole/src/main/webapp/app/client/services/guacClientManager.js Lines 164 to 165 in 0091bb1
Perhaps it would make sense for it to handle |
||||||
|
||||||
// Sync with local clipboard | ||||||
clipboardService.getLocalClipboard().then(function clipboardRead(data) { | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add documentation for parameters accepted by functions.