Skip to content

Commit 0065a7c

Browse files
committed
Remove IsScreenReaderActive() check
With the upcoming inclusion of PSReadLine 2.4, screen readers are now properly supported.
1 parent d8b1cc5 commit 0065a7c

File tree

2 files changed

+12
-54
lines changed

2 files changed

+12
-54
lines changed

src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs

Lines changed: 9 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1680,35 +1680,6 @@ private void CreateRunspace(RunspaceCreationEventArgs runspaceCreationArgs)
16801680
}
16811681
}
16821682

1683-
/// <summary>
1684-
/// Check if a screen reviewer utility is running.
1685-
/// When a screen reader is running, we don't auto-load the PSReadLine module at startup,
1686-
/// since PSReadLine is not accessibility-friendly enough as of today.
1687-
/// </summary>
1688-
private bool IsScreenReaderActive()
1689-
{
1690-
if (_screenReaderActive.HasValue)
1691-
{
1692-
return _screenReaderActive.Value;
1693-
}
1694-
1695-
_screenReaderActive = false;
1696-
if (Platform.IsWindowsDesktop)
1697-
{
1698-
// Note: this API can detect if a third-party screen reader is active, such as NVDA, but not the in-box Windows Narrator.
1699-
// Quoted from https://learn.microsoft.com/windows/win32/api/winuser/nf-winuser-systemparametersinfoa about the
1700-
// accessibility parameter 'SPI_GETSCREENREADER':
1701-
// "Narrator, the screen reader that is included with Windows, does not set the SPI_SETSCREENREADER or SPI_GETSCREENREADER flags."
1702-
bool enabled = false;
1703-
if (SystemParametersInfo(SPI_GETSCREENREADER, 0, ref enabled, 0))
1704-
{
1705-
_screenReaderActive = enabled;
1706-
}
1707-
}
1708-
1709-
return _screenReaderActive.Value;
1710-
}
1711-
17121683
private static bool LoadPSReadline()
17131684
{
17141685
// Don't load PSReadline if:
@@ -1759,7 +1730,6 @@ private void DoCreateRunspace(RunspaceCreationEventArgs args)
17591730
bool psReadlineFailed = false;
17601731

17611732
// Load PSReadline by default unless there is no use:
1762-
// - screen reader is active, such as NVDA, indicating non-visual access
17631733
// - we're running a command/file and just exiting
17641734
// - stdin is redirected by a parent process
17651735
// - we're not interactive
@@ -1770,26 +1740,18 @@ private void DoCreateRunspace(RunspaceCreationEventArgs args)
17701740
ReadOnlyCollection<ModuleSpecification> defaultImportModulesList = null;
17711741
if (!customConfigurationProvided && LoadPSReadline())
17721742
{
1773-
if (IsScreenReaderActive())
1743+
// Create and open Runspace with PSReadline.
1744+
defaultImportModulesList = DefaultInitialSessionState.Modules;
1745+
DefaultInitialSessionState.ImportPSModule(new[] { "PSReadLine" });
1746+
consoleRunspace = RunspaceFactory.CreateRunspace(this, DefaultInitialSessionState);
1747+
try
17741748
{
1775-
s_theConsoleHost.UI.WriteLine(ManagedEntranceStrings.PSReadLineDisabledWhenScreenReaderIsActive);
1776-
s_theConsoleHost.UI.WriteLine();
1749+
OpenConsoleRunspace(consoleRunspace, args.StaMode);
17771750
}
1778-
else
1751+
catch (Exception)
17791752
{
1780-
// Create and open Runspace with PSReadline.
1781-
defaultImportModulesList = DefaultInitialSessionState.Modules;
1782-
DefaultInitialSessionState.ImportPSModule(new[] { "PSReadLine" });
1783-
consoleRunspace = RunspaceFactory.CreateRunspace(this, DefaultInitialSessionState);
1784-
try
1785-
{
1786-
OpenConsoleRunspace(consoleRunspace, args.StaMode);
1787-
}
1788-
catch (Exception)
1789-
{
1790-
consoleRunspace = null;
1791-
psReadlineFailed = true;
1792-
}
1753+
consoleRunspace = null;
1754+
psReadlineFailed = true;
17931755
}
17941756
}
17951757

@@ -3102,7 +3064,6 @@ private sealed class ConsoleHostStartupException : Exception
31023064
private bool _setShouldExitCalled;
31033065
private bool _isRunningPromptLoop;
31043066
private bool _wasInitialCommandEncoded;
3105-
private bool? _screenReaderActive;
31063067

31073068
// hostGlobalLock is used to sync public method calls (in case multiple threads call into the host) and access to
31083069
// state that persists across method calls, like progress data. It's internal because the ui object also

src/Microsoft.PowerShell.ConsoleHost/resources/ManagedEntranceStrings.resx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,6 @@
132132
<data name="ShellBannerRLMode" xml:space="preserve">
133133
<value>[Restricted Language Mode]</value>
134134
</data>
135-
<data name="PSReadLineDisabledWhenScreenReaderIsActive" xml:space="preserve">
136-
<value>Warning: PowerShell detected that you might be using a screen reader and has disabled PSReadLine for compatibility purposes. If you want to re-enable it, run 'Import-Module PSReadLine'.</value>
137-
</data>
138135
<data name="PreviewUpdateNotificationMessage" xml:space="preserve">
139136
<value> {1} A new PowerShell preview release is available: v{0} {2}
140137
{1} Upgrade now, or check out the release page at:{3}{2}
@@ -162,9 +159,9 @@
162159
[-CustomPipeName &lt;string&gt;] [-EncodedCommand &lt;Base64EncodedCommand&gt;]
163160
[-ExecutionPolicy &lt;ExecutionPolicy&gt;] [-InputFormat {Text | XML}]
164161
[-Interactive] [-MTA] [-NoExit] [-NoLogo] [-NonInteractive] [-NoProfile]
165-
[-NoProfileLoadTime] [-OutputFormat {Text | XML}]
166-
[-SettingsFile &lt;filePath&gt;] [-SSHServerMode] [-STA]
167-
[-Version] [-WindowStyle &lt;style&gt;]
162+
[-NoProfileLoadTime] [-OutputFormat {Text | XML}]
163+
[-SettingsFile &lt;filePath&gt;] [-SSHServerMode] [-STA]
164+
[-Version] [-WindowStyle &lt;style&gt;]
168165
[-WorkingDirectory &lt;directoryPath&gt;]
169166

170167
pwsh[.exe] -h | -Help | -? | /?

0 commit comments

Comments
 (0)