From 39e439cffb61802ca546aacc41c2841ee6cd4708 Mon Sep 17 00:00:00 2001 From: Sr Komodo Date: Tue, 21 May 2019 23:04:51 -0300 Subject: [PATCH] re added fallback ui --- fallback.go | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++ main.go | 4 +++- ui.go | 41 ++++++++++++++++++++++++-------- 3 files changed, 102 insertions(+), 11 deletions(-) create mode 100644 fallback.go diff --git a/fallback.go b/fallback.go new file mode 100644 index 0000000..8d29e6d --- /dev/null +++ b/fallback.go @@ -0,0 +1,68 @@ +package main + +import ( + "fmt" + "strconv" +) + +func createFallbackUI() { + var choice string + paths, names := getProfilePaths() + + if paths == nil { + fmt.Println("ShadowFox couldn't automatically find 'profiles.ini'. Please follow these steps:") + fmt.Println(" 1. Close the program") + fmt.Println(" 2. Move the program to the folder 'profiles.ini' is located") + fmt.Println(" 3. Run the program") + fmt.Scanln() + return + } + + fmt.Println("Available profiles:") + for i, name := range names { + fmt.Printf(" %d: %s\n", i, name) + } + + fmt.Printf("\nWhich one would you like to use? [%d-%d] ", 0, len(names)-1) + + var profile string + for { + fmt.Scanln(&choice) + i, err := strconv.Atoi(choice) + if err != nil || i < 0 || i > len(paths) { + fmt.Print("Please input a valid number ") + } else { + profile = paths[i] + break + } + } + + fmt.Print("\nDo you want to (1) install or (2) uninstall ShadowFox? [1/2] ") + fmt.Scanln(&choice) + + if choice == "2" { + uninstall(profile) + fmt.Print("\nShadowFox was successfully uninstalled! (Press 'enter' to exit)") + fmt.Scanln() + return + } + + fmt.Print("\nWould you like to auto-generate UUIDs? [y/n] ") + fmt.Scanln(&choice) + uuids := (choice == "y" || choice == "Y") + + fmt.Print("\nWould you like to automatically set the Firefox dark theme? [y/n] ") + fmt.Scanln(&choice) + theme := (choice == "y" || choice == "Y") + + message, err := install(profile, uuids, theme) + if err != nil { + fmt.Printf("%s: %s", message, err.Error()) + fmt.Scanln() + return + } + + fmt.Print("\nShadowFox was successfully installed! (Press 'enter' to exit)") + fmt.Scanln() + return +} diff --git a/main.go b/main.go index 13f493a..193176e 100644 --- a/main.go +++ b/main.go @@ -8,6 +8,8 @@ func main() { if len(os.Args) > 1 { cli() } else { - createUI() + if err := createUI(); err != nil { + createFallbackUI() + } } } diff --git a/ui.go b/ui.go index cc50946..bb3a716 100644 --- a/ui.go +++ b/ui.go @@ -11,14 +11,20 @@ func checkErr(msg string, err error) { } } -func createUI() { +func createUI() error { paths, names := getProfilePaths() name, selected, err := dlgs.List("Shadowfox Updater", "Which Firefox profile are you going to use?", names) - checkErr("", err) + if err != nil { + return err + } + if !selected { - dlgs.Info("Shadowfox Updater", "You didn't pick any profile, the application will now close.") - return + _, err := dlgs.Info("Shadowfox Updater", "You didn't pick any profile, the application will now close.") + if err != nil { + return err + } + return nil } pathIndex := 0 @@ -31,31 +37,46 @@ func createUI() { profilePath := paths[pathIndex] action, selected, err := dlgs.List("Shadowfox Updater", "What do you want to do?", []string{"Install/Update Shadowfox", "Uninstall Shadowfox"}) - checkErr("", err) + if err != nil { + return err + } + if !selected { dlgs.Info("Shadowfox Updater", "You didn't pick any action, the application will now close.") - return + return nil } if action == "Install/Update Shadowfox" { shouldGenerateUUIDs, err := dlgs.Question("Shadowfox Updater", "Would you like to auto-generate UUIDs?", true) - checkErr("", err) + if err != nil { + return err + } shouldSetTheme, err := dlgs.Question("Shadowfox Updater", "Would you like to automatically set the Firefox dark theme?", false) - checkErr("", err) + if err != nil { + return err + } msg, err := install(profilePath, shouldGenerateUUIDs, shouldSetTheme) if err == nil { - dlgs.Info("Shadowfox Updater", "Shadowfox has been succesfully installed!") + _, err = dlgs.Info("Shadowfox Updater", "Shadowfox has been succesfully installed!") + if err != nil { + return err + } } else { checkErr(msg, err) } } else { msg, err := uninstall(profilePath) if err == nil { - dlgs.Info("Shadowfox Updater", "Shadowfox has been succesfully uninstalled!") + _, err = dlgs.Info("Shadowfox Updater", "Shadowfox has been succesfully uninstalled!") + if err != nil { + return err + } } else { checkErr(msg, err) } } + + return nil }