mirror of
https://github.com/schollz/croc.git
synced 2024-12-01 08:33:08 +03:00
better ui for window
This commit is contained in:
parent
f9dfa6bc05
commit
48933b5ecc
@ -61,6 +61,7 @@ type Croc struct {
|
||||
// special for window
|
||||
WindowRecipientPrompt bool
|
||||
WindowRecipientAccept bool
|
||||
WindowReceivingString string
|
||||
}
|
||||
|
||||
// Init will initiate with the default parameters
|
||||
|
@ -71,6 +71,7 @@ func (cr *Croc) receive(forceSend int, serverAddress string, tcpPorts []string,
|
||||
spin := spinner.New(spinner.CharSets[9], 100*time.Millisecond)
|
||||
spin.Writer = os.Stderr
|
||||
spin.Suffix = " performing PAKE..."
|
||||
cr.StateString = "Performing PAKE..."
|
||||
spin.Start()
|
||||
defer spin.Stop()
|
||||
|
||||
@ -159,6 +160,7 @@ func (cr *Croc) receive(forceSend int, serverAddress string, tcpPorts []string,
|
||||
c.WriteMessage(websocket.BinaryMessage, []byte("ready"))
|
||||
case 3:
|
||||
spin.Stop()
|
||||
cr.StateString = "Recieving file info..."
|
||||
|
||||
// unmarshal the file info
|
||||
log.Debugf("[%d] recieve file info", step)
|
||||
@ -207,12 +209,15 @@ func (cr *Croc) receive(forceSend int, serverAddress string, tcpPorts []string,
|
||||
if cr.FileInfo.IsDir {
|
||||
fileOrFolder = "folder"
|
||||
}
|
||||
fmt.Fprintf(os.Stderr, "\r%s %s (%s) into: %s\n",
|
||||
cr.WindowReceivingString = fmt.Sprintf("%s %s (%s) into: %s",
|
||||
overwritingOrReceiving,
|
||||
fileOrFolder,
|
||||
humanize.Bytes(uint64(cr.FileInfo.Size)),
|
||||
cr.FileInfo.Name,
|
||||
)
|
||||
fmt.Fprintf(os.Stderr, "\r%s%s\n",
|
||||
cr.WindowReceivingString,
|
||||
)
|
||||
if !noPrompt {
|
||||
if "y" != utils.GetInput("ok? (y/N): ") {
|
||||
fmt.Fprintf(os.Stderr, "cancelling request")
|
||||
@ -273,8 +278,8 @@ func (cr *Croc) receive(forceSend int, serverAddress string, tcpPorts []string,
|
||||
} else {
|
||||
blockSize = models.TCP_BUFFER_SIZE / 2
|
||||
}
|
||||
|
||||
// start the ui for pgoress
|
||||
cr.StateString = "Recieving file..."
|
||||
bytesWritten := 0
|
||||
fmt.Fprintf(os.Stderr, "\nReceiving (<-%s)...\n", otherIP)
|
||||
cr.Bar = progressbar.NewOptions(
|
||||
@ -495,6 +500,7 @@ func (cr *Croc) receive(forceSend int, serverAddress string, tcpPorts []string,
|
||||
}
|
||||
fmt.Fprintf(os.Stderr, "\nReceived %s written to %s (%2.1f %s)\n", folderOrFile, cr.FileInfo.Name, transferRate, transferType)
|
||||
os.Remove(progressFile)
|
||||
cr.StateString = fmt.Sprintf("Received %s written to %s (%2.1f %s)", folderOrFile, cr.FileInfo.Name, transferRate, transferType)
|
||||
}
|
||||
return err
|
||||
} else {
|
||||
|
@ -39,8 +39,6 @@ func (cr *Croc) startSender(forceSend int, serverAddress string, tcpPorts []stri
|
||||
fmt.Fprintf(os.Stderr, "\n"+err.Error())
|
||||
}
|
||||
cr.StateString = err.Error()
|
||||
} else {
|
||||
cr.StateString = "File transfer completed."
|
||||
}
|
||||
|
||||
done <- struct{}{}
|
||||
@ -455,6 +453,7 @@ func (cr *Croc) send(forceSend int, serverAddress string, tcpPorts []string, isL
|
||||
transferType = "kB/s"
|
||||
}
|
||||
fmt.Fprintf(os.Stderr, "\nTransfer complete (%2.1f %s)", transferRate, transferType)
|
||||
cr.StateString = fmt.Sprintf("Transfer complete (%2.1f %s)", transferRate, transferType)
|
||||
return nil
|
||||
} else {
|
||||
fmt.Fprintf(os.Stderr, "\nTransfer corrupted")
|
||||
|
@ -1,4 +1,4 @@
|
||||
VERSION=$(shell git describe --abbrev=0)
|
||||
VERSION=$(shell git describe --tags --abbrev=0)
|
||||
LDFLAGS=-ldflags "-X main.Version=${VERSION}"
|
||||
|
||||
.PHONY: linux
|
||||
|
@ -50,7 +50,7 @@ func main() {
|
||||
labels[0].SetText("secure data transfer")
|
||||
labels[1].SetText("Click 'Send' or 'Receive' to start")
|
||||
|
||||
button := widgets.NewQPushButton2("Send file", nil)
|
||||
button := widgets.NewQPushButton2("Send", nil)
|
||||
button.ConnectClicked(func(bool) {
|
||||
if isWorking {
|
||||
dialog("Can only do one send or receive at a time")
|
||||
@ -105,16 +105,6 @@ func main() {
|
||||
done <- true
|
||||
isWorking = false
|
||||
}()
|
||||
|
||||
// for i, label := range labels {
|
||||
// go func(i int, label *CustomLabel) {
|
||||
// var tick int
|
||||
// for range time.NewTicker(time.Duration((i+1)*25) * time.Millisecond).C {
|
||||
// tick++
|
||||
// label.SetText(fmt.Sprintf("%v %v", tick, time.Now().UTC().Format("15:04:05.0000")))
|
||||
// }
|
||||
// }(i, label)
|
||||
// }
|
||||
})
|
||||
widget.Layout().AddWidget(button)
|
||||
|
||||
@ -124,17 +114,13 @@ func main() {
|
||||
dialog("Can only do one send or receive at a time")
|
||||
return
|
||||
}
|
||||
|
||||
isWorking = true
|
||||
defer func() {
|
||||
isWorking = false
|
||||
}()
|
||||
|
||||
var codePhrase = widgets.QInputDialog_GetText(nil, "Enter code phrase", "",
|
||||
widgets.QLineEdit__Normal, "", true, core.Qt__Dialog, core.Qt__ImhNone)
|
||||
if len(codePhrase) < 3 {
|
||||
dialog(fmt.Sprintf("Invalid codephrase: '%s'", codePhrase))
|
||||
return
|
||||
}
|
||||
// determine the folder to save the file
|
||||
var folderDialog = widgets.NewQFileDialog2(nil, "Open folder to receive file...", "", "")
|
||||
folderDialog.SetAcceptMode(widgets.QFileDialog__AcceptOpen)
|
||||
folderDialog.SetFileMode(widgets.QFileDialog__DirectoryOnly)
|
||||
@ -146,42 +132,61 @@ func main() {
|
||||
dialog(fmt.Sprintf("No folder selected"))
|
||||
return
|
||||
}
|
||||
|
||||
var codePhrase = widgets.QInputDialog_GetText(nil, "croc", "Enter code phrase:",
|
||||
widgets.QLineEdit__Normal, "", true, core.Qt__Dialog, core.Qt__ImhNone)
|
||||
if len(codePhrase) < 3 {
|
||||
dialog(fmt.Sprintf("Invalid codephrase: '%s'", codePhrase))
|
||||
return
|
||||
}
|
||||
|
||||
cwd, _ := os.Getwd()
|
||||
|
||||
go func() {
|
||||
os.Chdir(fn)
|
||||
defer os.Chdir(cwd)
|
||||
|
||||
cr := croc.Init(true)
|
||||
done := make(chan bool)
|
||||
go func() {
|
||||
cr.Receive(codePhrase)
|
||||
done <- true
|
||||
}()
|
||||
cr.WindowRecipientPrompt = true
|
||||
|
||||
done := make(chan bool)
|
||||
|
||||
go func(done chan bool) {
|
||||
for {
|
||||
select {
|
||||
case _ = <-done:
|
||||
break
|
||||
if cr.WindowReceivingString != "" {
|
||||
var question = widgets.QMessageBox_Question(nil, "croc", fmt.Sprintf("%s?", cr.WindowReceivingString), widgets.QMessageBox__Yes|widgets.QMessageBox__No, 0)
|
||||
if question == widgets.QMessageBox__Yes {
|
||||
cr.WindowRecipientAccept = true
|
||||
labels[0].UpdateTextFromGoroutine(cr.WindowReceivingString)
|
||||
} else {
|
||||
cr.WindowRecipientAccept = false
|
||||
labels[2].UpdateTextFromGoroutine("canceled")
|
||||
return
|
||||
}
|
||||
labels[0].SetText(cr.StateString)
|
||||
if cr.FileInfo.SentName != "" {
|
||||
labels[0].SetText(fmt.Sprintf("%s", cr.FileInfo.SentName))
|
||||
cr.WindowRecipientPrompt = false
|
||||
cr.WindowReceivingString = ""
|
||||
}
|
||||
|
||||
if cr.Bar != nil {
|
||||
barState := cr.Bar.State()
|
||||
labels[1].SetText(fmt.Sprintf("%2.1f", barState.CurrentPercent))
|
||||
labels[1].UpdateTextFromGoroutine(fmt.Sprintf("%2.1f%% [%2.0f:%2.0f]", barState.CurrentPercent*100, barState.SecondsSince, barState.SecondsLeft))
|
||||
}
|
||||
labels[2].UpdateTextFromGoroutine(cr.StateString)
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
select {
|
||||
case _ = <-done:
|
||||
labels[2].UpdateTextFromGoroutine(cr.StateString)
|
||||
return
|
||||
default:
|
||||
continue
|
||||
}
|
||||
}
|
||||
}(done)
|
||||
|
||||
// for i, label := range labels {
|
||||
// go func(i int, label *CustomLabel) {
|
||||
// var tick int
|
||||
// for range time.NewTicker(time.Duration((i+1)*25) * time.Millisecond).C {
|
||||
// tick++
|
||||
// label.SetText(fmt.Sprintf("%v %v", tick, time.Now().UTC().Format("15:04:05.0000")))
|
||||
// }
|
||||
// }(i, label)
|
||||
// }
|
||||
cr.Receive(codePhrase)
|
||||
done <- true
|
||||
isWorking = false
|
||||
}()
|
||||
})
|
||||
widget.Layout().AddWidget(receiveButton)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user