/
gui.go
426 lines (365 loc) · 10.5 KB
/
gui.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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
package main
import (
"fmt"
"log"
"os"
"path"
"strconv"
"strings"
"github.com/AllenDang/giu"
)
type Proton struct {
Widget giu.Widget
Checked bool
Name string
Major int
Minor int
Used bool
}
const (
mainWindowWidth int = 692
mainWindowHeight int = 325
mainButtonWidth float32 = 220
mainButtonFullWidth float32 = 676
mainButtonHeight float32 = 100
pruneSubButtonWidth float32 = 100
pruneSubButtonHeight float32 = 50
mainWindowFlags giu.MasterWindowFlags = giu.MasterWindowFlagsNotResizable
// mainWindowFlags giu.MasterWindowFlags = giu.MasterWindowFlagsFloating + giu.MasterWindowFlagsNotResizable
)
var (
protons []Proton
rows []*giu.TableRowWidget
gamesRows []*giu.TableRowWidget
showPruneWindow bool = false
)
func getInstalledProtons() (err error) {
protons = []Proton{}
fileNames, err := os.ReadDir(protonPath)
if err != nil {
return err
}
for _, fileName := range fileNames {
if fileName.Type().IsDir() {
name := fileName.Name() // simplify
if !strings.Contains(name, "GE-Proton") {
continue
}
trimmed := strings.TrimPrefix(name, "GE-Proton") // leaves 7-31, for example
split := strings.Split(trimmed, "-") // should result in []string{"7", "31"}, for example
if len(split) < 2 { // skip if we can't parse
log.Println("couldn't determine version information from: " + name)
continue
}
major, err := strconv.Atoi(split[0]) // convert major number to int
if err != nil {
log.Println("problem converting major: " + err.Error())
continue
}
minor, err := strconv.Atoi(split[1]) // same with minor
if err != nil {
log.Println("problem converting minor: " + err.Error())
continue
}
protons = append(protons, Proton{ // create Proton object
Name: name,
Checked: false,
Major: major,
Minor: minor,
})
}
for i, proton := range protons {
proton.Widget = giu.Checkbox(proton.Name, &protons[i].Checked)
}
}
return err
}
func getLatestInstalled() (latest Proton) {
for _, proton := range protons {
if latest.Major < proton.Major {
latest = proton
continue
}
if latest.Minor < proton.Minor {
latest = proton
continue
}
}
return latest
}
func uncheckLatest() []Proton {
latest := getLatestInstalled()
for i, proton := range protons {
if proton.Major == latest.Major && proton.Minor == latest.Minor {
protons[i].Checked = false
}
}
return protons
}
func uncheckUsed() []Proton {
for i, proton := range protons {
if proton.Used {
protons[i].Checked = false
}
}
return protons
}
func buildRows() {
err := getInstalledProtons()
if err != nil {
return
}
games, err := getSteamGames()
if err != nil {
return
}
for i, proton := range protons {
for _, game := range games {
if game.CompatibilityTool == proton.Name {
protons[i].Used = true
}
}
}
protons = uncheckLatest()
protons = uncheckUsed()
protonBoxes := []giu.Widget{}
for i, proton := range protons {
protonBoxes = append(protonBoxes, giu.Checkbox(proton.Name, &protons[i].Checked))
}
rows = make([]*giu.TableRowWidget, len(protonBoxes))
for i := range rows {
rows[i] = giu.TableRow(
protonBoxes[i],
giu.Label(strconv.FormatBool(protons[i].Used)),
)
}
}
func buildGamesRows() {
games, err := getSteamGames()
if err != nil {
return
}
gamesRows = make([]*giu.TableRowWidget, len(games))
for i, game := range games {
installed := "Not currently installed"
if len(game.Path) > 0 {
if strings.Contains(game.Path, "/run/media") {
installed = "microSD card"
}
if strings.Contains(game.Path, ".local/share") {
installed = "internal SSD"
}
}
gamesRows[i] = giu.TableRow(
giu.Label(strconv.Itoa(game.Id)),
giu.Label(game.Name),
giu.Label(game.CompatibilityTool),
giu.Label(installed),
)
}
}
func prune() {
for _, proton := range protons {
if !proton.Checked {
continue
}
fmt.Println("Pruning " + proton.Name + "...")
err := os.RemoveAll(path.Join(protonPath, proton.Name))
if err != nil {
log.Println("error removing " + proton.Name + ": " + err.Error())
continue
}
}
buildRows()
}
func uncheckAll() {
for i := range protons {
protons[i].Checked = false
}
}
func checkAllExceptLatest() {
latest := getLatestInstalled()
for i, proton := range protons {
if proton == latest {
protons[i].Checked = false
} else {
protons[i].Checked = true
}
}
}
func stub() {}
func togglePruneWindow() {
giu.OpenPopup("prune")
}
func toggleGamesWindow() {
giu.OpenPopup("games")
}
func popupError(err error) {
giu.Msgbox("Error", err.Error())
}
func doInstall() {
err := install()
if err != nil {
popupError(err)
return
}
giu.Msgbox("Info", "Steam Deck GE-Proton Updater successfully installed! It will run when this Steam Deck reboots. See About for more information.")
installed, err = isInstalled()
if err != nil {
popupError(err)
return
}
}
func userMustRelaunch(result giu.DialogResult) {
os.Exit(0)
}
func doUpdate() {
res, err := doSelfUpdate()
if err != nil {
popupError(err)
return
}
if res {
giu.Msgbox("Info", "Update successful! You MUST close Steam Deck GE-Proton Updater and run it again to get the benefits.").ResultCallback(userMustRelaunch)
} else {
giu.Msgbox("Info", "Already on the latest release of Steam Deck GE-Proton Updater.")
}
}
func doUninstall(result giu.DialogResult) {
if result == false {
return
}
err := uninstall()
if err != nil {
popupError(err)
return
}
installed, err = isInstalled()
if err != nil {
popupError(err)
return
}
}
func promptUninstall() {
giu.Msgbox("Info", "Are you positive you want to remove Steam Deck GE-Proton Updater? This will not remove GE-Proton from your Steam Deck.").Buttons(giu.MsgboxButtonsYesNo).ResultCallback(doUninstall)
}
func popupVersion() {
giu.Msgbox("About", "Steam Deck GE-Proton Updater will run at every boot. In order, it will...\n\t1. try to update itself to the latest version,\n\t2. ensure it is configured correctly,\n\t3. attempt to get information about the latest GE-Proton release,\n\t4. install the latest release if you don't already have it.\n\n"+
"Version: "+version+"\n"+
"Commit: "+commit+"\n"+
"Date: "+date+"\n"+
"Built By: "+builtBy+"\n",
)
}
func buildGamesPopup() *giu.PopupModalWidget {
gamesTable := giu.Table().Size(
float32(mainWindowWidth-26), // fit scrollbar
float32(mainWindowHeight-102), // fit other widgets
).Flags(
giu.TableFlagsSortable,
).Columns(
giu.TableColumn("App ID").Flags(
giu.TableColumnFlagsNoDirectResize+giu.TableColumnFlagsNoResize+giu.TableColumnFlagsNoSort,
),
giu.TableColumn("App Name").Flags(
giu.TableColumnFlagsWidthStretch+giu.TableColumnFlagsNoDirectResize+giu.TableColumnFlagsNoResize+giu.TableColumnFlagsNoSort,
),
giu.TableColumn("Compatibility Tool").Flags(
giu.TableColumnFlagsNoDirectResize+giu.TableColumnFlagsNoResize+giu.TableColumnFlagsNoSort,
),
giu.TableColumn("Installed").Flags(
giu.TableColumnFlagsNoDirectResize+giu.TableColumnFlagsNoResize+giu.TableColumnFlagsNoSort,
),
).Rows(
gamesRows...,
)
return giu.PopupModal(
"games",
).Flags(
giu.WindowFlagsAlwaysAutoResize+giu.WindowFlagsNoMove+giu.WindowFlagsNoTitleBar,
).Layout(
giu.Row(
giu.Button("Refresh").Size(pruneSubButtonWidth, pruneSubButtonHeight).OnClick(buildGamesRows),
giu.Button("Close").Size(pruneSubButtonWidth, pruneSubButtonHeight).OnClick(giu.CloseCurrentPopup),
),
giu.Row(
giu.Label("Games using Proton, and what version of Proton each is set to use:"),
),
gamesTable,
)
}
func buildPrunePopup() *giu.PopupModalWidget {
pruneTable := giu.Table().Size(
float32(mainWindowWidth-36), // fit scrollbar
float32(mainWindowHeight-152), // fit other widgets
).Columns(
giu.TableColumn("Installed GE-Proton version").Flags(
giu.TableColumnFlagsWidthStretch+giu.TableColumnFlagsNoDirectResize+giu.TableColumnFlagsNoResize,
),
giu.TableColumn("In-use").Flags(
giu.TableColumnFlagsNoDirectResize+giu.TableColumnFlagsNoResize,
),
).Rows(
rows...,
)
return giu.PopupModal(
"prune",
).Flags(
giu.WindowFlagsAlwaysAutoResize+giu.WindowFlagsNoMove+giu.WindowFlagsNoTitleBar,
).Layout(
giu.Row(
giu.Button("Refresh").Size(pruneSubButtonWidth, pruneSubButtonHeight).OnClick(buildRows),
giu.Button("Uncheck All").Size(pruneSubButtonWidth, pruneSubButtonHeight).OnClick(uncheckAll),
giu.Button("Check All").Size(pruneSubButtonWidth, pruneSubButtonHeight).OnClick(checkAllExceptLatest),
giu.Label(" "),
giu.Button("Prune").Size(pruneSubButtonWidth, pruneSubButtonHeight).OnClick(prune),
),
giu.Label("Please click the Prune button to PERMANENTLY DELETE the installations checked below."),
pruneTable,
giu.Button("Close").Size(pruneSubButtonWidth, pruneSubButtonHeight).OnClick(giu.CloseCurrentPopup),
)
}
func getLatestGeProtonRelease() {
err := get()
if err != nil {
popupError(err)
return
}
}
func loop() {
aboutButton := giu.Button("About Steam Deck GE-Proton Updater").Size(mainButtonFullWidth, mainButtonHeight).OnClick(popupVersion)
updateButton := giu.Button("Update Steam Deck\nGE-Proton Updater").Size(mainButtonWidth, mainButtonHeight).OnClick(doUpdate)
installButton := giu.Button("Install Steam Deck\nGE-Proton Updater").Size(mainButtonWidth, mainButtonHeight).OnClick(doInstall)
uninstallButton := giu.Button("Uninstall Steam Deck\nGE-Proton Updater").Size(mainButtonWidth, mainButtonHeight).OnClick(promptUninstall)
getProtonButton := giu.Button("Get latest GE-Proton release").Size(mainButtonWidth, mainButtonHeight).OnClick(getLatestGeProtonRelease)
pruneProtonButton := giu.Button("Prune chosen GE-Proton releases").Size(mainButtonWidth, mainButtonHeight).OnClick(togglePruneWindow)
listGamesButton := giu.Button("Show list of games").Size(mainButtonWidth, mainButtonHeight).OnClick(toggleGamesWindow)
// buttons we want disabled when we aren't running the real deal
if !installed {
uninstallButton.Disabled(true)
}
giu.SingleWindow().Layout(
giu.PrepareMsgbox(),
buildPrunePopup(),
buildGamesPopup(),
giu.Row(
aboutButton,
),
giu.Row(
installButton,
uninstallButton,
updateButton,
),
giu.Row(
getProtonButton,
pruneProtonButton,
listGamesButton,
),
)
}
func gui() {
mainWindow := giu.NewMasterWindow("Steam Deck GE-Proton Updater "+version+" "+commit, mainWindowWidth, mainWindowHeight, mainWindowFlags)
buildRows()
buildGamesRows()
mainWindow.Run(loop)
}