Skip to content

Commit

Permalink
NVDAControlEx: Try fix nvda_active.
Browse files Browse the repository at this point in the history
  • Loading branch information
m1maker committed Feb 8, 2025
1 parent 6b17986 commit e218672
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions Dep/nvda_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ void nvda_disconnect(HANDLE hPipe) {
// Sends a command to the NVDA named pipe
int nvda_send_command(HANDLE hPipe, const char* command) {
if (hPipe == INVALID_HANDLE_VALUE) {
return -1;
hPipe = nvda_connect(); // Reconnect if the pipe is invalid
if (hPipe == INVALID_HANDLE_VALUE) {
return -1;
}
}

DWORD bytesWritten;
Expand All @@ -42,6 +45,9 @@ int nvda_send_command(HANDLE hPipe, const char* command) {
);

if (!result) {
// If the write fails, close the pipe and reconnect
nvda_disconnect(hPipe);
hPipe = INVALID_HANDLE_VALUE;
return -1;
}

Expand Down Expand Up @@ -90,9 +96,7 @@ int nvda_braille(HANDLE hPipe, const char* text) {

// Sends an "active" command to NVDA
int nvda_active(HANDLE hPipe) {
DWORD instances;
GetNamedPipeHandleState(hPipe, NULL, &instances, NULL, NULL, NULL, 0);
return instances > 0 ? 0 : -1;
return nvda_send_command(hPipe, "active");
}

#ifdef __cplusplus
Expand Down

0 comments on commit e218672

Please sign in to comment.