discordo/util/theme.go
rigormorrtiss d684312f38 Implement ChannelsTreeView Component for categories (#7)
* Add ChannelsTreeView component

* Remove ChannelsList component

* Implement ChannelsTreeView comp for categories

* Update README preview
2021-07-30 20:37:13 +04:00

50 lines
1.4 KiB
Go

package util
import (
"encoding/json"
"os"
)
type Theme struct {
DropDownBackground string `json:"dropdown.background"`
DropDownForeground string `json:"dropdown.foreground"`
InputFieldBackground string `json:"inputField.background"`
InputFieldForeground string `json:"inputField.foreground"`
InputFieldPlaceholderForeground string `json:"inputField.placeholderTextForeground"`
TreeViewBackground string `json:"treeview.background"`
TextViewBackground string `json:"textview.background"`
TextViewForeground string `json:"textview.foreground"`
}
func NewTheme() *Theme {
var theme Theme
theme.TextViewBackground = "#2E3440"
theme.TextViewForeground = "#D8DEE9"
theme.TreeViewBackground = "#2E3440"
theme.InputFieldBackground = "#3B4252"
theme.InputFieldForeground = "#D8DEE9"
theme.InputFieldPlaceholderForeground = "#D8DEE9"
theme.DropDownBackground = "#3B4252"
theme.DropDownForeground = "#D8DEE9"
userHomeDir, err := os.UserHomeDir()
if err != nil {
panic(err)
}
themeFilePath := userHomeDir + "/.config/discordo/theme.json"
if _, err := os.Stat(themeFilePath); os.IsNotExist(err) {
return &theme
}
data, err := os.ReadFile(themeFilePath)
if err != nil {
panic(err)
}
if err = json.Unmarshal(data, &theme); err != nil {
panic(err)
}
return &theme
}