Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve config struct #1

Merged
merged 3 commits into from
Jul 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 2 additions & 11 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,10 @@ package main

import "image"

type Pages [][]struct {
Icon string `json:"icon,omitempty"`
SwitchPage *int `json:"switch_page,omitempty"`
Text string `json:"text,omitempty"`
Keybind string `json:"keybind,omitempty"`
Command string `json:"command,omitempty"`
Brightness *int `json:"brightness,omitempty"`
Url string `json:"url,omitempty"`
buff image.Image
}
type Page []Key

type Config struct {
Pages Pages `json:"pages"`
Pages []Page `json:"pages"`
}

type Key struct {
Expand Down
12 changes: 8 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,12 @@ func main() {
log.Fatal(err)
}
config, err = readConfig()
if err != nil {
if err != nil && !os.IsNotExist(err) {
log.Fatal(err)
}
if len(config.Pages) == 0 {
config.Pages = append(config.Pages, Page{})
}
cleanupHook()
setPage()
kch, err := dev.ReadKeys()
Expand All @@ -59,7 +62,9 @@ func main() {
continue
}
if k.Pressed == true {
handleInput(config.Pages[page][k.Index])
if len(config.Pages)-1 >= page && len(config.Pages[page])-1 >= int(k.Index) {
handleInput(config.Pages[page][k.Index])
}
}
}
}
Expand All @@ -86,8 +91,7 @@ func setImage(img image.Image, i int, p int) {

func setPage() {
currentPage := config.Pages[page]
for i := range currentPage {
currentKey := currentPage[i]
for i, currentKey := range currentPage {
if currentKey.buff == nil {
if currentKey.Icon == "" {
img := image.NewRGBA(image.Rect(0, 0, int(dev.Pixels), int(dev.Pixels)))
Expand Down