-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Remove IsScreenReaderActive() check
#26118
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
Merged
daxian-dbw
merged 2 commits into
PowerShell:master
from
andyleejordan:remove-screenreader-check
Sep 30, 2025
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -54,16 +54,11 @@ internal sealed partial class ConsoleHost | |
| internal const int ExitCodeCtrlBreak = 128 + 21; // SIGBREAK | ||
| internal const int ExitCodeInitFailure = 70; // Internal Software Error | ||
| internal const int ExitCodeBadCommandLineParameter = 64; // Command Line Usage Error | ||
| private const uint SPI_GETSCREENREADER = 0x0046; | ||
| #if UNIX | ||
| internal const string DECCKM_ON = "\x1b[?1h"; | ||
| internal const string DECCKM_OFF = "\x1b[?1l"; | ||
| #endif | ||
|
|
||
| [DllImport("user32.dll", SetLastError = true)] | ||
| [return: MarshalAs(UnmanagedType.Bool)] | ||
| private static extern bool SystemParametersInfo(uint uiAction, uint uiParam, ref bool pvParam, uint fWinIni); | ||
|
|
||
| /// <summary> | ||
| /// Internal Entry point in msh console host implementation. | ||
| /// </summary> | ||
|
|
@@ -1680,35 +1675,6 @@ private void CreateRunspace(RunspaceCreationEventArgs runspaceCreationArgs) | |
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Check if a screen reviewer utility is running. | ||
| /// When a screen reader is running, we don't auto-load the PSReadLine module at startup, | ||
| /// since PSReadLine is not accessibility-friendly enough as of today. | ||
| /// </summary> | ||
| private bool IsScreenReaderActive() | ||
| { | ||
| if (_screenReaderActive.HasValue) | ||
| { | ||
| return _screenReaderActive.Value; | ||
| } | ||
|
|
||
| _screenReaderActive = false; | ||
| if (Platform.IsWindowsDesktop) | ||
| { | ||
| // Note: this API can detect if a third-party screen reader is active, such as NVDA, but not the in-box Windows Narrator. | ||
| // Quoted from https://learn.microsoft.com/windows/win32/api/winuser/nf-winuser-systemparametersinfoa about the | ||
| // accessibility parameter 'SPI_GETSCREENREADER': | ||
| // "Narrator, the screen reader that is included with Windows, does not set the SPI_SETSCREENREADER or SPI_GETSCREENREADER flags." | ||
| bool enabled = false; | ||
| if (SystemParametersInfo(SPI_GETSCREENREADER, 0, ref enabled, 0)) | ||
| { | ||
| _screenReaderActive = enabled; | ||
| } | ||
| } | ||
|
|
||
| return _screenReaderActive.Value; | ||
| } | ||
|
|
||
| private static bool LoadPSReadline() | ||
| { | ||
| // Don't load PSReadline if: | ||
|
|
@@ -1759,7 +1725,6 @@ private void DoCreateRunspace(RunspaceCreationEventArgs args) | |
| bool psReadlineFailed = false; | ||
|
|
||
| // Load PSReadline by default unless there is no use: | ||
| // - screen reader is active, such as NVDA, indicating non-visual access | ||
| // - we're running a command/file and just exiting | ||
| // - stdin is redirected by a parent process | ||
| // - we're not interactive | ||
|
|
@@ -1770,26 +1735,18 @@ private void DoCreateRunspace(RunspaceCreationEventArgs args) | |
| ReadOnlyCollection<ModuleSpecification> defaultImportModulesList = null; | ||
| if (!customConfigurationProvided && LoadPSReadline()) | ||
| { | ||
| if (IsScreenReaderActive()) | ||
| // Create and open Runspace with PSReadline. | ||
| defaultImportModulesList = DefaultInitialSessionState.Modules; | ||
| DefaultInitialSessionState.ImportPSModule(new[] { "PSReadLine" }); | ||
| consoleRunspace = RunspaceFactory.CreateRunspace(this, DefaultInitialSessionState); | ||
| try | ||
| { | ||
| s_theConsoleHost.UI.WriteLine(ManagedEntranceStrings.PSReadLineDisabledWhenScreenReaderIsActive); | ||
| s_theConsoleHost.UI.WriteLine(); | ||
| OpenConsoleRunspace(consoleRunspace, args.StaMode); | ||
| } | ||
| else | ||
| catch (Exception) | ||
| { | ||
| // Create and open Runspace with PSReadline. | ||
| defaultImportModulesList = DefaultInitialSessionState.Modules; | ||
| DefaultInitialSessionState.ImportPSModule(new[] { "PSReadLine" }); | ||
| consoleRunspace = RunspaceFactory.CreateRunspace(this, DefaultInitialSessionState); | ||
| try | ||
| { | ||
| OpenConsoleRunspace(consoleRunspace, args.StaMode); | ||
| } | ||
| catch (Exception) | ||
| { | ||
| consoleRunspace = null; | ||
| psReadlineFailed = true; | ||
| } | ||
| consoleRunspace = null; | ||
|
Collaborator
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 wonder why don't we dispose the runspace?
Member
Author
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. That's a question I don't have an answer to. |
||
| psReadlineFailed = true; | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -3102,7 +3059,6 @@ private sealed class ConsoleHostStartupException : Exception | |
| private bool _setShouldExitCalled; | ||
| private bool _isRunningPromptLoop; | ||
| private bool _wasInitialCommandEncoded; | ||
| private bool? _screenReaderActive; | ||
|
|
||
| // hostGlobalLock is used to sync public method calls (in case multiple threads call into the host) and access to | ||
| // state that persists across method calls, like progress data. It's internal because the ui object also | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.