@file:DependsOn("com.github.hypfvieh:dbus-java-core:4.0.0") @file:DependsOn("com.github.hypfvieh:dbus-java-transport-jnr-unixsocket:4.0.0") @file:DependsOn("org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.6.0") import org.freedesktop.dbus.annotations.DBusInterfaceName import org.freedesktop.dbus.connections.impl.DBusConnection import org.freedesktop.dbus.interfaces.DBusInterface import org.freedesktop.dbus.types.Variant val connection = DBusConnection.getConnection(DBusConnection.DBusBusType.SESSION) @DBusInterfaceName("org.freedesktop.portal.Settings") interface SettingsInterface : DBusInterface { fun Read(namespace: String, key: String): Variant<*> } val settingsInterface = connection.getRemoteObject( "org.freedesktop.portal.Desktop", "/org/freedesktop/portal/desktop", SettingsInterface::class.java ) val theme = settingsInterface.Read("org.freedesktop.appearance", "color-scheme") fun recursiveVariantValue(variant: Variant<*>): Any { val value = variant.value if(value !is Variant<*>) return value else return recursiveVariantValue(value) } println(recursiveVariantValue(theme))