-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
236 lines (186 loc) · 6.09 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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
package main
import (
"fmt"
"image/color"
"net/url"
"strings"
"time"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/canvas"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/widget"
"github.com/4rkal/dmvp2p/helpers"
"github.com/4rkal/dmvp2p/pages"
)
var users []helpers.User
var settings pages.Settings
var settings_found bool
func init() {
users = helpers.LoadUsers()
var err error
settings, err = pages.LoadSettings()
if err != nil {
fmt.Println(err)
settings_found = false
} else {
settings_found = true
}
}
func createUserCard(user helpers.User) fyne.CanvasObject {
createHyperlink := func(label string, link string) *widget.Hyperlink {
parsedURL, err := url.Parse(link)
if err != nil {
fmt.Println("Error parsing URL:", err)
return nil
}
return widget.NewHyperlink(label, parsedURL)
}
mining := false
var donateButton *widget.Button
donateButton = widget.NewButton("Start Donating", func() {
if !mining {
fmt.Println("Starting mining for:", user.Name)
err := helpers.StartMining("p2pmd.xmrvsbeast.com", user.Address, settings.XmrigPath, settings.P2poolPath)
if err != nil {
fmt.Println("Error starting mining:", err)
return
}
donateButton.SetText("Stop Donating")
donateButton.Importance = widget.DangerImportance
mining = true
} else {
fmt.Println("Stopping mining for:", user.Name)
err := helpers.StopMining()
if err != nil {
fmt.Println("Error stopping mining:", err)
return
}
donateButton.SetText("Start Donating")
donateButton.Importance = widget.HighImportance
mining = false
}
})
donateButton.Importance = widget.HighImportance
var socialLinks []fyne.CanvasObject
if user.GitHub != "" {
socialLinks = append(socialLinks, createHyperlink("GitHub", "https://github.com/"+user.GitHub))
socialLinks = append(socialLinks, widget.NewLabel("|"))
}
if user.X != "" {
socialLinks = append(socialLinks, createHyperlink("X", "https://x.com/"+user.X))
socialLinks = append(socialLinks, widget.NewLabel("|"))
}
if user.Website != "" {
socialLinks = append(socialLinks, createHyperlink("Website", user.Website))
}
if len(socialLinks) > 0 {
if label, ok := socialLinks[len(socialLinks)-1].(*widget.Label); ok && label.Text == "|" {
socialLinks = socialLinks[:len(socialLinks)-1]
}
}
return widget.NewCard(
user.Name,
user.Description,
container.NewVBox(
container.NewHBox(socialLinks...),
donateButton,
),
)
}
func filterUsers(searchTerm string) []helpers.User {
var filteredUsers []helpers.User
for _, user := range users {
if strings.Contains(strings.ToLower(user.Name), strings.ToLower(searchTerm)) {
filteredUsers = append(filteredUsers, user)
}
}
return filteredUsers
}
func main() {
a := app.NewWithID("com.example.dmvp2p")
w := a.NewWindow("DMVP2P (Donate Monero Via P2Pool)")
fullScreenButton := pages.NewFullscreenButton(w)
input := widget.NewEntry()
input.SetPlaceHolder("Enter user...")
userList := container.NewVBox()
updateUserList := func() {
userList.Objects = nil
searchTerm := input.Text
filteredUsers := filterUsers(searchTerm)
for _, user := range filteredUsers {
userList.Add(createUserCard(user))
}
userList.Refresh()
}
input.OnChanged = func(content string) {
updateUserList()
}
updateUserList()
scrollContainer := container.NewScroll(userList)
text := canvas.NewText("DMVP2P", color.White)
text.TextSize = 50
text.Alignment = fyne.TextAlignCenter
text.TextStyle = fyne.TextStyle{Bold: true}
text2 := canvas.NewText("Donate Monero Via P2Pool", color.White)
text2.Alignment = fyne.TextAlignCenter
text3 := canvas.NewText("Mining Statistics", color.White)
text3.TextSize = 30
text3.Alignment = fyne.TextAlignCenter
text3.TextStyle = fyne.TextStyle{Bold: true}
text4 := canvas.NewText("Settings", color.White)
text4.TextSize = 30
text4.Alignment = fyne.TextAlignCenter
text4.TextStyle = fyne.TextStyle{Bold: true}
emtpy_line := widget.NewLabel("")
errors := canvas.NewText("", color.White)
if !settings_found {
fmt.Println("settings not found")
errors.Text = "Settings not found, please set the P2Pool/XMRig binary locations in the settings tab. Then restart"
errors.Color = color.RGBA{R: 255, G: 0, B: 0, A: 255}
}
p2pool_label := widget.NewLabel("P2Pool Path:")
infoLabel := widget.NewLabel("No file selected.")
if settings.P2poolPath != "" {
infoLabel.SetText("Selected file: " + settings.P2poolPath)
}
hashrate_label := canvas.NewText("No hashrate detected", color.White)
hashrate_label.TextSize = 20
hashrate_label.Alignment = fyne.TextAlignCenter
ticker := time.NewTicker(2 * time.Second)
defer ticker.Stop()
go func() {
for range ticker.C {
stats := helpers.GetXmrigStats()
if stats.Highest != 0 && stats.Total != nil {
hashrate_label.Text = fmt.Sprintf("%v h/s | Max %v h/s", stats.Total[0], stats.Highest)
}
}
}()
selectFileButton := widget.NewButton("Select File", func() {
helpers.SelectFileWithDialog(infoLabel, &settings.P2poolPath)
})
xmrig_label := widget.NewLabel("XMRig Path:")
infoLabel2 := widget.NewLabel("No file selected.")
if settings.XmrigPath != "" {
infoLabel2.SetText("Selected file: " + settings.XmrigPath)
}
selectFileButton2 := widget.NewButton("Select File", func() {
helpers.SelectFileWithDialog(infoLabel2, &settings.XmrigPath)
})
saveSettings := widget.NewButton("Save Settings", func() {
pages.SaveSettings(settings)
})
scrollContainer.SetMinSize(fyne.NewSize(0, 700))
userContainer := container.NewVBox(errors, text, text2, input, scrollContainer)
tabs := container.NewAppTabs(
container.NewTabItemWithIcon("Home", theme.HomeIcon(), container.NewStack(userContainer)),
container.NewTabItemWithIcon("Mining", theme.BrokenImageIcon(), container.NewVBox(text3, emtpy_line, hashrate_label)),
container.NewTabItemWithIcon("Settings", theme.SettingsIcon(), container.NewVBox(text4, fullScreenButton, emtpy_line, p2pool_label, infoLabel, selectFileButton, xmrig_label, infoLabel2, selectFileButton2, emtpy_line, saveSettings)),
)
w.SetIcon(theme.ComputerIcon())
w.SetContent(tabs)
w.Resize(fyne.NewSize(900, 750))
w.ShowAndRun()
}