|
@@ -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
|