X-Git-Url: https://git.nmode.ca/signal-cli/blobdiff_plain/0476895c3d9e843e505ef768340d7969b084cada..04fa0468151c78f80197feb6434e39e0fd7e2d9e:/src/main/java/org/asamk/signal/App.java diff --git a/src/main/java/org/asamk/signal/App.java b/src/main/java/org/asamk/signal/App.java index 7a9297a8..4daaa815 100644 --- a/src/main/java/org/asamk/signal/App.java +++ b/src/main/java/org/asamk/signal/App.java @@ -34,6 +34,7 @@ import org.asamk.signal.output.OutputWriter; import org.asamk.signal.output.PlainTextWriterImpl; import org.asamk.signal.util.IOUtils; import org.freedesktop.dbus.connections.impl.DBusConnection; +import org.freedesktop.dbus.connections.impl.DBusConnectionBuilder; import org.freedesktop.dbus.errors.ServiceUnknown; import org.freedesktop.dbus.errors.UnknownMethod; import org.freedesktop.dbus.exceptions.DBusException; @@ -45,7 +46,7 @@ import java.io.BufferedWriter; import java.io.File; import java.io.IOException; import java.io.OutputStreamWriter; -import java.nio.charset.Charset; +import java.util.Set; import static net.sourceforge.argparse4j.DefaultSettings.VERSION_0_9_0_DEFAULT_SETTINGS; @@ -63,8 +64,8 @@ public class App { .description("Commandline interface for Signal.") .version(BaseConfig.PROJECT_NAME + " " + BaseConfig.PROJECT_VERSION); - parser.addArgument("-v", "--version").help("Show package version.").action(Arguments.version()); - parser.addArgument("--verbose") + parser.addArgument("--version").help("Show package version.").action(Arguments.version()); + parser.addArgument("-v", "--verbose") .help("Raise log level and include lib signal logs. Specify multiple times for even more logs.") .action(Arguments.count()); parser.addArgument("--log-file") @@ -122,7 +123,7 @@ public class App { var outputType = outputTypeInput == null ? command.getSupportedOutputTypes().stream().findFirst().orElse(null) : outputTypeInput; - var writer = new BufferedWriter(new OutputStreamWriter(System.out, Charset.defaultCharset())); + var writer = new BufferedWriter(new OutputStreamWriter(System.out, IOUtils.getConsoleCharset())); var outputWriter = outputType == null ? null : outputType == OutputType.JSON ? new JsonWriterImpl(writer) : new PlainTextWriterImpl(writer); @@ -188,7 +189,12 @@ public class App { return; } - var accounts = signalAccountFiles.getAllLocalAccountNumbers(); + Set accounts = null; + try { + accounts = signalAccountFiles.getAllLocalAccountNumbers(); + } catch (IOException e) { + throw new IOErrorException("Failed to load local accounts file", e); + } if (accounts.size() == 0) { throw new UserErrorException("No local users found, you first need to register or link an account"); } else if (accounts.size() > 1) { @@ -299,6 +305,8 @@ public class App { ) throws CommandException { try (var multiAccountManager = signalAccountFiles.initMultiAccountManager()) { command.handleCommand(ns, multiAccountManager, outputWriter); + } catch (IOException e) { + throw new IOErrorException("Failed to load local accounts file", e); } } @@ -365,7 +373,7 @@ public class App { } else { busType = DBusConnection.DBusBusType.SESSION; } - try (var dBusConn = DBusConnection.getConnection(busType)) { + try (var dBusConn = DBusConnectionBuilder.forType(busType).build()) { if (command instanceof ProvisioningCommand c) { if (account != null) { throw new UserErrorException("You cannot specify a account (phone number) when linking");