-
Notifications
You must be signed in to change notification settings - Fork 4
/
packageView.go
152 lines (140 loc) · 5.3 KB
/
packageView.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
package main
import (
"github.com/20kdc/CCUpdaterUI/design"
"github.com/20kdc/CCUpdaterUI/frenyard"
"github.com/20kdc/CCUpdaterUI/frenyard/framework"
"github.com/20kdc/CCUpdaterUI/frenyard/integration"
"github.com/20kdc/CCUpdaterUI/middle"
"github.com/CCDirectLink/CCUpdaterCLI"
)
// ShowPackageView shows a dialog for a package.
func (app *upApplication) ShowPackageView(back framework.ButtonBehavior, pkg string, remotePackages map[string]ccmodupdater.RemotePackage) {
// Construct a package context here and use it to sanity-check some things.
// It also makes a nice cup-holder for the local/remote repositories.
txCtx := ccmodupdater.PackageTXContext{
LocalPackages: app.gameInstance.Packages(),
RemotePackages: remotePackages,
}
// Get local, remote and latest packages for reference.
localPkg := txCtx.LocalPackages[pkg]
remotePkg := txCtx.RemotePackages[pkg]
var latestPkg ccmodupdater.Package = middle.GetLatestOf(localPkg, remotePkg)
// No latest package = no information.
if latestPkg == nil {
if middle.InternetConnectionWarning {
app.MessageBox("Package not available", "The package '" + pkg + "' could not be found.\n\nAs you have ended up here, the package probably had to exist in some form.\nThis error is probably because CCUpdaterUI was unable to retrieve remote packages.\n\n1. Check your internet connection\n2. Try restarting CCUpdaterUI\n3. Contact us", back)
} else {
app.MessageBox("I just don't know what went wrong...", "The package '" + pkg + "' could not be found.\nYou should never be able to see this dialog in normal operation.", back)
}
return
}
// Ok, now let's actually start work on the UI
showInstallButton := false
annotations := "\n ID: " + pkg + "\n Latest Version: " + latestPkg.Metadata().Version().Original()
if localPkg != nil {
if remotePkg != nil && remotePkg.Metadata().Version().GreaterThan(localPkg.Metadata().Version()) {
annotations += "\n Installed: " + localPkg.Metadata().Version().Original()
showInstallButton = true
} else {
annotations += "\n Installed"
}
} else {
showInstallButton = true
}
chunks := []integration.TypeChunk{
integration.NewColouredTextTypeChunk(latestPkg.Metadata().HumanName(), design.GlobalFont, design.ThemeText),
integration.NewColouredTextTypeChunk(annotations, design.ListItemSubTextFont, design.ThemeSubText),
}
descriptionText := latestPkg.Metadata().Description() + "\n"
buttons := []framework.UILayoutElement{}
homepage := latestPkg.Metadata()["homepage"]
switch homepageString := homepage.(type) {
case string:
buttons = append(buttons, design.ButtonAction(design.ThemePageActionButton, "HOMEPAGE", func () {
middle.OpenURL(homepageString)
}))
descriptionText += "\nHomepage: " + homepageString
}
if (localPkg != nil) && pkg != "Simplify" {
removeTx := ccmodupdater.PackageTX{
pkg: ccmodupdater.PackageTXOperationRemove,
}
removeTheme := design.ThemeRemoveActionButton
_, removeErr := txCtx.Solve(removeTx)
buttonText := "REMOVE"
if removeErr != nil {
buttonText = "NOT REMOVABLE"
removeTheme = design.ThemeImpossibleActionButton
}
buttons = append(buttons, design.ButtonAction(removeTheme, buttonText, func () {
app.GSDownwards()
app.PerformTransaction(func (success bool) {
app.GSUpwards()
app.ShowPackageView(back, pkg, remotePackages)
}, removeTx, remotePackages)
}))
}
if showInstallButton {
installTx := ccmodupdater.PackageTX{
pkg: ccmodupdater.PackageTXOperationInstall,
}
buttonText := "INSTALL"
buttonColour := design.ThemeOkActionButton
if localPkg != nil {
buttonText = "UPDATE"
buttonColour = design.ThemeUpdateActionButton
}
_, removeErr := txCtx.Solve(installTx)
if removeErr != nil {
buttonText = "NOT INSTALLABLE"
buttonColour = design.ThemeImpossibleActionButton
}
buttons = append(buttons, design.ButtonAction(buttonColour, buttonText, func () {
app.GSDownwards()
app.PerformTransaction(func (success bool) {
app.GSUpwards()
app.ShowPackageView(back, pkg, remotePackages)
}, installTx, remotePackages)
}))
}
detail := framework.NewUIFlexboxContainerPtr(framework.FlexboxContainer{
DirVertical: false,
Slots: []framework.FlexboxSlot{
framework.FlexboxSlot{
Element: design.NewIconPtr(0xFFFFFFFF, middle.PackageIcon(latestPkg), 36),
},
framework.FlexboxSlot{
Basis: design.SizeMarginAroundEverything,
},
framework.FlexboxSlot{
Element: framework.NewUILabelPtr(integration.NewCompoundTypeChunk(chunks), 0xFFFFFFFF, 0, frenyard.Alignment2i{X: frenyard.AlignStart, Y: frenyard.AlignStart}),
},
},
})
fullPanel := framework.NewUIFlexboxContainerPtr(framework.FlexboxContainer{
DirVertical: true,
Slots: []framework.FlexboxSlot{
framework.FlexboxSlot{
Element: detail,
},
framework.FlexboxSlot{
Basis: design.SizeMarginAroundEverything,
},
framework.FlexboxSlot{
Element: framework.NewUILabelPtr(integration.NewTextTypeChunk(descriptionText, design.GlobalFont), design.ThemeText, 0, frenyard.Alignment2i{X: frenyard.AlignStart, Y: frenyard.AlignStart}),
Shrink: 1,
},
framework.FlexboxSlot{
Grow: 1,
Shrink: 1,
},
framework.FlexboxSlot{
Element: design.ButtonBar(buttons),
},
},
})
app.Teleport(design.LayoutDocument(design.Header{
Title: latestPkg.Metadata().HumanName(),
Back: back,
}, fullPanel, true))
}