Skip to content
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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

phreakocious
Copy link

Unintentionally closing a guac tab with ctrl-w is a frequent complaint. This change prompts the user when closing the tab if there is an active connection.

Copy link
Contributor

@mike-jumper mike-jumper left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also read through our contribution guidelines when you can:

https://github.com/apache/guacamole-client/blob/65895aecdefecba94272065d5820db95e8322d1e/CONTRIBUTING

In particular, each change needs a corresponding JIRA issue, and that JIRA issue needs to be tagged in the commit message(s) following established convention. You can see examples of this in practice in our git history.

@phreakocious phreakocious changed the title prompt when closing the window/tab to avoid accidents with ctrl-w [GUACAMOLE-1292] prompt when closing the window/tab to avoid accidents with ctrl-w Feb 19, 2021
@phreakocious phreakocious changed the title [GUACAMOLE-1292] prompt when closing the window/tab to avoid accidents with ctrl-w GUACAMOLE-1292: prompt when closing the window/tab to avoid accidents with ctrl-w Feb 19, 2021
@phreakocious
Copy link
Author

Was there anything else you'd like altered?

Copy link
Contributor

@necouchman necouchman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One question/concern from me...

/**
* Catch window or tab closing (ctrl-w) and prompt the user if there is an active connection
*
* @param {Event} e
Copy link
Contributor

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.

* Catch window or tab closing (ctrl-w) and prompt the user if there is an active connection
*
* @param {Event} e
* @returns {undefined}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this function returns nothing, there's no need to include an @returns.

Comment on lines +856 to +857
// Start intercepting ctrl-w / window close
$window.addEventListener('beforeunload', windowCloseListener, false);
Copy link
Contributor

Choose a reason for hiding this comment

The 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:

  • The user navigates away from the client view (the client will remain active and connecting in the background, ready for the user to resume)
  • The user has multiple connections open within the same tab (they will fight over handling of beforeunload). Depending on whether the event handler is recognized as the same function by the event stack, this would result either in the connections removing each other's handlers or the connections adding multiple copies of the event handler.

I think this instead needs to be at the root level, outside the handling of a connection. If there were a single beforeunload event handler that is never removed, that handler could:

  1. Check whether any clients are present in the overall set of managed clients (this is exposed by the guacClientManager service).
  2. If there are clients, prompt. If there aren't, don't.

In fact, guacClientManager already handles unload:

// Disconnect all clients when window is unloaded
$window.addEventListener('unload', service.clear);

Perhaps it would make sense for it to handle beforeunload as well, and for that to be the sole instance of this event handler?

@mike-jumper
Copy link
Contributor

@phreakocious - FYI: looks like you inadvertently pushed a bunch of commits from master. Might need to rebase.

@phreakocious
Copy link
Author

@phreakocious - FYI: looks like you inadvertently pushed a bunch of commits from master. Might need to rebase.

Thanks for the heads up.

@necouchman
Copy link
Contributor

necouchman commented May 13, 2021

@phreakocious: One of your commits still lacks the GUACAMOLE-1292: prefix on it. Aside from that, not sure if @mike-jumper has any other concerns on this one...

@phreakocious
Copy link
Author

@phreakocious: One of your commits still lacks the GUACAMOLE-1292: prefix on it. Aside from that, not sure if @mike-jumper has any other concerns on this one...

It will likely be awhile before I'll have time to address the concerns raised in the last review. It did work to achieve the intended goal when I last tested it, but there could certainly be edge cases.

@necouchman
Copy link
Contributor

@phreakocious Thanks for letting us know. If it gets addressed prior to 1.4.0 release, great, otherwise we'll push it to the next release.

@webtroter
Copy link
Contributor

Hi,
I'm no developer, but I'm looking forward to that safety net. I already accidentally closed guacamole five times in the last hour.

I'm here to see if that issue can be reactivated.

@Cyberes
Copy link

Cyberes commented Jan 22, 2023

Just chiming in and voicing my support for this PR.

@necouchman
Copy link
Contributor

Thanks @Cyberes and @webtroter - at this point we're just waiting for the contributor to finish fixing up the requested items, or someone else to come along and for the changes and finish up the work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants