-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
176 lines (137 loc) · 4.43 KB
/
main.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
package main
import (
"image/color"
"io"
"net/http"
"os"
"os/user"
"path/filepath"
"runtime"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/canvas"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/widget"
"github.com/sqweek/dialog"
)
func main() {
user, err := user.Current()
if err != nil {
panic(err)
}
if user.Username != "root" && runtime.GOOS == "linux" {
dialog.Message("Installing neptune requires root permissions. Please rerun neptune installer as root to continue.").Error()
return
}
a := app.New()
a.Settings().SetTheme(discordTheme{})
w := a.NewWindow("neptune installer")
w.SetFixedSize(true)
selectedInstancePath := make([]string, 1)
instances := make(map[string]string)
var channels []string
for _, instance := range GetChannels() {
instances[instance.Channel] = instance.Path
channels = append(channels, instance.Channel)
}
header := canvas.NewText("neptune installer", color.White)
header.TextSize = 22
header.Alignment = fyne.TextAlignCenter
description := widget.NewLabel("Choose the version of TIDAL you'd like to install to, then click install.")
installButton := widget.NewButton("Install", func() {})
installButton.Disable()
installedContainer := container.NewVBox()
updateButton := widget.NewButton("Update", func() {})
uninstallButton := widget.NewButton("Uninstall", func() {})
installedContainer.Add(updateButton)
installedContainer.Add(uninstallButton)
installedContainer.Hide()
showInstall := func() {
installButton.Show()
installButton.Enable()
installedContainer.Hide()
w.Resize(fyne.NewSize(0, 0))
}
showUninstall := func() {
installButton.Hide()
installButton.Disable()
installedContainer.Show()
w.Resize(fyne.NewSize(0, 0))
}
installButton.OnTapped = func() {
installButton.Disable()
neptuneZip, err := os.CreateTemp("", "neptune.zip")
if err != nil {
dialog.Message("Failed to create temp file!\n%s", err).Error()
a.Quit()
}
tempDirectory := os.TempDir()
resp, err := http.Get("https://github.com/uwu/neptune/archive/refs/heads/master.zip")
if err != nil {
dialog.Message("Failed to download neptune!\n%s", err).Error()
a.Quit()
}
defer resp.Body.Close()
if _, err := io.Copy(neptuneZip, resp.Body); err != nil {
dialog.Message("Failed to copy neptune to temp folder!\n%s", err).Error()
a.Quit()
}
err = Unzip(neptuneZip.Name(), tempDirectory)
if err != nil {
dialog.Message("Failed to unzip neptune!\n%s", err).Error()
a.Quit()
}
// It's okay if this fails, the temp folder should ideally be cleared by the system at some point.
os.Remove(neptuneZip.Name())
neptuneDir := filepath.Join(tempDirectory, "neptune-master")
injectorPath := filepath.Join(neptuneDir, "injector")
if err := os.Rename(injectorPath, filepath.Join(selectedInstancePath[0], "app")); err != nil {
dialog.Message("Failed to move injector to app directory!\n%s", err).Error()
a.Quit()
}
// It's fine if this fails, it's in the temp dir.
os.Remove(neptuneDir)
appAsarPath := filepath.Join(selectedInstancePath[0], "app.asar")
originalAsarPath := filepath.Join(selectedInstancePath[0], "original.asar")
if _, err := os.Stat(originalAsarPath); err != nil {
if err := os.Rename(appAsarPath, originalAsarPath); err != nil {
dialog.Message("Failed to rename original asar!\n%s", err).Error()
a.Quit()
}
}
showUninstall()
}
updateButton.OnTapped = func() {
updateButton.Disable()
os.RemoveAll(filepath.Join(selectedInstancePath[0], "app"))
installButton.OnTapped()
dialog.Message("Update complete!").Title("neptune updated successfully!").Info()
updateButton.Enable()
}
uninstallButton.OnTapped = func() {
if err := os.RemoveAll(filepath.Join(selectedInstancePath[0], "app")); err != nil {
dialog.Message("Failed to remove app directory!\n%s", err).Error()
return
}
if err := os.Rename(filepath.Join(selectedInstancePath[0], "original.asar"), filepath.Join(selectedInstancePath[0], "app.asar")); err != nil {
dialog.Message("Failed to rename original.asar to app.asar!\n%s", err).Error()
return
}
showInstall()
}
w.SetContent(container.NewVBox(
header,
description,
widget.NewSelect(channels, func(s string) {
selectedInstancePath[0] = instances[s]
if _, err := os.Stat(filepath.Join(selectedInstancePath[0], "original.asar")); os.IsNotExist(err) {
showInstall()
} else {
showUninstall()
}
}),
installButton,
installedContainer,
))
w.ShowAndRun()
}