Skip to content

Fix open of Contributors and License Help menu options on Windows 11 #14816

Merged
seanbudd merged 4 commits into
nvaccess:masterfrom
XLTechie:fix14725
Apr 18, 2023
Merged

Fix open of Contributors and License Help menu options on Windows 11 #14816
seanbudd merged 4 commits into
nvaccess:masterfrom
XLTechie:fix14725

Conversation

@XLTechie

@XLTechie XLTechie commented Apr 10, 2023

Copy link
Copy Markdown
Collaborator

Link to issue number:

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.

Change log entries:

Bug fixes
In Windows 11, it is (once again) possible to open the Contributors and License items on the NVDA Help menu.

Code Review Checklist:

  • Pull Request description:
    • description is up to date
    • change log entries
  • Testing:
    • Unit tests
    • System (end to end) tests
    • Manual testing
  • API is compatible with existing add-ons.
  • Documentation:
    • User Documentation
    • Developer / Technical Documentation
    • Context sensitive help for GUI changes
  • UX of all users considered:
    • Speech
    • Braille
    • Low Vision
    • Different web browsers
    • Localization in other languages / culture than English
  • Security precautions taken.

@XLTechie XLTechie marked this pull request as ready for review April 10, 2023 06:20
@XLTechie XLTechie requested a review from a team as a code owner April 10, 2023 06:20
@XLTechie XLTechie requested a review from seanbudd April 10, 2023 06:20
@AppVeyorBot

Copy link
Copy Markdown

See test results for failed build of commit c64df92087

Comment thread source/gui/__init__.py Outdated
@Brian1Gaff

Brian1Gaff commented Apr 10, 2023 via email

Copy link
Copy Markdown

@XLTechie

Copy link
Copy Markdown
Collaborator Author

@seanbudd PR description updated; new function created; a couple little unrelated odds and ends fixed. Ready for re-review.

@XLTechie

Copy link
Copy Markdown
Collaborator Author

@lukaszgo1 Regarding your request to put this in a public function so that add-ons can use it:

It turns out, according to this mailing list post, that it would not have worked anyway. Evidently, the operation="edit" fix, only works for files under "Program Files" directories.

@Brian1Gaff

Brian1Gaff commented Apr 11, 2023 via email

Copy link
Copy Markdown

@seanbudd seanbudd left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I've noticed more discussion in the mailing list thread

Does this fix still work correctly? What if NVDA is running as a portable copy outside program files?

Copy file "copying.txt" to "c:"
and in the console, execute the command "os.startfile(r"C:\copying.txt", operation="edit").
The error occurs.
Now copy the same file to "c:\Program files (x86)" and run the command:
os.startfile(r"C:\Program Files (x86)\copying.txt", operation="edit").

Comment thread source/systemUtils.py Outdated
Comment thread source/systemUtils.py Outdated
…systems. (#14816)

Per #14725, Windows 11 can't open text files in Notepad with os.startfile's default operation.
- 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.
@XLTechie

XLTechie commented Apr 13, 2023

Copy link
Copy Markdown
Collaborator Author

@seanbudd The tests you requested have been done by @britechguy, and I have updated the description with the results. The original problem didn't exist for portable copies as far as anyone reported, so we hadn't tested that exhaustively before.

Other than that, I have moved the comments inside the def (because PEP-8 said so); the commit text should be good as-is; and the questionable side-lints have been withdrawn.

@XLTechie

Copy link
Copy Markdown
Collaborator Author

@seanbudd GTG

Comment thread source/systemUtils.py Outdated
@seanbudd seanbudd merged commit dc60282 into nvaccess:master Apr 18, 2023
@nvaccessAuto nvaccessAuto added this to the 2023.2 milestone Apr 18, 2023
@seanbudd

Copy link
Copy Markdown
Member

Thanks @XLTechie

@XLTechie XLTechie deleted the fix14725 branch April 18, 2023 09:05
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.

Contributors file do not open

6 participants