Skip to content

Instantly share code, notes, and snippets.

@DevSrSouza
Created February 2, 2022 04:40
Show Gist options
  • Select an option

  • Save DevSrSouza/b013d1a8119f50615a493b36cf0b9b56 to your computer and use it in GitHub Desktop.

Select an option

Save DevSrSouza/b013d1a8119f50615a493b36cf0b9b56 to your computer and use it in GitHub Desktop.

Revisions

  1. DevSrSouza created this gist Feb 2, 2022.
    31 changes: 31 additions & 0 deletions get-theme.main.kts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    @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))