Skip to content

Instantly share code, notes, and snippets.

@DevSrSouza
Created February 2, 2022 04:40
Show Gist options
  • Save DevSrSouza/b013d1a8119f50615a493b36cf0b9b56 to your computer and use it in GitHub Desktop.
Save DevSrSouza/b013d1a8119f50615a493b36cf0b9b56 to your computer and use it in GitHub Desktop.
Kotlin Script that get Linux System Theme based on Dbus appearance color-schema from Gnome 42, KDE and Elementary
@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))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment