Skip to content

refactor the exit of nvda and gui.terminate#12342

Merged
seanbudd merged 3 commits into
masterfrom
cleanup-exit
May 7, 2021
Merged

refactor the exit of nvda and gui.terminate#12342
seanbudd merged 3 commits into
masterfrom
cleanup-exit

Conversation

@seanbudd

@seanbudd seanbudd commented Apr 27, 2021

Copy link
Copy Markdown
Member

Link to issue number:

Closes #12238, #12325

Changes

Summary of the issue:

PR #12286 Introduced the following issues:

  • Logging via prints caused a wx error dialog to appear in binary builds. This is confusing, but is also seeming to freeze up the Windows shell, or at very least, NVDA is struggling to read much after this occurs.
  • Prevented the addon handler from properly closing addons
  • Added unnecessary wait time for exiting NVDA to check whether to send WM_QUIT after WM_EXIT_NVDA fails.

PR #12286 addressed:

When restarting NVDA, WM_QUIT is posted as an event to the window, forcibly exiting the app. This leaves objects such as the system tray icon left behind.

Additionally, changes introduced in #12183

  • caused the braille viewer to be closed without saving state properly
  • lost code that destroyed the system tray and menu in some instances
  • made most of gui.terminate no longer necessary/redundant

Description of how this pull request fixes the issue:

This PR:

  • Creates core.triggerNVDAExit which terminates necessary modules and then closes all windows
  • Uses a parser error message if an new NVDA instance fails to end a running instances.
  • Uses an enum for ChangeWindowMessageFilter filters.

PR #12286 addressed it's issues by:

  • A windows event winUser.WM_EXIT_NVDA is registered that triggers safeAppExit and can be called across instances of NVDA.
  • move the safe destruction of the brailleviewer to safeAppExit so that it is exited properly before destruction
  • reintroduce the destruction of the system tray icon and menu, and remove the icon manually.
  • ensured safeAppExit is not called from gui.terminate if it has been called elsewhere to terminate the app. WM_QUIT is the other way to exit the MainLoop other than safeAppExit
  • removed restarting the MainLoop in gui.terminate to process pending events as this doesn't work.

Testing strategy:

  • Ensure NVDA system tray icons are cleaned on any exit.
  • Ensure NVDA exits properly on restart and when starting the process subsequently. Check nvda-old.log when restarting NVDA.
  • Ensure NVDA can exit and restart correctly without errors or crashes. Existing system tests exist for this process.
  • Test these with the build binary for this branch as well as source
    • Running 2020.4 (leave it running) and start this build. This build should cause 2020.4 to exit, and this build should replace it as the running version. Confirm by checking about -> version
    • Running this build (leave it running) and start 2020.4 which should cause this build to exit, and 2020.4 should replace it as the running version. Confirm by checking about -> version
    • Running latest alpha (leave it running) and start this build. This build should cause latest alpha to exit, and this build should replace it as the running version. Confirm by checking about -> version
    • Running this build (leave it running) and start latest alpha which should cause this build to exit, and latest alpha should replace it as the running version. Confirm by checking about -> version

Known issues with pull request:

WM_QUIT will not exit the app safely (called from a new NVDA instance) when a dialog such as WelcomeDialog is still open

Change log entry:

None

Code Review Checklist:

  • Pull Request description is up to date.
  • Unit tests.
  • System (end to end) tests.
  • Manual tests.
  • User Documentation.
  • Change log entry.
  • Context sensitive help for GUI changes.

@seanbudd seanbudd requested a review from a team as a code owner April 27, 2021 01:24
@seanbudd seanbudd requested a review from michaelDCurran April 27, 2021 01:24
@seanbudd seanbudd changed the title Cleanup exit refactor the exit of nvda and gui.terminate Apr 27, 2021
@seanbudd seanbudd requested a review from feerrenrut April 27, 2021 01:35
@seanbudd seanbudd self-assigned this Apr 27, 2021
@seanbudd seanbudd added this to the 2021.1 milestone Apr 27, 2021

@lukaszgo1 lukaszgo1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Aside from one comment about raising WinError below this looks pretty nice. I am no longer able to reproduce crashes I've been experiencing with the previous implementation.

Comment thread source/winUser.py Outdated

@LeonarddeR LeonarddeR left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I have two concerns with the current code:

  1. It introduces logic to the winUser module. winUser historically was meant to wrap user32.dll functions, now there's NVDA specific stuff leaking into it. I'd like to suggest moving this to another module, windowUtils for example, though a separate module in the gui could also be considered.
  2. Please avoid registering the window message at the top level of a module, which will always register the message when the module is imported. This means it will try to register the message when linting, for example.

@seanbudd

Copy link
Copy Markdown
Member Author

I have two concerns with the current code:

  1. It introduces logic to the winUser module. winUser historically was meant to wrap user32.dll functions, now there's NVDA specific stuff leaking into it. I'd like to suggest moving this to another module, windowUtils for example, though a separate module in the gui could also be considered.
  2. Please avoid registering the window message at the top level of a module, which will always register the message when the module is imported. This means it will try to register the message when linting, for example.

We've addressed this in favour of reverting using this custom windows message, as it's not necessary to fix the bug and this otherwise blocks the release.

Comment thread source/nvda.pyw Outdated
@AppVeyorBot

Copy link
Copy Markdown

See test results for failed build of commit 6bf2942c42

Comment thread source/gui/__init__.py
Comment thread source/core.py
Comment thread source/gui/__init__.py Outdated
Comment thread source/nvda.pyw Outdated
@seanbudd seanbudd marked this pull request as draft April 30, 2021 05:15
@seanbudd seanbudd marked this pull request as ready for review May 3, 2021 03:54
@seanbudd seanbudd requested a review from feerrenrut May 3, 2021 23:14

@feerrenrut feerrenrut left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks @seanbudd

Comment thread source/core.py Outdated
preNVDAExit.unregister(handler)


def closeAllWindows():

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It seems like this should never be called directly, only via preNVDAExit Action. If so, please add a note to the doc string.

I also think this function name should be prefixed with an underscore, as a convention to signify their "protected" state. Typically anything that we don't want add-ons to use should be prefixed with an underscore (or in a class that is named that way).

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.

NVDA Alpha fails to clean its system tray icon after restart

6 participants