mirror of
https://github.com/schollz/croc.git
synced 2025-10-11 13:21:00 +02:00
start implementing UI
This commit is contained in:
parent
55b6eb3802
commit
58910a3f34
5 changed files with 41 additions and 6 deletions
1
go.mod
1
go.mod
|
@ -3,6 +3,7 @@ module github.com/schollz/croc/v5
|
||||||
go 1.12
|
go 1.12
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
github.com/denisbrodbeck/machineid v1.0.1
|
||||||
github.com/go-redis/redis v6.15.2+incompatible
|
github.com/go-redis/redis v6.15.2+incompatible
|
||||||
github.com/mattn/go-colorable v0.1.1
|
github.com/mattn/go-colorable v0.1.1
|
||||||
github.com/pion/webrtc/v2 v2.0.2
|
github.com/pion/webrtc/v2 v2.0.2
|
||||||
|
|
2
go.sum
2
go.sum
|
@ -3,6 +3,8 @@ github.com/cheekybits/genny v1.0.0/go.mod h1:+tQajlRqAUrPI7DOSpB0XAqZYtQakVtB7wX
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/denisbrodbeck/machineid v1.0.1 h1:geKr9qtkB876mXguW2X6TU4ZynleN6ezuMSRhl4D7AQ=
|
||||||
|
github.com/denisbrodbeck/machineid v1.0.1/go.mod h1:dJUwb7PTidGDeYyUBmXZ2GphQBbjJCrnectwCyxcUSI=
|
||||||
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
|
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
|
||||||
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
||||||
github.com/go-redis/redis v6.15.2+incompatible h1:9SpNVG76gr6InJGxoZ6IuuxaCOQwDAhzyXg+Bs+0Sb4=
|
github.com/go-redis/redis v6.15.2+incompatible h1:9SpNVG76gr6InJGxoZ6IuuxaCOQwDAhzyXg+Bs+0Sb4=
|
||||||
|
|
|
@ -15,6 +15,7 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/denisbrodbeck/machineid"
|
||||||
"github.com/go-redis/redis"
|
"github.com/go-redis/redis"
|
||||||
"github.com/mattn/go-colorable"
|
"github.com/mattn/go-colorable"
|
||||||
"github.com/pions/webrtc"
|
"github.com/pions/webrtc"
|
||||||
|
@ -36,8 +37,16 @@ func init() {
|
||||||
log.SetFormatter(&logrus.TextFormatter{ForceColors: true})
|
log.SetFormatter(&logrus.TextFormatter{ForceColors: true})
|
||||||
log.SetOutput(colorable.NewColorableStdout())
|
log.SetOutput(colorable.NewColorableStdout())
|
||||||
log.SetLevel(logrus.DebugLevel)
|
log.SetLevel(logrus.DebugLevel)
|
||||||
receiver.Debug()
|
}
|
||||||
sender.Debug()
|
|
||||||
|
func Debug(debug bool) {
|
||||||
|
receiver.Debug(debug)
|
||||||
|
sender.Debug(debug)
|
||||||
|
if debug {
|
||||||
|
log.SetLevel(logrus.DebugLevel)
|
||||||
|
} else {
|
||||||
|
log.SetLevel(logrus.WarnLevel)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type Client struct {
|
type Client struct {
|
||||||
|
@ -193,6 +202,7 @@ func (c *Client) Receive() (err error) {
|
||||||
func (c *Client) transfer(options TransferOptions) (err error) {
|
func (c *Client) transfer(options TransferOptions) (err error) {
|
||||||
if c.IsSender {
|
if c.IsSender {
|
||||||
c.FilesToTransfer = make([]FileInfo, len(options.PathToFiles))
|
c.FilesToTransfer = make([]FileInfo, len(options.PathToFiles))
|
||||||
|
totalFilesSize := int64(0)
|
||||||
for i, pathToFile := range options.PathToFiles {
|
for i, pathToFile := range options.PathToFiles {
|
||||||
var fstats os.FileInfo
|
var fstats os.FileInfo
|
||||||
var fullPath string
|
var fullPath string
|
||||||
|
@ -216,6 +226,7 @@ func (c *Client) transfer(options TransferOptions) (err error) {
|
||||||
ModTime: fstats.ModTime(),
|
ModTime: fstats.ModTime(),
|
||||||
}
|
}
|
||||||
c.FilesToTransfer[i].Hash, err = utils.HashFile(fullPath)
|
c.FilesToTransfer[i].Hash, err = utils.HashFile(fullPath)
|
||||||
|
totalFilesSize += fstats.Size()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -242,6 +253,19 @@ func (c *Client) transfer(options TransferOptions) (err error) {
|
||||||
}
|
}
|
||||||
log.Debugf("file %d info: %+v", i, c.FilesToTransfer[i])
|
log.Debugf("file %d info: %+v", i, c.FilesToTransfer[i])
|
||||||
}
|
}
|
||||||
|
fname := fmt.Sprintf("%d files", len(c.FilesToTransfer))
|
||||||
|
if len(c.FilesToTransfer) == 1 {
|
||||||
|
fname = fmt.Sprintf("'%s'", c.FilesToTransfer[0].Name)
|
||||||
|
}
|
||||||
|
machID, macIDerr := machineid.ID()
|
||||||
|
if macIDerr != nil {
|
||||||
|
log.Error(macIDerr)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if len(machID) > 6 {
|
||||||
|
machID = machID[:6]
|
||||||
|
}
|
||||||
|
fmt.Fprintf(os.Stderr, "Sending %s (%s) as '%s'\n", fname, utils.ByteCountDecimal(totalFilesSize), machID)
|
||||||
}
|
}
|
||||||
// create channel for quitting
|
// create channel for quitting
|
||||||
// quit with c.quit <- true
|
// quit with c.quit <- true
|
||||||
|
|
|
@ -25,8 +25,12 @@ func init() {
|
||||||
log.SetLevel(logrus.WarnLevel)
|
log.SetLevel(logrus.WarnLevel)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Debug() {
|
func Debug(debug bool) {
|
||||||
|
if debug {
|
||||||
log.SetLevel(logrus.DebugLevel)
|
log.SetLevel(logrus.DebugLevel)
|
||||||
|
} else {
|
||||||
|
log.SetLevel(logrus.WarnLevel)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Session is a receiver session
|
// Session is a receiver session
|
||||||
|
|
|
@ -34,8 +34,12 @@ func init() {
|
||||||
log.SetLevel(logrus.WarnLevel)
|
log.SetLevel(logrus.WarnLevel)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Debug() {
|
func Debug(debug bool) {
|
||||||
|
if debug {
|
||||||
log.SetLevel(logrus.DebugLevel)
|
log.SetLevel(logrus.DebugLevel)
|
||||||
|
} else {
|
||||||
|
log.SetLevel(logrus.WarnLevel)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type outputMsg struct {
|
type outputMsg struct {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue