- private void handleCommand(Command command, Signal ts, DBusConnection dBusConn) throws CommandException {
- if (command instanceof ExtendedDbusCommand) {
- ((ExtendedDbusCommand) command).handleCommand(ns, ts, dBusConn);
- } else if (command instanceof DbusCommand) {
- ((DbusCommand) command).handleCommand(ns, ts);
+ 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;
+ }
+ }
+
+ private void handleCommand(
+ Command command, Signal ts, DBusConnection dBusConn, OutputWriter outputWriter
+ ) throws CommandException {
+ if (command instanceof LocalCommand localCommand) {
+ try (final var m = new DbusManagerImpl(ts, dBusConn)) {
+ localCommand.handleCommand(ns, m, outputWriter);
+ } catch (UnsupportedOperationException e) {
+ throw new UserErrorException("Command is not yet implemented via dbus", e);
+ } catch (IOException | DBusExecutionException e) {
+ throw new UnexpectedErrorException(e.getMessage(), e);
+ }