mirror of
https://github.com/schollz/croc.git
synced 2024-11-24 08:02:33 +03:00
add spinner for recipient
This commit is contained in:
parent
11566c710d
commit
2ce63b5cda
@ -29,6 +29,13 @@ func (c *Croc) client(role int, channel string) (err error) {
|
||||
|
||||
interrupt := make(chan os.Signal, 1)
|
||||
signal.Notify(interrupt, os.Interrupt)
|
||||
if role == 1 {
|
||||
c.cs.Lock()
|
||||
c.cs.channel.spin.Suffix = " connecting..."
|
||||
c.cs.channel.spin.Start()
|
||||
c.cs.Unlock()
|
||||
|
||||
}
|
||||
|
||||
// connect to the websocket
|
||||
u := url.URL{Scheme: strings.Split(c.WebsocketAddress, "://")[0], Host: strings.Split(c.WebsocketAddress, "://")[1], Path: "/"}
|
||||
@ -50,6 +57,12 @@ func (c *Croc) client(role int, channel string) (err error) {
|
||||
// add websocket to locked channel
|
||||
c.cs.Lock()
|
||||
c.cs.channel.ws = ws
|
||||
if role == 1 {
|
||||
c.cs.channel.spin.Stop()
|
||||
c.cs.channel.spin.Suffix = " waiting for other..."
|
||||
c.cs.channel.spin.Start()
|
||||
c.cs.channel.waitingForOther = true
|
||||
}
|
||||
c.cs.Unlock()
|
||||
|
||||
// read in the messages and process them
|
||||
@ -235,6 +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 {
|
||||
c.cs.channel.waitingForOther = false
|
||||
c.cs.channel.spin.Stop()
|
||||
c.cs.channel.waitingForPake = true
|
||||
}
|
||||
|
||||
// update the Pake
|
||||
if cd.Pake != nil && cd.Pake.Role != c.cs.channel.Role {
|
||||
@ -262,6 +280,10 @@ 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 {
|
||||
c.cs.channel.waitingForPake = false
|
||||
c.cs.channel.spin.Stop()
|
||||
}
|
||||
|
||||
// process the client state
|
||||
if c.cs.channel.Pake.IsVerified() && !c.cs.channel.isReady && c.cs.channel.EncryptedFileMetaData.Encrypted != nil {
|
||||
@ -302,6 +324,21 @@ func (c *Croc) processState(cd channelData) (err error) {
|
||||
c.cs.channel.isReady = true
|
||||
go c.spawnConnections(c.cs.channel.Role)
|
||||
}
|
||||
|
||||
// process spinner
|
||||
if c.cs.channel.Role == 1 && !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 {
|
||||
doStart = false
|
||||
}
|
||||
if doStart {
|
||||
c.cs.channel.spin.Start()
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/briandowns/spinner"
|
||||
"github.com/gorilla/websocket"
|
||||
"github.com/schollz/pake"
|
||||
"github.com/schollz/progressbar"
|
||||
@ -75,6 +76,7 @@ func Init() (c *Croc) {
|
||||
c.rs.channel = make(map[string]*channelData)
|
||||
c.rs.ips = make(map[string]string)
|
||||
c.cs.channel = new(channelData)
|
||||
c.cs.channel.spin = spinner.New(spinner.CharSets[9], 100*time.Millisecond)
|
||||
c.rs.Unlock()
|
||||
c.localIP = getLocalIP()
|
||||
return
|
||||
@ -167,6 +169,12 @@ type channelData struct {
|
||||
startTransfer time.Time
|
||||
transferTime time.Duration
|
||||
|
||||
// spin is the spinner for the recipient
|
||||
spin *spinner.Spinner
|
||||
waitingForConnection bool
|
||||
waitingForOther bool
|
||||
waitingForPake bool
|
||||
|
||||
// ws is the connection that the client has to the relay
|
||||
ws *websocket.Conn
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user