Skip to content

Commit

Permalink
[middle/warnings] Implement version checking
Browse files Browse the repository at this point in the history
  • Loading branch information
lexisother committed Aug 16, 2022
1 parent 8b512be commit ae75cd2
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 8 deletions.
49 changes: 42 additions & 7 deletions middle/warnings.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package middle

import "os/exec"
import (
"io/ioutil"
"net/http"
"os/exec"
"strings"
)

type WarningID int

Expand All @@ -14,9 +19,26 @@ const (
)

type Warning struct {
Text string
Action WarningID
Parameter string
Text string
Action WarningID
ActionText string
Parameter string
}

var remoteVersion string
var hasAlreadyCheckedUpdate = false

func checkUpdate() {
if !hasAlreadyCheckedUpdate {
hasAlreadyCheckedUpdate = true
} else {
return
}

res, _ := http.Get("https://raw.githubusercontent.com/replugged-org/installer/main/middle/version.go")

data, _ := ioutil.ReadAll(res.Body)
remoteVersion = strings.Trim(string(data)[33:38], "\r\n")
}

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

if !hasAlreadyCheckedUpdate {
checkUpdate()
}
if remoteVersion != version {
warnings = append(warnings, Warning{
Text: "A new version of the installer is available! (v" + remoteVersion + ")",
Action: URLAndCloseWarningID,
ActionText: "UPDATE",
Parameter: "https://github.com/replugged-org/installer/releases",
})
}

if !hasAlreadyCheckedNpm {
checkNpm()
}
if !npm {
warnings = append(warnings, Warning{
Text: "NPM is not installed.",
Action: URLAndCloseWarningID,
Parameter: "https://docs.npmjs.com/downloading-and-installing-node-js-and-npm",
Text: "NPM is not installed.",
Action: URLAndCloseWarningID,
ActionText: "INSTALL",
Parameter: "https://docs.npmjs.com/downloading-and-installing-node-js-and-npm",
})
}

Expand Down
2 changes: 1 addition & 1 deletion src/primaryView.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (app *UpApplication) ShowPrimaryView() {
{
Element: design.InformationPanel(design.InformationPanelDetails{
Text: v.Text,
ActionText: "FIX",
ActionText: v.ActionText,
Action: fixAction,
}),
},
Expand Down

0 comments on commit ae75cd2

Please sign in to comment.