mirror of
https://github.com/aljazceru/signal-cli.git
synced 2025-12-26 10:34:23 +01:00
Implement close for DbusManagerImpl
This commit is contained in:
@@ -344,11 +344,11 @@ public class App {
|
||||
Command command, Signal ts, DBusConnection dBusConn, OutputWriter outputWriter
|
||||
) throws CommandException {
|
||||
if (command instanceof LocalCommand localCommand) {
|
||||
try {
|
||||
localCommand.handleCommand(ns, new DbusManagerImpl(ts, dBusConn), outputWriter);
|
||||
try (final var m = new DbusManagerImpl(ts, dBusConn)) {
|
||||
localCommand.handleCommand(ns, m, outputWriter);
|
||||
} catch (UnsupportedOperationException e) {
|
||||
throw new UserErrorException("Command is not yet implemented via dbus", e);
|
||||
} catch (DBusExecutionException e) {
|
||||
} catch (IOException | DBusExecutionException e) {
|
||||
throw new UnexpectedErrorException(e.getMessage(), e);
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -437,13 +437,7 @@ public class DbusManagerImpl implements Manager {
|
||||
synchronized (messageHandlers) {
|
||||
messageHandlers.remove(handler);
|
||||
if (messageHandlers.size() == 0) {
|
||||
try {
|
||||
connection.removeSigHandler(Signal.MessageReceivedV2.class, signal, this.dbusMsgHandler);
|
||||
connection.removeSigHandler(Signal.ReceiptReceivedV2.class, signal, this.dbusRcptHandler);
|
||||
connection.removeSigHandler(Signal.SyncMessageReceivedV2.class, signal, this.dbusSyncHandler);
|
||||
} catch (DBusException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
uninstallMessageHandlers();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -583,6 +577,13 @@ public class DbusManagerImpl implements Manager {
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
synchronized (this) {
|
||||
this.notify();
|
||||
}
|
||||
synchronized (messageHandlers) {
|
||||
messageHandlers.clear();
|
||||
uninstallMessageHandlers();
|
||||
}
|
||||
}
|
||||
|
||||
private SendMessageResults handleMessage(
|
||||
@@ -757,6 +758,16 @@ public class DbusManagerImpl implements Manager {
|
||||
}
|
||||
}
|
||||
|
||||
private void uninstallMessageHandlers() {
|
||||
try {
|
||||
connection.removeSigHandler(Signal.MessageReceivedV2.class, signal, this.dbusMsgHandler);
|
||||
connection.removeSigHandler(Signal.ReceiptReceivedV2.class, signal, this.dbusRcptHandler);
|
||||
connection.removeSigHandler(Signal.SyncMessageReceivedV2.class, signal, this.dbusSyncHandler);
|
||||
} catch (DBusException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private List<MessageEnvelope.Data.Attachment> getAttachments(final Map<String, Variant<?>> extras) {
|
||||
if (!extras.containsKey("attachments")) {
|
||||
return List.of();
|
||||
|
||||
Reference in New Issue
Block a user