config.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. config.Theme.DropDownBackground = "#3B4252"
  31. config.Theme.TreeViewBackground = "#282a36"
  32. config.Theme.TextViewBackground = "#282a36"
  33. config.Theme.InputFieldBackground = "#3B4252"
  34. config.Theme.DropDownForeground = "#f8f8f2"
  35. config.Theme.TextViewForeground = "#f8f8f2"
  36. config.Theme.TreeNodeForeground = "#8be9fd"
  37. config.Theme.InputFieldForeground = "#f8f8f2"
  38. config.Theme.InputFieldPlaceholderForeground = "#6272a4"
  39. configPath := userHomeDir + "/.config/discordo/config.json"
  40. if _, err := os.Stat(configPath); os.IsNotExist(err) {
  41. return &config
  42. }
  43. data, err := os.ReadFile(configPath)
  44. if err != nil {
  45. panic(err)
  46. }
  47. if err = json.Unmarshal(data, &config); err != nil {
  48. panic(err)
  49. }
  50. return &config
  51. }