Browse Source

bump version and properly run new version check in the client

Alan Shreve 12 years ago
parent
commit
73521b606c
3 changed files with 20 additions and 15 deletions
  1. 14 9
      src/ngrok/client/main.go
  2. 5 5
      src/ngrok/client/views/term/view.go
  3. 1 1
      src/ngrok/version/version.go

+ 14 - 9
src/ngrok/client/main.go

@@ -77,31 +77,35 @@ func proxy(proxyAddr string, s *State, ctl *ui.Controller) {
 }
 
 func versionCheck(s *State, ctl *ui.Controller) {
-	for {
+	check := func() {
 		resp, err := http.Get(versionEndpoint)
 		if err != nil {
 			log.Warn("Failed to get version info %s: %v", versionEndpoint, err)
-			continue
+			return
 		}
 
 		var payload struct {
-			client struct {
-				version string
+			Client struct {
+				Version string
 			}
 		}
 
-		err = json.NewDecoder(resp.Body).Decode(payload)
+		err = json.NewDecoder(resp.Body).Decode(&payload)
 		if err != nil {
 			log.Warn("Failed to read version info: %v", err)
-			continue
+			return
 		}
 
-		if payload.client.version != version.MajorMinor() {
-			s.newVersion = payload.client.version
+		if payload.Client.Version != version.MajorMinor() {
+			s.newVersion = payload.Client.Version
 			ctl.Update(s)
 		}
+	}
 
-		time.Sleep(versionCheckInterval)
+	// check immediately and then at a set interval
+	check()
+	for _ = range time.Tick(versionCheckInterval) {
+		check()
 	}
 }
 
@@ -271,6 +275,7 @@ func Main() {
 	web.NewWebView(ctl, s, opts.webport)
 
 	go reconnectingControl(s, ctl)
+	go versionCheck(s, ctl)
 
 	quitMessage := ""
 	ctl.Wait.Add(1)

+ 5 - 5
src/ngrok/client/views/term/view.go

@@ -76,11 +76,11 @@ func (v *TermView) Render() {
 	v.Printf(v.w-len(quitMsg), 0, quitMsg)
 
 	// new version message
-	//newVersion := v.state.GetNewVersion()
-	//if newVersion != "" {
-	newVersionMsg := fmt.Sprintf("new version available")
-	v.APrintf(termbox.ColorYellow, 30, 0, newVersionMsg)
-	//}
+	newVersion := v.state.GetNewVersion()
+	if newVersion != "" {
+		newVersionMsg := fmt.Sprintf("new version available")
+		v.APrintf(termbox.ColorYellow, 30, 0, newVersionMsg)
+	}
 
 	v.APrintf(termbox.ColorBlue|termbox.AttrBold, 0, 0, "ngrok")
 

+ 1 - 1
src/ngrok/version/version.go

@@ -7,7 +7,7 @@ import (
 const (
 	Proto = "1"
 	Major = "0"
-	Minor = "1"
+	Minor = "2"
 )
 
 func MajorMinor() string {