Skip to content

Commit 00a2be6

Browse files
committed
Turn back to one named pipe on Windows to simplify things
1 parent 3279bdb commit 00a2be6

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

src/main/java/org/keepassxc/WindowsConnection.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ public class WindowsConnection extends Connection {
1515

1616
private static final Logger log = LoggerFactory.getLogger(WindowsConnection.class);
1717

18-
private RandomAccessFile readPipe;
19-
private RandomAccessFile writePipe;
18+
private RandomAccessFile pipe;
2019

2120
/**
2221
* Connect to the KeePassXC proxy via a Windows named pipe the proxy has opened.
@@ -26,9 +25,7 @@ public class WindowsConnection extends Connection {
2625
@Override
2726
public void connect() throws IOException {
2827
try {
29-
readPipe = new RandomAccessFile("\\\\.\\pipe\\" + PROXY_NAME + "_" + System.getenv("USERNAME"),
30-
"r");
31-
writePipe = new RandomAccessFile("\\\\.\\pipe\\" + PROXY_NAME + "_" + System.getenv("USERNAME"),
28+
pipe = new RandomAccessFile("\\\\.\\pipe\\" + PROXY_NAME + "_" + System.getenv("USERNAME"),
3229
"rw");
3330
} catch (FileNotFoundException e) {
3431
log.error("Cannot connect to proxy. Is KeepassXC started?");
@@ -45,7 +42,7 @@ public void connect() throws IOException {
4542
@Override
4643
protected void sendCleartextMessage(String msg) throws IOException {
4744
log.trace("Sending message: {}", msg);
48-
writePipe.write(msg.getBytes(StandardCharsets.UTF_8));
45+
pipe.write(msg.getBytes(StandardCharsets.UTF_8));
4946
}
5047

5148
@Override
@@ -54,7 +51,7 @@ protected JSONObject getCleartextResponse() {
5451
var raw = "";
5552
do {
5653
try {
57-
c = readPipe.read();
54+
c = pipe.read();
5855
raw += (char) c;
5956
} catch (IOException e) {
6057
log.error(e.toString(), e.getCause());
@@ -72,14 +69,13 @@ protected JSONObject getCleartextResponse() {
7269

7370
@Override
7471
protected boolean isConnected() {
75-
return null != readPipe && null != writePipe;
72+
return null != pipe;
7673
}
7774

7875
@Override
7976
public void close() throws Exception {
8077
messagePublisher.doStop();
8178
executorService.shutdown();
82-
readPipe.close();
83-
writePipe.close();
79+
pipe.close();
8480
}
8581
}

0 commit comments

Comments
 (0)