Skip to content

Commit edce599

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 a6dc616 commit edce599

File tree

2 files changed

+17
-45
lines changed

2 files changed

+17
-45
lines changed

PSReadLine/Accessibility.cs

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

2424
// TODO: Support Linux per https://code.visualstudio.com/docs/configure/accessibility/accessibility
25-
return false;
25+
return false;
2626
}
2727

2828
private static bool IsAnyWindowsScreenReaderEnabled()
@@ -32,31 +32,25 @@ private static bool IsAnyWindowsScreenReaderEnabled()
3232
// doesn't detect the in-box Windows Narrator and is otherwise known
3333
// to be problematic.
3434
//
35-
// The following is adapted from the Electron project, under the MIT License.
36-
// Hence this is also how VS Code detects screenreaders.
37-
// See: https://github.com/electron/electron/pull/39988
38-
39-
// Check for Windows Narrator using the NarratorRunning mutex
40-
if (PlatformWindows.IsMutexPresent("NarratorRunning"))
35+
// Unfortunately, the alternative method used by Electron and
36+
// Chromium, where the relevant screen reader libraries (modules)
37+
// are checked for does not work in the context of PowerShell
38+
// because it relies on those applications injecting themselves into
39+
// the app. Which they do not because it's not a windowed app, so
40+
// we're stuck using the known-to-be-buggy way.
41+
bool spiScreenReader = false;
42+
PlatformWindows.SystemParametersInfo(PlatformWindows.SPI_GETSCREENREADER, 0, ref spiScreenReader, 0);
43+
if (spiScreenReader)
44+
{
4145
return true;
46+
}
4247

43-
// Check for various screen reader libraries
44-
string[] screenReaderLibraries = {
45-
// NVDA
46-
"nvdaHelperRemote.dll",
47-
// JAWS
48-
"jhook.dll",
49-
// Window-Eyes
50-
"gwhk64.dll",
51-
"gwmhook.dll",
52-
// ZoomText
53-
"AiSquared.Infuser.HookLib.dll"
54-
};
55-
56-
foreach (string library in screenReaderLibraries)
48+
// At least we can correctly check for Windows Narrator using the
49+
// NarratorRunning mutex (which is mostly not broken with
50+
// PSReadLine, as it were).
51+
if (PlatformWindows.IsMutexPresent("NarratorRunning"))
5752
{
58-
if (PlatformWindows.IsLibraryLoaded(library))
59-
return true;
53+
return true;
6054
}
6155

6256
return false;

PSReadLine/PlatformWindows.cs

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

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

0 commit comments

Comments
 (0)