theme.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package util
  2. import (
  3. "encoding/json"
  4. "os"
  5. )
  6. type Theme struct {
  7. DropDownBackground string `json:"dropdown.background"`
  8. DropDownForeground string `json:"dropdown.foreground"`
  9. InputFieldBackground string `json:"inputField.background"`
  10. InputFieldForeground string `json:"inputField.foreground"`
  11. InputFieldPlaceholderForeground string `json:"inputField.placeholderTextForeground"`
  12. TreeViewBackground string `json:"treeview.background"`
  13. TextViewBackground string `json:"textview.background"`
  14. TextViewForeground string `json:"textview.foreground"`
  15. }
  16. func NewTheme() *Theme {
  17. var theme Theme
  18. theme.TextViewBackground = "#2E3440"
  19. theme.TextViewForeground = "#D8DEE9"
  20. theme.TreeViewBackground = "#2E3440"
  21. theme.InputFieldBackground = "#3B4252"
  22. theme.InputFieldForeground = "#D8DEE9"
  23. theme.InputFieldPlaceholderForeground = "#D8DEE9"
  24. theme.DropDownBackground = "#3B4252"
  25. theme.DropDownForeground = "#D8DEE9"
  26. userHomeDir, err := os.UserHomeDir()
  27. if err != nil {
  28. panic(err)
  29. }
  30. themeFilePath := userHomeDir + "/.config/discordo/theme.json"
  31. if _, err := os.Stat(themeFilePath); os.IsNotExist(err) {
  32. return &theme
  33. }
  34. data, err := os.ReadFile(themeFilePath)
  35. if err != nil {
  36. panic(err)
  37. }
  38. if err = json.Unmarshal(data, &theme); err != nil {
  39. panic(err)
  40. }
  41. return &theme
  42. }