]> nmode's Git Repositories - signal-cli/blobdiff - src/main/java/org/asamk/signal/Main.java
Show better error message, if libunix-java.so is not available
[signal-cli] / src / main / java / org / asamk / signal / Main.java
index b2550fe75544771269c85e7301129b5c8ba8bc78..633ef469ef353fbee0a509c6940b6c8a278fa576 100644 (file)
@@ -46,6 +46,7 @@ import java.security.Security;
 import java.text.DateFormat;
 import java.text.SimpleDateFormat;
 import java.util.*;
 import java.text.DateFormat;
 import java.text.SimpleDateFormat;
 import java.util.*;
+import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeoutException;
 
 public class Main {
 import java.util.concurrent.TimeoutException;
 
 public class Main {
@@ -87,6 +88,9 @@ public class Main {
                     ts = (Signal) dBusConn.getRemoteObject(
                             SIGNAL_BUSNAME, SIGNAL_OBJECTPATH,
                             Signal.class);
                     ts = (Signal) dBusConn.getRemoteObject(
                             SIGNAL_BUSNAME, SIGNAL_OBJECTPATH,
                             Signal.class);
+                } catch (UnsatisfiedLinkError e) {
+                    System.err.println("Missing native library dependency for dbus service: " + e.getMessage());
+                    return 1;
                 } catch (DBusException e) {
                     e.printStackTrace();
                     if (dBusConn != null) {
                 } catch (DBusException e) {
                     e.printStackTrace();
                     if (dBusConn != null) {
@@ -349,6 +353,9 @@ public class Main {
                                     System.out.println();
                                 }
                             });
                                     System.out.println();
                                 }
                             });
+                        } catch (UnsatisfiedLinkError e) {
+                            System.err.println("Missing native library dependency for dbus service: " + e.getMessage());
+                            return 1;
                         } catch (DBusException e) {
                             e.printStackTrace();
                             return 1;
                         } catch (DBusException e) {
                             e.printStackTrace();
                             return 1;
@@ -365,17 +372,18 @@ public class Main {
                         System.err.println("User is not registered.");
                         return 1;
                     }
                         System.err.println("User is not registered.");
                         return 1;
                     }
-                    int timeout = 5;
-                    if (ns.getInt("timeout") != null) {
-                        timeout = ns.getInt("timeout");
+                    double timeout = 5;
+                    if (ns.getDouble("timeout") != null) {
+                        timeout = ns.getDouble("timeout");
                     }
                     boolean returnOnTimeout = true;
                     if (timeout < 0) {
                         returnOnTimeout = false;
                         timeout = 3600;
                     }
                     }
                     boolean returnOnTimeout = true;
                     if (timeout < 0) {
                         returnOnTimeout = false;
                         timeout = 3600;
                     }
+                    boolean ignoreAttachments = ns.getBoolean("ignore_attachments");
                     try {
                     try {
-                        m.receiveMessages(timeout, returnOnTimeout, new ReceiveMessageHandler(m));
+                        m.receiveMessages((long) (timeout * 1000), TimeUnit.MILLISECONDS, returnOnTimeout, ignoreAttachments, new ReceiveMessageHandler(m));
                     } catch (IOException e) {
                         System.err.println("Error while receiving messages: " + e.getMessage());
                         return 3;
                     } catch (IOException e) {
                         System.err.println("Error while receiving messages: " + e.getMessage());
                         return 3;
@@ -544,12 +552,16 @@ public class Main {
                             conn = DBusConnection.getConnection(busType);
                             conn.exportObject(SIGNAL_OBJECTPATH, m);
                             conn.requestBusName(SIGNAL_BUSNAME);
                             conn = DBusConnection.getConnection(busType);
                             conn.exportObject(SIGNAL_OBJECTPATH, m);
                             conn.requestBusName(SIGNAL_BUSNAME);
+                        } catch (UnsatisfiedLinkError e) {
+                            System.err.println("Missing native library dependency for dbus service: " + e.getMessage());
+                            return 1;
                         } catch (DBusException e) {
                             e.printStackTrace();
                             return 2;
                         }
                         } catch (DBusException e) {
                             e.printStackTrace();
                             return 2;
                         }
+                        ignoreAttachments = ns.getBoolean("ignore_attachments");
                         try {
                         try {
-                            m.receiveMessages(3600, false, new DbusReceiveMessageHandler(m, conn));
+                            m.receiveMessages(1, TimeUnit.HOURS, false, ignoreAttachments, new DbusReceiveMessageHandler(m, conn));
                         } catch (IOException e) {
                             System.err.println("Error while receiving messages: " + e.getMessage());
                             return 3;
                         } catch (IOException e) {
                             System.err.println("Error while receiving messages: " + e.getMessage());
                             return 3;
@@ -719,13 +731,19 @@ public class Main {
 
         Subparser parserReceive = subparsers.addParser("receive");
         parserReceive.addArgument("-t", "--timeout")
 
         Subparser parserReceive = subparsers.addParser("receive");
         parserReceive.addArgument("-t", "--timeout")
-                .type(int.class)
+                .type(double.class)
                 .help("Number of seconds to wait for new messages (negative values disable timeout)");
                 .help("Number of seconds to wait for new messages (negative values disable timeout)");
+        parserReceive.addArgument("--ignore-attachments")
+                .help("Don’t download attachments of received messages.")
+                .action(Arguments.storeTrue());
 
         Subparser parserDaemon = subparsers.addParser("daemon");
         parserDaemon.addArgument("--system")
                 .action(Arguments.storeTrue())
                 .help("Use DBus system bus instead of user bus.");
 
         Subparser parserDaemon = subparsers.addParser("daemon");
         parserDaemon.addArgument("--system")
                 .action(Arguments.storeTrue())
                 .help("Use DBus system bus instead of user bus.");
+        parserDaemon.addArgument("--ignore-attachments")
+                .help("Don’t download attachments of received messages.")
+                .action(Arguments.storeTrue());
 
         try {
             Namespace ns = parser.parseArgs(args);
 
         try {
             Namespace ns = parser.parseArgs(args);