Browse Source

fix download completion ui handling, add some better logging

Alan Shreve 12 years ago
parent
commit
452ba7a575
2 changed files with 21 additions and 12 deletions
  1. 1 3
      src/ngrok/client/main.go
  2. 20 9
      src/ngrok/client/update_release.go

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

@@ -22,9 +22,7 @@ const (
 	pingInterval        = 20 * time.Second
 	maxPongLatency      = 15 * time.Second
 	updateCheckInterval = 6 * time.Hour
-	//updateEndpoint      = "http://dl.ngrok.com/update"
-	updateEndpoint = "http://dl.ngrok.me:8080/update"
-	BadGateway     = `<html>
+	BadGateway          = `<html>
 <body style="background-color: #97a8b9">
     <div style="margin:auto; width:400px;padding: 20px 60px; background-color: #D3D3D3; border: 5px solid maroon;">
         <h2>Tunnel %s unavailable</h2>

+ 20 - 9
src/ngrok/client/update_release.go

@@ -13,6 +13,11 @@ import (
 	"time"
 )
 
+const (
+	//updateEndpoint      = "http://dl.ngrok.com/update"
+	updateEndpoint = "http://dl.ngrok.me:8080/update"
+)
+
 func autoUpdate(s *State, ctl *ui.Controller) {
 	update := func() bool {
 		params := make(url.Values)
@@ -24,22 +29,28 @@ func autoUpdate(s *State, ctl *ui.Controller) {
 		go func() {
 			for {
 				select {
-				case progress := <-download.Progress:
-					if progress < 100 {
-						s.update = ui.UpdateStatus(progress)
-					} else {
+				case progress, ok := <-download.Progress:
+					if !ok {
+						close(downloadComplete)
+						return
+					} else if progress == 100 {
 						s.update = ui.UpdateInstalling
+						ctl.Update(s)
+						close(downloadComplete)
+						return
+					} else {
+						if (progress % 25 == 0) {
+							log.Info("Downloading update %d%% complete", progress)
+						}
+						s.update = ui.UpdateStatus(progress)
+						ctl.Update(s)
 					}
-					ctl.Update(s)
-				case <-downloadComplete:
-					close(downloadComplete)
-					return
 				}
 			}
 		}()
 
+		log.Info("Checking for update")
 		err := download.UpdateFromUrl(updateEndpoint + "?" + params.Encode())
-		downloadComplete <- 1
 		<-downloadComplete
 		if err != nil {
 			if err != update.UpdateUnavailable {