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;
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;
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);
? TrustNewIdentity.ON_FIRST_USE
: trustNewIdentityCli == TrustNewIdentityCli.ALWAYS ? TrustNewIdentity.ALWAYS : TrustNewIdentity.NEVER;
- final SignalAccountFiles signalAccountFiles = new SignalAccountFiles(configPath,
- serviceEnvironment,
- BaseConfig.USER_AGENT,
- trustNewIdentity);
+ final SignalAccountFiles signalAccountFiles;
+ try {
+ signalAccountFiles = new SignalAccountFiles(configPath,
+ serviceEnvironment,
+ BaseConfig.USER_AGENT,
+ trustNewIdentity);
+ } catch (IOException e) {
+ throw new IOErrorException("Failed to read local accounts list", e);
+ }
if (command instanceof ProvisioningCommand provisioningCommand) {
if (account != null) {
return;
}
- var accounts = signalAccountFiles.getAllLocalAccountNumbers();
+ Set<String> 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) {
) 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);
}
}
} 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");