-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
106 lines (81 loc) · 2.54 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
package main
import (
"fmt"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/layout"
"fyne.io/fyne/v2/widget"
)
func MainUi(input *widget.Entry, loading func(bool)) *fyne.Container {
var pid int
install := widget.NewButton("install", func() {
loading(true)
OutputResult(input, "Trying to locate existing Mecchi folder...")
mecchiFolder := MecchiFolderExists()
firstTimeInstall := false
mecchiFolderPath := ""
if mecchiFolder.success {
OutputResult(input, fmt.Sprintf("Mecchi already exists: %s", mecchiFolder.result))
mecchiFolderPath = mecchiFolder.result
} else {
OutputResult(input, "Mecchi does not exist, downloading from Github...")
newMecchiFolder := CloneMecchi()
if newMecchiFolder.success {
OutputResult(input, fmt.Sprintf("Mecchi downloaded successfully to: %s", newMecchiFolder.result))
mecchiFolderPath = newMecchiFolder.result
} else {
OutputResult(input, fmt.Sprintf("Mecchi download failed: %s", newMecchiFolder.error))
}
}
OutputResult(input, fmt.Sprintf("Now installing dependencies to %s...", mecchiFolderPath))
mecchiInstallation := InstallMecchi(mecchiFolderPath, firstTimeInstall, input)
if mecchiInstallation.success {
OutputResult(input, "Successfully installed dependencies...")
} else {
OutputResult(input, mecchiInstallation.error)
}
loading(false)
})
var launch *widget.Button
var stop *widget.Button
launch = widget.NewButton("launch", func() {
go func() {
mecchiFolder := MecchiFolderExists()
if !mecchiFolder.success {
OutputResult(input, "Mecchi does not exist, install it first! "+mecchiFolder.error)
} else {
OutputResult(input, "Launching Mecchi...")
mecchiProcess := LaunchMecchi(mecchiFolder.result, input)
if mecchiProcess.success {
pid = mecchiProcess.result
}
launch.Hidden = true
stop.Hidden = false
}
}()
})
stop = widget.NewButton("stop", func() {
OutputResult(input, "Stopping Mecchi...")
KillMecchi(pid, input)
OutputResult(input, "Mecchi stopped.")
launch.Hidden = false
stop.Hidden = true
})
update := widget.NewButton("update", func() {
loading(true)
updateResult := UpdateMecchi(input)
if updateResult.success {
OutputResult(input, "Mecchi successfully updated")
} else {
OutputResult(input, updateResult.error)
}
loading(false)
})
stop.Hidden = true
content := container.NewVBox(
container.NewAdaptiveGrid(1, layout.NewSpacer()),
container.NewAdaptiveGrid(1, launch, stop),
container.NewGridWithColumns(2, install, update),
)
return content
}