X-Git-Url: https://git.nmode.ca/signal-cli/blobdiff_plain/af292d8f0ea897ea13470489d51c40acca50fc3e..a9a6edaf3ff8ac81b1229db294d738f624688a0d:/src/main/java/org/asamk/signal/commands/DaemonCommand.java diff --git a/src/main/java/org/asamk/signal/commands/DaemonCommand.java b/src/main/java/org/asamk/signal/commands/DaemonCommand.java index 49489293..02063b87 100644 --- a/src/main/java/org/asamk/signal/commands/DaemonCommand.java +++ b/src/main/java/org/asamk/signal/commands/DaemonCommand.java @@ -54,10 +54,10 @@ public class DaemonCommand implements MultiLocalCommand { public void handleCommand( final Namespace ns, final Manager m, final OutputWriter outputWriter ) throws CommandException { - boolean ignoreAttachments = ns.getBoolean("ignore-attachments"); + boolean ignoreAttachments = Boolean.TRUE.equals(ns.getBoolean("ignore-attachments")); DBusConnection.DBusBusType busType; - if (ns.getBoolean("system")) { + if (Boolean.TRUE.equals(ns.getBoolean("system"))) { busType = DBusConnection.DBusBusType.SYSTEM; } else { busType = DBusConnection.DBusBusType.SESSION; @@ -75,7 +75,7 @@ public class DaemonCommand implements MultiLocalCommand { } } catch (DBusException | IOException e) { logger.error("Dbus command failed", e); - throw new UnexpectedErrorException("Dbus command failed"); + throw new UnexpectedErrorException("Dbus command failed", e); } } @@ -83,10 +83,10 @@ public class DaemonCommand implements MultiLocalCommand { public void handleCommand( final Namespace ns, final List managers, final SignalCreator c, final OutputWriter outputWriter ) throws CommandException { - boolean ignoreAttachments = ns.getBoolean("ignore-attachments"); + boolean ignoreAttachments = Boolean.TRUE.equals(ns.getBoolean("ignore-attachments")); DBusConnection.DBusBusType busType; - if (ns.getBoolean("system")) { + if (Boolean.TRUE.equals(ns.getBoolean("system"))) { busType = DBusConnection.DBusBusType.SYSTEM; } else { busType = DBusConnection.DBusBusType.SESSION; @@ -95,7 +95,7 @@ public class DaemonCommand implements MultiLocalCommand { try (var conn = DBusConnection.getConnection(busType)) { final var signalControl = new DbusSignalControlImpl(c, m -> { try { - final var objectPath = DbusConfig.getObjectPath(m.getUsername()); + final var objectPath = DbusConfig.getObjectPath(m.getSelfNumber()); return run(conn, objectPath, m, outputWriter, ignoreAttachments); } catch (DBusException e) { logger.error("Failed to export object", e); @@ -113,14 +113,17 @@ public class DaemonCommand implements MultiLocalCommand { signalControl.run(); } catch (DBusException | IOException e) { logger.error("Dbus command failed", e); - throw new UnexpectedErrorException("Dbus command failed"); + throw new UnexpectedErrorException("Dbus command failed", e); } } private Thread run( DBusConnection conn, String objectPath, Manager m, OutputWriter outputWriter, boolean ignoreAttachments ) throws DBusException { - conn.exportObject(new DbusSignalImpl(m, objectPath)); + final var signal = new DbusSignalImpl(m, conn, objectPath); + conn.exportObject(signal); + final var initThread = new Thread(signal::initObjects); + initThread.start(); logger.info("Exported dbus object: " + objectPath); @@ -134,10 +137,13 @@ public class DaemonCommand implements MultiLocalCommand { break; } catch (IOException e) { logger.warn("Receiving messages failed, retrying", e); - } catch (InterruptedException ignored) { - break; } } + try { + initThread.join(); + } catch (InterruptedException ignored) { + } + signal.close(); }); thread.start();