X-Git-Url: https://git.nmode.ca/signal-cli/blobdiff_plain/f97b0c0faad04f9475d4248a1f09c775d1c3df3f..c5cf78a50ad213fb21728f4d648de51dfac7f07e:/src/main/java/org/asamk/signal/Main.java diff --git a/src/main/java/org/asamk/signal/Main.java b/src/main/java/org/asamk/signal/Main.java index fbdc0ce1..d67bfca0 100644 --- a/src/main/java/org/asamk/signal/Main.java +++ b/src/main/java/org/asamk/signal/Main.java @@ -46,6 +46,7 @@ import java.security.Security; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.*; +import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; public class Main { @@ -110,7 +111,7 @@ public class Main { ts = m; if (m.userExists()) { try { - m.load(); + m.init(); } catch (Exception e) { System.err.println("Error loading state file \"" + m.getFileName() + "\": " + e.getMessage()); return 2; @@ -177,6 +178,9 @@ public class Main { } catch (IOException e) { System.err.println("Link request error: " + e.getMessage()); return 3; + } catch (AssertionError e) { + handleAssertionError(e); + return 1; } catch (InvalidKeyException e) { e.printStackTrace(); return 2; @@ -202,6 +206,9 @@ public class Main { } catch (InvalidKeyException e) { e.printStackTrace(); return 2; + } catch (AssertionError e) { + handleAssertionError(e); + return 1; } catch (URISyntaxException e) { e.printStackTrace(); return 2; @@ -221,8 +228,8 @@ public class Main { for (DeviceInfo d : devices) { System.out.println("Device " + d.getId() + (d.getId() == m.getDeviceId() ? " (this device)" : "") + ":"); System.out.println(" Name: " + d.getName()); - System.out.println(" Created: " + d.getCreated()); - System.out.println(" Last seen: " + d.getLastSeen()); + System.out.println(" Created: " + formatTimestamp(d.getCreated())); + System.out.println(" Last seen: " + formatTimestamp(d.getLastSeen())); } } catch (IOException e) { e.printStackTrace(); @@ -359,9 +366,9 @@ public class Main { 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) { @@ -369,7 +376,7 @@ public class Main { timeout = 3600; } try { - m.receiveMessages(timeout, returnOnTimeout, new ReceiveMessageHandler(m)); + m.receiveMessages((long) (timeout * 1000), TimeUnit.MILLISECONDS, returnOnTimeout, new ReceiveMessageHandler(m)); } catch (IOException e) { System.err.println("Error while receiving messages: " + e.getMessage()); return 3; @@ -543,7 +550,7 @@ public class Main { return 2; } try { - m.receiveMessages(3600, false, new DbusReceiveMessageHandler(m, conn)); + m.receiveMessages(1, TimeUnit.HOURS, false, new DbusReceiveMessageHandler(m, conn)); } catch (IOException e) { System.err.println("Error while receiving messages: " + e.getMessage()); return 3; @@ -713,7 +720,7 @@ public class Main { 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)"); Subparser parserDaemon = subparsers.addParser("daemon");