Fix open of Contributors and License Help menu options on Windows 11 (#14816)
Fixes #14725
Summary of the issue:
Under Windows 11, attempting to open the NVDA Help menu items "Contributors" or "License", results in Notepad trying to open nonsense filenames while using installed, normal user level, copies of NVDA
Through testing, this has been narrowed to a bug in os.startfile in Python 3.7 as invoked on Windows 11, though the actual bug may be in a lower level library. The bug does not seem to occur when using the commandline "start" command.
It also does not occur in portable or admin level copies of NVDA.
Description of user facing changes
Restores the ability to open the Contributors List or License file from the NVDA Help menu.
Description of development approach
Through testing, I and @britechguy were able to narrow the source of the errors, and determine that attempting to open the file for editing, rather than by trusting the Windows open file association for .txt files, would open these files in Notepad correctly.
Taken from the text of the commit:
Added the _displayTextFileWorkaround function to the systemUtils module.
Called it wherever os.startfile was opening a .txt file in gui/__init__.py.
The function uses os.startfile's "edit" operation to open the text file, which still uses Notepad, at least on most systems.
Additionally:
gui.MainFrame was importing systemUtils late, in init, and onRunCOMRegistrationFixesCommand.
Moved to a single import in top section.
Testing strategy:
Manual testing with 2023.1's Python console, that calling os.startfile as described, opens these files correctly under Windows 11. While calling it the standard way from the Python console, results in nonsense filenames being delivered to Notepad, and the subsequent failure of the task.
Using a try build of this PR, tested opening these help menu items on Windows 10, with expected success.
Tested that installing a try build of this PR on Windows 11, could open the files from the menu, and could open a copy of copying.txt at the root of the system drive, using the Python console.
A portable copy generated from this PR, placed in the root directory of a USB stick, could open its included text files from the Help menu, and could open a copy of copying.txt placed at the root of the USB drive.
Additionally, to confirm that consolidating and moving the imports of systemUtils didn't break anything, I tested that NVDA launched, and the COM Registration Fixing Tool still works, under Windows 10, which is sufficient.
Tested on:
Windows 11: 22H2, build 22621.1555
Windows 10: 22H2, build 19045.2846
Known issues with pull request:
It is not necessary to use operation="edit" under Windows 10. Since this seemed (1) rather harmless, and (2) a low impact bug, I didn't think it was necessary to test for Windows version before deciding which call structure to use for the new function.
It is conceivable, that opening for editing will have side effects on some systems. However, since it seems reasonable to presume that a user who has made editing text files open in some other program than Notepad is quite experienced, I thought the negative potential here was rather low to non-existent.
When we migrate to a newer Python version, the necessity of this workaround should be reevaluated, as hopefully this will be fixed by a newer library.