Skip to content

Commit

Permalink
Stop listening on printers properly
Browse files Browse the repository at this point in the history
  • Loading branch information
tresf committed Nov 26, 2024
1 parent 326f296 commit bde79b5
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/qz/printer/status/StatusMonitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,19 +134,19 @@ public synchronized static void sendStatuses(SocketConnection connection) {
ArrayList<Status> statuses = isWindows() ? WmiPrinterStatusThread.getAllStatuses(): CupsUtils.getAllStatuses();

// First check if we're listening on all printers for this connection
List<SocketConnection> allPrinters = clientPrinterConnections.get(ALL_PRINTERS);
if (allPrinters != null) {
sendForAllPrinters = allPrinters.contains(connection);
List<SocketConnection> connections = clientPrinterConnections.get(ALL_PRINTERS);
if (connections != null) {
sendForAllPrinters = connections.contains(connection);
}

for (Status status : statuses) {
if (sendForAllPrinters) {
statusSessions.get(connection).statusChanged(status, () -> allPrinters.remove(connection));
statusSessions.get(connection).statusChanged(status, () -> stopListening(connection));
} else {
// Only send the status of the printers requested
List<SocketConnection> thisPrinter = clientPrinterConnections.get(status.getPrinter());
if ((thisPrinter != null) && thisPrinter.contains(connection)) {
statusSessions.get(connection).statusChanged(status, () -> thisPrinter.remove(connection));
connections = clientPrinterConnections.get(status.getPrinter());
if ((connections != null) && connections.contains(connection)) {
statusSessions.get(connection).statusChanged(status, () -> stopListening(connection));
}
}
}
Expand Down Expand Up @@ -210,7 +210,7 @@ private synchronized static boolean dispatchStatusEvent() {

// Notify each client subscription
for(SocketConnection connection : listeningConnections) {
statusSessions.get(connection).statusChanged(status, () -> statusSessions.remove(connection));
statusSessions.get(connection).statusChanged(status, () -> stopListening(connection));
}

return true;
Expand Down

0 comments on commit bde79b5

Please sign in to comment.