Skip to content

Commit ae75cd2

Browse files
committed
[middle/warnings] Implement version checking
1 parent 8b512be commit ae75cd2

File tree

2 files changed

+43
-8
lines changed

2 files changed

+43
-8
lines changed

middle/warnings.go

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
package middle
22

3-
import "os/exec"
3+
import (
4+
"io/ioutil"
5+
"net/http"
6+
"os/exec"
7+
"strings"
8+
)
49

510
type WarningID int
611

@@ -14,9 +19,26 @@ const (
1419
)
1520

1621
type Warning struct {
17-
Text string
18-
Action WarningID
19-
Parameter string
22+
Text string
23+
Action WarningID
24+
ActionText string
25+
Parameter string
26+
}
27+
28+
var remoteVersion string
29+
var hasAlreadyCheckedUpdate = false
30+
31+
func checkUpdate() {
32+
if !hasAlreadyCheckedUpdate {
33+
hasAlreadyCheckedUpdate = true
34+
} else {
35+
return
36+
}
37+
38+
res, _ := http.Get("https://raw.githubusercontent.com/replugged-org/installer/main/middle/version.go")
39+
40+
data, _ := ioutil.ReadAll(res.Body)
41+
remoteVersion = strings.Trim(string(data)[33:38], "\r\n")
2042
}
2143

2244
var npm = false
@@ -37,14 +59,27 @@ func checkNpm() {
3759
func FindWarnings(config Config) []Warning {
3860
warnings := []Warning{}
3961

62+
if !hasAlreadyCheckedUpdate {
63+
checkUpdate()
64+
}
65+
if remoteVersion != version {
66+
warnings = append(warnings, Warning{
67+
Text: "A new version of the installer is available! (v" + remoteVersion + ")",
68+
Action: URLAndCloseWarningID,
69+
ActionText: "UPDATE",
70+
Parameter: "https://github.com/replugged-org/installer/releases",
71+
})
72+
}
73+
4074
if !hasAlreadyCheckedNpm {
4175
checkNpm()
4276
}
4377
if !npm {
4478
warnings = append(warnings, Warning{
45-
Text: "NPM is not installed.",
46-
Action: URLAndCloseWarningID,
47-
Parameter: "https://docs.npmjs.com/downloading-and-installing-node-js-and-npm",
79+
Text: "NPM is not installed.",
80+
Action: URLAndCloseWarningID,
81+
ActionText: "INSTALL",
82+
Parameter: "https://docs.npmjs.com/downloading-and-installing-node-js-and-npm",
4883
})
4984
}
5085

src/primaryView.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func (app *UpApplication) ShowPrimaryView() {
117117
{
118118
Element: design.InformationPanel(design.InformationPanelDetails{
119119
Text: v.Text,
120-
ActionText: "FIX",
120+
ActionText: v.ActionText,
121121
Action: fixAction,
122122
}),
123123
},

0 commit comments

Comments
 (0)