11package middle
22
3- import "os/exec"
3+ import (
4+ "io/ioutil"
5+ "net/http"
6+ "os/exec"
7+ "strings"
8+ )
49
510type WarningID int
611
@@ -14,9 +19,26 @@ const (
1419)
1520
1621type 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
2244var npm = false
@@ -37,14 +59,27 @@ func checkNpm() {
3759func 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
0 commit comments