Skip to content

Commit

Permalink
Add an API to get the color scheme setting
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacalz committed Mar 14, 2024
1 parent 4ee6fc3 commit 50360ae
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions settings/color.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package settings

import (
"github.com/godbus/dbus/v5"
"github.com/rymdport/portal"
)

const readOneCallPath = settingsCallPath + ".ReadOne"

// ColorScheme is the type of color scheme preference that the user has set.
type ColorScheme uint8

const (
NoPreference = ColorScheme(iota) // Indicates that no appearance preference was set.
Dark // Indicates that dark mode is preferred.
Light // Indicates that light mode is preferred.
)

// GetColorScheme returns the currently set color scheme.
func GetColorScheme() (ColorScheme, error) {
dbusConn, err := dbus.SessionBus()
if err != nil {
return NoPreference, err
}

dbusObj := dbusConn.Object(portal.ObjectName, portal.ObjectPath)
call := dbusObj.Call(
readOneCallPath,
dbus.FlagNoAutoStart,
"org.freedesktop.appearance",
"color-scheme",
)
if call.Err != nil {
return NoPreference, err
}

var value uint8
if err = call.Store(&value); err != nil {
return NoPreference, err
}

return ColorScheme(value), nil
}

0 comments on commit 50360ae

Please sign in to comment.