Skip to content

Commit 80e3683

Browse files
committed
Revert to system parameter screen reader check on Windows
That algorithm doesn't work for a non-windowed app like PowerShell.
1 parent cfed451 commit 80e3683

File tree

2 files changed

+17
-49
lines changed

2 files changed

+17
-49
lines changed

PSReadLine/Accessibility.cs

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -22,38 +22,28 @@ internal static bool IsScreenReaderActive()
2222
}
2323

2424
private static bool IsAnyWindowsScreenReaderEnabled() {
25-
// The supposedly official way to check for a screen reader on
26-
// Windows is SystemParametersInfo(SPI_GETSCREENREADER, ...) but it
27-
// doesn't detect the in-box Windows Narrator and is otherwise known
28-
// to be problematic.
25+
// The official way to check for a screen reader on Windows is
26+
// SystemParametersInfo(SPI_GETSCREENREADER, ...) but it doesn't
27+
// detect the in-box Windows Narrator and is otherwise known to be
28+
// problematic.
2929
//
30-
// The following is adapted from the Electron project, under the MIT License.
31-
// Hence this is also how VS Code detects screenreaders.
32-
// See: https://github.com/electron/electron/pull/39988
30+
// Unfortunately, the alternative method used by Electron and
31+
// Chromium, where the relevant screen reader libraries (modules)
32+
// are checked for does not work in the context of PowerShell
33+
// because it relies on those applications injecting themselves into
34+
// the app. Which they do not because it's not a windowed app, so
35+
// we're stuck using the known-to-be-buggy way.
36+
bool spiScreenReader = false;
37+
PlatformWindows.SystemParametersInfo(PlatformWindows.SPI_GETSCREENREADER, 0, ref spiScreenReader, 0);
38+
if (spiScreenReader)
39+
return true;
3340

34-
// Check for Windows Narrator using the NarratorRunning mutex
41+
// At least we can correctly check for Windows Narrator using the
42+
// NarratorRunning mutex (which is mostly not broken with
43+
// PSReadLine, as it were).
3544
if (PlatformWindows.IsMutexPresent("NarratorRunning"))
3645
return true;
3746

38-
// Check for various screen reader libraries
39-
string[] screenReaderLibraries = {
40-
// NVDA
41-
"nvdaHelperRemote.dll",
42-
// JAWS
43-
"jhook.dll",
44-
// Window-Eyes
45-
"gwhk64.dll",
46-
"gwmhook.dll",
47-
// ZoomText
48-
"AiSquared.Infuser.HookLib.dll"
49-
};
50-
51-
foreach (string library in screenReaderLibraries)
52-
{
53-
if (PlatformWindows.IsLibraryLoaded(library))
54-
return true;
55-
}
56-
5747
return false;
5848
}
5949

PSReadLine/PlatformWindows.cs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -92,28 +92,6 @@ internal static bool IsMutexPresent(string name)
9292
}
9393
}
9494

95-
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
96-
[return: MarshalAs(UnmanagedType.Bool)]
97-
internal static extern bool GetModuleHandleEx(uint dwFlags, string lpModuleName, out IntPtr phModule);
98-
99-
internal static bool IsLibraryLoaded(string name)
100-
{
101-
// Prevents the reference count for the module being incremented.
102-
const uint GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT = 0x00000002;
103-
try
104-
{
105-
bool retValue = GetModuleHandleEx(
106-
GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
107-
name,
108-
out IntPtr phModule);
109-
return phModule != IntPtr.Zero;
110-
}
111-
catch
112-
{
113-
return false;
114-
}
115-
}
116-
11795
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
11896
static extern bool SetConsoleCtrlHandler(BreakHandler handlerRoutine, bool add);
11997

0 commit comments

Comments
 (0)