Skip to content

Commit

Permalink
show spinners
Browse files Browse the repository at this point in the history
  • Loading branch information
schollz committed Jul 6, 2018
1 parent 57b1251 commit 4565d17
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,11 @@ func (c *Croc) processState(cd channelData) (err error) {
log.Debugf("local IP: %s", c.cs.channel.Addresses[0])
}
c.bothConnected = cd.Addresses[0] != "" && cd.Addresses[1] != ""
if c.cs.channel.Role == 1 && c.cs.channel.waitingForOther {
if !c.cs.channel.waitingForPake && c.bothConnected {
c.cs.channel.waitingForOther = false
c.cs.channel.spin.Stop()
if c.cs.channel.spin.Active() {
c.cs.channel.spin.Stop()
}
c.cs.channel.waitingForPake = true
}

Expand Down Expand Up @@ -280,9 +282,12 @@ func (c *Croc) processState(cd channelData) (err error) {
go c.getFilesReady()
c.cs.channel.filesReady = true
}
if c.cs.channel.Role == 1 && c.cs.channel.Pake.IsVerified() && c.cs.channel.waitingForPake {
if c.cs.channel.Pake.IsVerified() && c.cs.channel.waitingForPake {
c.cs.channel.waitingForPake = false
c.cs.channel.spin.Stop()
if c.cs.channel.Role == 0 {
c.cs.channel.waitingForRecipient = true
}
}

// process the client state
Expand Down Expand Up @@ -326,12 +331,14 @@ func (c *Croc) processState(cd channelData) (err error) {
}

// process spinner
if c.cs.channel.Role == 1 && !c.cs.channel.spin.Active() {
if !c.cs.channel.spin.Active() {
doStart := true
if c.cs.channel.waitingForOther {
c.cs.channel.spin.Suffix = " waiting for other..."
} else if c.cs.channel.waitingForPake {
c.cs.channel.spin.Suffix = " performing PAKE..."
} else if c.cs.channel.waitingForRecipient {
c.cs.channel.spin.Suffix = " waiting for ok..."
} else {
doStart = false
}
Expand Down Expand Up @@ -416,6 +423,11 @@ func (c *Croc) dialUp() (err error) {
}
if i == 0 {
c.cs.Lock()
if c.cs.channel.waitingForRecipient {
c.cs.channel.spin.Stop()
c.cs.channel.waitingForRecipient = false
fmt.Print(" ")
}
c.bar = progressbar.NewOptions(c.cs.channel.fileMetaData.Size, progressbar.OptionSetWriter(os.Stderr))
if role == 0 {
fmt.Fprintf(os.Stderr, "\nSending (->%s)...\n", c.cs.channel.Addresses[1])
Expand Down
1 change: 1 addition & 0 deletions src/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ type channelData struct {
waitingForConnection bool
waitingForOther bool
waitingForPake bool
waitingForRecipient bool

// ws is the connection that the client has to the relay
ws *websocket.Conn
Expand Down

0 comments on commit 4565d17

Please sign in to comment.