Browse Source

use new version of go-update. report update error statistics. bump version

Alan Shreve 12 years ago
parent
commit
aa4543b824

+ 1 - 1
src/ngrok/client/main.go

@@ -261,7 +261,7 @@ func Main() {
 	}
 
 	go reconnectingControl(s, ctl)
-	go autoUpdate(s, ctl)
+	go autoUpdate(s, ctl, opts.authtoken)
 
 	quitMessage := ""
 	ctl.Wait.Add(1)

+ 1 - 1
src/ngrok/client/update_debug.go

@@ -7,5 +7,5 @@ import (
 )
 
 // no auto-updating in debug mode
-func autoUpdate(s *State, ctl *ui.Controller) {
+func autoUpdate(s *State, ctl *ui.Controller, token string) {
 }

+ 25 - 10
src/ngrok/client/update_release.go

@@ -4,6 +4,7 @@ package client
 
 import (
 	update "github.com/inconshreveable/go-update"
+	"net/http"
 	"net/url"
 	"ngrok/client/ui"
 	"ngrok/log"
@@ -16,8 +17,8 @@ const (
 	updateEndpoint = "https://dl.ngrok.com/update"
 )
 
-func autoUpdate(s *State, ctl *ui.Controller) {
-	update := func() bool {
+func autoUpdate(s *State, ctl *ui.Controller, token string) {
+	update := func() (updateSuccessful bool) {
 		params := make(url.Values)
 		params.Add("version", version.MajorMinor())
 		params.Add("os", runtime.GOOS)
@@ -52,20 +53,34 @@ func autoUpdate(s *State, ctl *ui.Controller) {
 		err := download.UpdateFromUrl(updateEndpoint + "?" + params.Encode())
 		<-downloadComplete
 		if err != nil {
-			if err != update.UpdateUnavailable {
-				log.Error("Error while updating ngrok: %v", err)
+			log.Error("Error while updating ngrok: %v", err)
+			if download.Available {
 				s.update = ui.UpdateError
 			} else {
 				s.update = ui.UpdateNone
 			}
-			ctl.Update(s)
-			return false
+
+			// record the error to ngrok.com's servers for debugging purposes
+			params.Add("error", err.Error())
+			params.Add("user", token)
+			resp, err := http.PostForm("https://dl.ngrok.com/update/error", params)
+			if err != nil {
+				log.Error("Error while reporting update error")
+			}
+			resp.Body.Close()
 		} else {
-			log.Info("Marked update ready")
-			s.update = ui.UpdateReady
-			ctl.Update(s)
-			return true
+			if download.Available {
+				log.Info("Marked update ready")
+				s.update = ui.UpdateReady
+				updateSuccessful = true
+			} else {
+				log.Info("No update available at this time")
+				s.update = ui.UpdateNone
+			}
 		}
+
+		ctl.Update(s)
+		return
 	}
 
 	// try to update immediately and then at a set interval

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

@@ -88,7 +88,7 @@ func (v *TermView) Render() {
 	case ui.UpdateReady:
 		updateMsg = "ngrok has updated: restart ngrok for the new version"
 	case ui.UpdateError:
-		updateMsg = "new version available at http://ngrok.com"
+		updateMsg = "new version available at https://ngrok.com"
 	default:
 		pct := float64(updateStatus) / 100.0
 		const barLength = 25

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

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