theme.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. ListBackground string `json:"list.background"`
  13. ListMainTextForeground string `json:"list.mainTextForeground"`
  14. ListSelectedForeground string `json:"list.selectedTextForeground"`
  15. TextViewBackground string `json:"textview.background"`
  16. TextViewForeground string `json:"textview.foreground"`
  17. }
  18. func NewTheme() *Theme {
  19. var theme Theme
  20. theme.TextViewBackground = "#2E3440"
  21. theme.TextViewForeground = "#D8DEE9"
  22. theme.ListBackground = "#2E3440"
  23. theme.ListMainTextForeground = "#4C566A"
  24. theme.ListSelectedForeground = "#ECEFF4"
  25. theme.InputFieldBackground = "#3B4252"
  26. theme.InputFieldForeground = "#D8DEE9"
  27. theme.InputFieldPlaceholderForeground = "#D8DEE9"
  28. theme.DropDownBackground = "#3B4252"
  29. theme.DropDownForeground = "#D8DEE9"
  30. userHomeDir, err := os.UserHomeDir()
  31. if err != nil {
  32. panic(err)
  33. }
  34. themeFilePath := userHomeDir + "/.config/discordo/theme.json"
  35. if _, err := os.Stat(themeFilePath); os.IsNotExist(err) {
  36. return &theme
  37. }
  38. data, err := os.ReadFile(themeFilePath)
  39. if err != nil {
  40. panic(err)
  41. }
  42. if err = json.Unmarshal(data, &theme); err != nil {
  43. panic(err)
  44. }
  45. return &theme
  46. }