diff --git a/helper/helper.go b/helper/helper.go index cd39dd3..2183d66 100644 --- a/helper/helper.go +++ b/helper/helper.go @@ -145,7 +145,7 @@ func StringOscillator(s string, amplitude int) chan string { return c } -func ClickRepeteadly(s *SavedGroups) { +func ClickRepeteadly(s *SavedGroups, c chan os.Signal) { for index, g := range s.Groups { fmt.Printf("- Press %v to select %v\n", index+1, g.Name) } @@ -188,6 +188,7 @@ func ClickRepeteadly(s *SavedGroups) { } if t >= 10 { fmt.Println("You stayed away too long, exiting...") + c <- os.Interrupt return } } @@ -203,15 +204,19 @@ func cleanUp(c chan os.Signal) chan int { return r } +func interactWithUser(s *SavedGroups, yamlFile string, c chan os.Signal) { + addSavedGroup(s) + storeSavedGroups(s, yamlFile) + ClickRepeteadly(s, c) +} + func RunAutoClicker() { c := make(chan os.Signal, 1) quit := cleanUp(c) signal.Notify(c, os.Interrupt) yamlFile := "SavedGroups.yaml" s := getSavedGroups(yamlFile) - addSavedGroup(s) - storeSavedGroups(s, yamlFile) - go ClickRepeteadly(s) + go interactWithUser(s, yamlFile, c) if <-quit == 1 { fmt.Println("Exiting...") } else {