mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-30 02:50:39 +00:00
Move all dbus interaction to dbus package
This commit is contained in:
parent
7e9940be4a
commit
9741c93ce9
4 changed files with 31 additions and 31 deletions
|
@ -13,12 +13,34 @@ import org.asamk.signal.commands.exceptions.CommandException;
|
|||
import org.asamk.signal.commands.exceptions.UnexpectedErrorException;
|
||||
import org.asamk.signal.commands.exceptions.UserErrorException;
|
||||
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 org.freedesktop.dbus.exceptions.DBusExecutionException;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class DbusCommandHandler {
|
||||
|
||||
public static void initDbusClient(
|
||||
final Command command, final String account, final boolean systemBus, final CommandHandler commandHandler
|
||||
) throws CommandException {
|
||||
try {
|
||||
final var busType = systemBus ? DBusConnection.DBusBusType.SYSTEM : DBusConnection.DBusBusType.SESSION;
|
||||
try (var dBusConn = DBusConnectionBuilder.forType(busType).build()) {
|
||||
handleCommand(command, account, dBusConn, commandHandler);
|
||||
}
|
||||
} catch (ServiceUnknown e) {
|
||||
throw new UserErrorException("signal-cli DBus daemon not running on "
|
||||
+ (systemBus ? "system" : "session")
|
||||
+ " bus: "
|
||||
+ e.getMessage(), e);
|
||||
} catch (DBusExecutionException | DBusException | IOException e) {
|
||||
throw new UnexpectedErrorException("Dbus client failed: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void handleCommand(
|
||||
final Command command,
|
||||
final String account,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue