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