Skip to content

Commit

Permalink
re added fallback ui
Browse files Browse the repository at this point in the history
  • Loading branch information
arguablykomodo committed May 22, 2019
1 parent d2b27ff commit 39e439c
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 11 deletions.
68 changes: 68 additions & 0 deletions fallback.go
Original file line number Diff line number Diff line change
@@ -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
}
4 changes: 3 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ func main() {
if len(os.Args) > 1 {
cli()
} else {
createUI()
if err := createUI(); err != nil {
createFallbackUI()
}
}
}
41 changes: 31 additions & 10 deletions ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}

0 comments on commit 39e439c

Please sign in to comment.