0
0
Fork 0
mirror of https://github.com/schollz/croc.git synced 2025-10-11 13:21:00 +02:00

add spinner

This commit is contained in:
Zack Scholl 2019-04-11 14:12:41 -07:00
parent 7f41fdcfb8
commit 1622fd5092
2 changed files with 16 additions and 6 deletions

View file

@ -25,6 +25,7 @@ import (
"github.com/schollz/croc/v5/src/webrtc/pkg/session/sender" "github.com/schollz/croc/v5/src/webrtc/pkg/session/sender"
"github.com/schollz/pake" "github.com/schollz/pake"
"github.com/schollz/progressbar/v2" "github.com/schollz/progressbar/v2"
"github.com/schollz/spinner"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
@ -85,6 +86,7 @@ type Client struct {
dataChannel [8]*webrtc.DataChannel dataChannel [8]*webrtc.DataChannel
bar *progressbar.ProgressBar bar *progressbar.ProgressBar
spinner *spinner.Spinner
mutex *sync.Mutex mutex *sync.Mutex
quit chan bool quit chan bool
@ -183,6 +185,10 @@ func New(sender bool, sharedSecret string) (c *Client, err error) {
}) })
} }
c.spinner = spinner.New(spinner.CharSets[9], 100*time.Millisecond)
c.spinner.Writer = os.Stderr
c.spinner.Suffix = " connecting..."
c.mutex = &sync.Mutex{} c.mutex = &sync.Mutex{}
return return
} }
@ -269,7 +275,9 @@ func (c *Client) transfer(options TransferOptions) (err error) {
machID = machID[:6] machID = machID[:6]
} }
fmt.Fprintf(os.Stderr, "Sending %s (%s) from your machine, '%s'\n", fname, utils.ByteCountDecimal(totalFilesSize), machID) fmt.Fprintf(os.Stderr, "Sending %s (%s) from your machine, '%s'\n", fname, utils.ByteCountDecimal(totalFilesSize), machID)
} }
c.spinner.Start()
// create channel for quitting // create channel for quitting
// quit with c.quit <- true // quit with c.quit <- true
c.quit = make(chan bool) c.quit = make(chan bool)
@ -359,6 +367,11 @@ func (c *Client) sendOverRedis() (err error) {
func (c *Client) processMessage(m Message) (err error) { func (c *Client) processMessage(m Message) (err error) {
switch m.Type { switch m.Type {
case "pake": case "pake":
if c.spinner.Suffix != " performing PAKE..." {
c.spinner.Stop()
c.spinner.Suffix = " performing PAKE..."
c.spinner.Start()
}
notVerified := !c.Pake.IsVerified() notVerified := !c.Pake.IsVerified()
err = c.Pake.Update(m.Bytes) err = c.Pake.Update(m.Bytes)
if err != nil { if err != nil {
@ -420,6 +433,7 @@ func (c *Client) processMessage(m Message) (err error) {
}.String()).Err() }.String()).Err()
// start receiving data // start receiving data
pathToFile := path.Join(c.FilesToTransfer[c.FilesToTransferCurrentNum].FolderRemote, c.FilesToTransfer[c.FilesToTransferCurrentNum].Name) pathToFile := path.Join(c.FilesToTransfer[c.FilesToTransferCurrentNum].FolderRemote, c.FilesToTransfer[c.FilesToTransferCurrentNum].Name)
c.spinner.Stop()
c.recvSess.ReceiveData(pathToFile, c.FilesToTransfer[c.FilesToTransferCurrentNum].Size) c.recvSess.ReceiveData(pathToFile, c.FilesToTransfer[c.FilesToTransferCurrentNum].Size)
log.Debug("sending close-sender") log.Debug("sending close-sender")
err = c.redisdb.Publish(c.nameOutChannel, Message{ err = c.redisdb.Publish(c.nameOutChannel, Message{
@ -430,6 +444,7 @@ func (c *Client) processMessage(m Message) (err error) {
// Apply the answer as the remote description // Apply the answer as the remote description
err = c.sendSess.SetSDP(m.Message) err = c.sendSess.SetSDP(m.Message)
pathToFile := path.Join(c.FilesToTransfer[c.FilesToTransferCurrentNum].FolderSource, c.FilesToTransfer[c.FilesToTransferCurrentNum].Name) pathToFile := path.Join(c.FilesToTransfer[c.FilesToTransferCurrentNum].FolderSource, c.FilesToTransfer[c.FilesToTransferCurrentNum].Name)
c.spinner.Stop()
c.sendSess.TransferFile(pathToFile) c.sendSess.TransferFile(pathToFile)
case "close-sender": case "close-sender":
log.Debug("close-sender received...") log.Debug("close-sender received...")

View file

@ -16,7 +16,6 @@ import (
internalSess "github.com/schollz/croc/v5/src/webrtc/internal/session" internalSess "github.com/schollz/croc/v5/src/webrtc/internal/session"
"github.com/schollz/croc/v5/src/webrtc/pkg/session/common" "github.com/schollz/croc/v5/src/webrtc/pkg/session/common"
"github.com/schollz/progressbar/v2" "github.com/schollz/progressbar/v2"
"github.com/schollz/spinner"
logrus "github.com/sirupsen/logrus" logrus "github.com/sirupsen/logrus"
) )
@ -219,10 +218,6 @@ func (s *Session) receiveData(pathToFile string, fileSize int64) error {
} }
func (s *Session) CreateConnection() (err error) { func (s *Session) CreateConnection() (err error) {
s.spinner = spinner.New(spinner.CharSets[9], 100*time.Millisecond)
s.spinner.Writer = os.Stderr
s.spinner.Suffix = " connecting..."
return s.sess.CreateConnection(s.onConnectionStateChange()) return s.sess.CreateConnection(s.onConnectionStateChange())
} }