mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 10:30:38 +00:00
Align dbus handling of no account parameter with normal mode
This commit is contained in:
parent
db154df4a4
commit
f7b2916618
3 changed files with 44 additions and 6 deletions
|
@ -11,6 +11,9 @@
|
||||||
{
|
{
|
||||||
"interfaces":["org.asamk.Signal$Group"]}
|
"interfaces":["org.asamk.Signal$Group"]}
|
||||||
,
|
,
|
||||||
|
{
|
||||||
|
"interfaces":["org.asamk.SignalControl"]}
|
||||||
|
,
|
||||||
{
|
{
|
||||||
"interfaces":["org.freedesktop.dbus.interfaces.DBus"]}
|
"interfaces":["org.freedesktop.dbus.interfaces.DBus"]}
|
||||||
|
|
||||||
|
|
|
@ -103,6 +103,12 @@
|
||||||
{
|
{
|
||||||
"pattern":"\\Qcom/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_JP\\E"
|
"pattern":"\\Qcom/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_JP\\E"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"pattern":"\\Qcom/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_LV\\E"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"pattern":"\\Qcom/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_MM\\E"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"pattern":"\\Qcom/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_MO\\E"
|
"pattern":"\\Qcom/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_MO\\E"
|
||||||
},
|
},
|
||||||
|
|
|
@ -6,6 +6,7 @@ import net.sourceforge.argparse4j.inf.ArgumentParser;
|
||||||
import net.sourceforge.argparse4j.inf.Namespace;
|
import net.sourceforge.argparse4j.inf.Namespace;
|
||||||
|
|
||||||
import org.asamk.Signal;
|
import org.asamk.Signal;
|
||||||
|
import org.asamk.SignalControl;
|
||||||
import org.asamk.signal.commands.Command;
|
import org.asamk.signal.commands.Command;
|
||||||
import org.asamk.signal.commands.Commands;
|
import org.asamk.signal.commands.Commands;
|
||||||
import org.asamk.signal.commands.LocalCommand;
|
import org.asamk.signal.commands.LocalCommand;
|
||||||
|
@ -30,6 +31,8 @@ import org.asamk.signal.output.OutputWriter;
|
||||||
import org.asamk.signal.output.PlainTextWriterImpl;
|
import org.asamk.signal.output.PlainTextWriterImpl;
|
||||||
import org.asamk.signal.util.IOUtils;
|
import org.asamk.signal.util.IOUtils;
|
||||||
import org.freedesktop.dbus.connections.impl.DBusConnection;
|
import org.freedesktop.dbus.connections.impl.DBusConnection;
|
||||||
|
import org.freedesktop.dbus.errors.ServiceUnknown;
|
||||||
|
import org.freedesktop.dbus.errors.UnknownMethod;
|
||||||
import org.freedesktop.dbus.exceptions.DBusException;
|
import org.freedesktop.dbus.exceptions.DBusException;
|
||||||
import org.freedesktop.dbus.exceptions.DBusExecutionException;
|
import org.freedesktop.dbus.exceptions.DBusExecutionException;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -326,15 +329,41 @@ public class App {
|
||||||
busType = DBusConnection.DBusBusType.SESSION;
|
busType = DBusConnection.DBusBusType.SESSION;
|
||||||
}
|
}
|
||||||
try (var dBusConn = DBusConnection.getConnection(busType)) {
|
try (var dBusConn = DBusConnection.getConnection(busType)) {
|
||||||
var ts = dBusConn.getRemoteObject(DbusConfig.getBusname(),
|
var accountObjectPath = account == null ? tryGetSingleAccountObjectPath(dBusConn) : null;
|
||||||
DbusConfig.getObjectPath(account),
|
if (accountObjectPath == null) {
|
||||||
Signal.class);
|
accountObjectPath = DbusConfig.getObjectPath(account);
|
||||||
|
}
|
||||||
|
var ts = dBusConn.getRemoteObject(DbusConfig.getBusname(), accountObjectPath, Signal.class);
|
||||||
|
|
||||||
handleCommand(command, ts, dBusConn, outputWriter);
|
handleCommand(command, ts, dBusConn, outputWriter);
|
||||||
}
|
}
|
||||||
} catch (DBusException | IOException e) {
|
} catch (ServiceUnknown e) {
|
||||||
logger.error("Dbus client failed", e);
|
throw new UserErrorException("signal-cli DBus daemon not running on "
|
||||||
throw new UnexpectedErrorException("Dbus client failed", e);
|
+ (systemBus ? "system" : "session")
|
||||||
|
+ " bus: "
|
||||||
|
+ e.getMessage(), e);
|
||||||
|
} catch (DBusExecutionException | DBusException | IOException e) {
|
||||||
|
throw new UnexpectedErrorException("Dbus client failed: " + e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String tryGetSingleAccountObjectPath(final DBusConnection dBusConn) throws DBusException, CommandException {
|
||||||
|
var control = dBusConn.getRemoteObject(DbusConfig.getBusname(),
|
||||||
|
DbusConfig.getObjectPath(),
|
||||||
|
SignalControl.class);
|
||||||
|
try {
|
||||||
|
final var accounts = control.listAccounts();
|
||||||
|
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) {
|
||||||
|
throw new UserErrorException(
|
||||||
|
"Multiple users found, you need to specify an account (phone number) with -a");
|
||||||
|
}
|
||||||
|
|
||||||
|
return accounts.get(0).getPath();
|
||||||
|
} catch (UnknownMethod e) {
|
||||||
|
// dbus daemon not running in multi-account mode
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue