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

add receive

This commit is contained in:
Zack Scholl 2019-10-23 13:34:44 -07:00
parent 6f1c496230
commit 6293331e76
4 changed files with 66 additions and 14 deletions

View file

@ -1,5 +1,8 @@
windows:
go get github.com/schollz/croc/v6@win
go build -v -ldflags -H=windowsgui -o croc.exe
linux:
go get github.com/schollz/croc/v6@win
go build -v -o croc
@ -9,6 +12,4 @@ linuxprereqs:
sudo apt-get install libglib2.0-dev
sudo apt-get install libgtk-3-dev
windows:
go get github.com/schollz/croc/v6@win
go build -v -ldflags -H=windowsgui -o croc.exe

View file

@ -5,6 +5,6 @@ go 1.13
require (
fyne.io/fyne v1.1.1
github.com/gotk3/gotk3 v0.0.0-20190930052053-f6994e9a1558 // indirect
github.com/schollz/croc/v6 v6.1.6-0.20191009155022-6cdf8cecfc0a
github.com/schollz/croc/v6 v6.1.6-0.20191009214340-6f1c49623059
github.com/sqweek/dialog v0.0.0-20190728103509-6254ed5b0d3c
)

View file

@ -18,6 +18,7 @@ github.com/cpuguy83/go-md2man/v2 v2.0.0 h1:EoUDS0afbrsXAZ9YQ9jdu/mZ2sXgT1/2yyNng
github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
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/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
@ -62,6 +63,8 @@ github.com/schollz/croc/v6 v6.1.6-0.20191009003006-e2198faa24d0 h1:UH27BGqcbGDIo
github.com/schollz/croc/v6 v6.1.6-0.20191009003006-e2198faa24d0/go.mod h1:Wd/ZHrsZlxT21hRqbxaEWl8ww1uCHGR6xACaZQQV/wk=
github.com/schollz/croc/v6 v6.1.6-0.20191009155022-6cdf8cecfc0a h1:yVOlp4bFxCFSLMQZq4aTmAe4xJx6uXTVV5J4rBxZiwY=
github.com/schollz/croc/v6 v6.1.6-0.20191009155022-6cdf8cecfc0a/go.mod h1:Wd/ZHrsZlxT21hRqbxaEWl8ww1uCHGR6xACaZQQV/wk=
github.com/schollz/croc/v6 v6.1.6-0.20191009214340-6f1c49623059 h1:zjVHFer4w5VAXCNGEhvD7zSBQPWafHZj797siKoRZPM=
github.com/schollz/croc/v6 v6.1.6-0.20191009214340-6f1c49623059/go.mod h1:Wd/ZHrsZlxT21hRqbxaEWl8ww1uCHGR6xACaZQQV/wk=
github.com/schollz/logger v1.0.1 h1:BuBAU+euqphM0Ny9qFVScl4RSxatis4nCHIkOxO2cUU=
github.com/schollz/logger v1.0.1/go.mod h1:P6F4/dGMGcx8wh+kG1zrNEd4vnNpEBY/mwEMd/vn6AM=
github.com/schollz/mnemonicode v1.0.1 h1:LiH5hwADZwjwnfXsaD4xgnMyTAtaKHN+e5AyjRU6WSU=
@ -93,6 +96,7 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.3.1-0.20190311161405-34c6fa2dc709 h1:Ko2LQMrRU+Oy/+EDBwX7eZ2jp3C47eDBB8EIhKTun+I=
github.com/stretchr/testify v1.3.1-0.20190311161405-34c6fa2dc709/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/tscholl2/siec v0.0.0-20180721101609-21667da05937 h1:lhssCpSe3TjKcbvUoPzFMuv9oUyZDgI3Cmgolfw2C90=
github.com/tscholl2/siec v0.0.0-20180721101609-21667da05937/go.mod h1:KL9+ubr1JZdaKjgAaHr+tCytEncXBa1pR6FjbTsOJnw=
@ -127,4 +131,5 @@ golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGm
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/tylerb/is.v1 v1.1.2/go.mod h1:9yQB2tyIhZ5oph6Kk5Sq7cJMd9c5Jpa1p3hr9kxzPqo=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

View file

@ -169,29 +169,75 @@ func main() {
}
entry.SetPlaceHolder("Enter code phrase")
var receiveFileButtion *widget.Button
receiveFolder := ""
receiveFileButtion = widget.NewButton("Set directory to save", func() {
filename, err := nativedialog.Directory().Title("Now find a dir").Browse()
fmt.Println(filename)
fmt.Println(err)
receiveFileButtion.SetText(filename)
receiveFolder = filename
})
receiveScreen := widget.NewVBox(
widget.NewLabelWithStyle("Receive a file", fyne.TextAlignCenter, fyne.TextStyle{Bold: true}),
receiveFileButtion,
entry,
widget.NewButton("Receive", func() {
cnf := dialog.NewConfirm("Confirmation", "Accept file ?", confirmCallback, w)
cnf.SetDismissText("Nah")
cnf.SetConfirmText("Oh Yes!")
cnf.Show()
fmt.Println("codePhraseToReceive")
if receiveFolder != "" {
err := os.Chdir(receiveFolder)
if err != nil {
panic(err)
}
}
crocOptions := croc.Options{
SharedSecret: codePhraseToReceive,
IsSender: false,
Debug: false,
NoPrompt: true,
RelayAddress: models.DEFAULT_RELAY,
Stdout: false,
DisableLocal: true,
RelayPorts: strings.Split("9009,9010,9011,9012,9013", ","),
}
cr, err := croc.New(crocOptions)
if err != nil {
return
}
finished := false
transfering := false
var prog *dialog.ProgressDialog
startTime := time.Now()
go func() {
for {
if finished || cr == nil {
// mbPerSecond := float64(finfo.Size()) / time.Since(startTime).Seconds()
// currentInfo.SetText(fmt.Sprintf("Finished transfer (%s/s).", utils.ByteCountDecimal(int64(mbPerSecond))))
prog.Hide()
return
}
if cr.Step1ChannelSecured {
currentInfo.SetText("Channel secured.")
}
if cr.Step4FileTransfer && !transfering {
transfering = true
currentInfo.SetText("Transfering file.")
prog = dialog.NewProgress("Progress", "Transfering", w)
startTime = time.Now()
}
if transfering && cr.Bar != nil {
prog.SetValue(cr.Bar.State().CurrentPercent)
}
time.Sleep(100 * time.Millisecond)
}
}()
err = cr.Receive()
if err != nil {
panic(err)
}
cr = nil
finished = true
}),
layout.NewSpacer(),
currentInfo,
widget.NewHBox(
widget.NewLabel("Progress:"),
progress,
),
)
progress.SetValue(0)