config.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. type Config struct {
  18. GetMessagesLimit uint `json:"getMessagesLimit"`
  19. Theme *Theme `json:"theme"`
  20. }
  21. func NewConfig() *Config {
  22. userHomeDir, err := os.UserHomeDir()
  23. if err != nil {
  24. panic(err)
  25. }
  26. var config Config = Config{
  27. GetMessagesLimit: 50,
  28. Theme: &Theme{},
  29. }
  30. configPath := userHomeDir + "/.config/discordo/config.json"
  31. if _, err := os.Stat(configPath); os.IsNotExist(err) {
  32. return &config
  33. }
  34. data, err := os.ReadFile(configPath)
  35. if err != nil {
  36. panic(err)
  37. }
  38. if err = json.Unmarshal(data, &config); err != nil {
  39. panic(err)
  40. }
  41. return &config
  42. }