-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathui.go
106 lines (92 loc) · 2.31 KB
/
ui.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package main
import (
"fmt"
"github.com/gen2brain/dlgs"
"github.com/skratchdot/open-golang/open"
)
func createUI() error {
shouldUpdate, newTag, err := checkForUpdate()
if err != nil {
_, err := dlgs.Error(header, err.Error())
if err != nil {
return err
}
}
if shouldUpdate {
wantToUpdate, err := dlgs.Question(header, fmt.Sprintf("There is a new shadowfox-updater version available (%s -> %s)\nDo you want to update?", tag, newTag), true)
if err != nil {
return err
}
if wantToUpdate {
open.Start("https://github.com/SrKomodo/shadowfox-updater/#installing")
return nil
}
}
paths, names, err := getProfilePaths()
if err != nil {
_, err := dlgs.Error(header, err.Error())
if err != nil {
return err
}
}
name, selected, err := dlgs.List(header, "Which Firefox profile are you going to use?", names)
if err != nil {
return err
}
if !selected {
_, err := dlgs.Info(header, "You didn't pick any profile, the application will now close.")
return err
}
pathIndex := 0
for _, name2 := range names {
if name == name2 {
break
}
pathIndex++
}
profilePath := paths[pathIndex]
action, selected, err := dlgs.List(header, "What do you want to do?", []string{"Install/Update Shadowfox", "Uninstall Shadowfox"})
if err != nil {
return err
}
if !selected {
_, err := dlgs.Info(header, "You didn't pick any action, the application will now close.")
return err
}
if action == "Install/Update Shadowfox" {
shouldGenerateUUIDs, err := dlgs.Question(header, "Would you like to auto-generate UUIDs?", true)
if err != nil {
return err
}
shouldSetTheme, err := dlgs.Question(header, "Would you like to automatically set the Firefox dark theme?", false)
if err != nil {
return err
}
err = install(profilePath, shouldGenerateUUIDs, shouldSetTheme)
if err == nil {
_, err = dlgs.Info(header, "Shadowfox has been succesfully installed!")
if err != nil {
return err
}
} else {
_, err := dlgs.Error(header, err.Error())
if err != nil {
return err
}
}
} else {
err := uninstall(profilePath)
if err == nil {
_, err = dlgs.Info(header, "Shadowfox has been succesfully uninstalled!")
if err != nil {
return err
}
} else {
_, err := dlgs.Error(header, err.Error())
if err != nil {
return err
}
}
}
return nil
}