theme.go 1.4 KB

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