diff --git a/config.go b/config.go index cdab108..d2b9b7c 100644 --- a/config.go +++ b/config.go @@ -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 { diff --git a/main.go b/main.go index de127f5..e0c08d8 100644 --- a/main.go +++ b/main.go @@ -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() @@ -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]) + } } } } @@ -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)))