Refactor getSockPath.

Removed extra code.
This commit is contained in:
Leonid Nikitin 2024-01-14 17:25:35 +06:00
parent 5a4c960201
commit 97dd0f4b32
Signed by: kor-elf
GPG Key ID: 604A019EB118CAC4

View File

@ -65,7 +65,6 @@ func (h ConvertorHandler) getSockPath(file convertor.File, progressbar *widget.P
buf := make([]byte, 16) buf := make([]byte, 16)
data := "" data := ""
progress := 0.0 progress := 0.0
progressMessage := ""
for { for {
_, err := fd.Read(buf) _, err := fd.Read(buf)
if err != nil { if err != nil {
@ -73,24 +72,19 @@ func (h ConvertorHandler) getSockPath(file convertor.File, progressbar *widget.P
} }
data += string(buf) data += string(buf)
a := re.FindAllStringSubmatch(data, -1) a := re.FindAllStringSubmatch(data, -1)
cp := ""
if len(a) > 0 && len(a[len(a)-1]) > 0 { if len(a) > 0 && len(a[len(a)-1]) > 0 {
c, _ := strconv.Atoi(a[len(a)-1][len(a[len(a)-1])-1]) c, err := strconv.Atoi(a[len(a)-1][len(a[len(a)-1])-1])
if err != nil {
return
}
progress = float64(c) progress = float64(c)
cp = fmt.Sprintf("%.2f", float64(c)/totalDuration*100)
} }
if strings.Contains(data, "progress=end") { if strings.Contains(data, "progress=end") {
cp = "done"
progress = totalDuration progress = totalDuration
} }
if cp == "" { if progressbar.Value != progress {
cp = ".0"
}
if cp != progressMessage {
progressbar.Value = progress progressbar.Value = progress
progressbar.Refresh() progressbar.Refresh()
progressMessage = cp
fmt.Println("progress: ", progressMessage)
} }
} }
}() }()