Skip to content

Commit

Permalink
Change to wait for doc.Find.Each to complete in ConnectTextChanged
Browse files Browse the repository at this point in the history
  • Loading branch information
Shimi9999 committed Oct 4, 2021
1 parent 6bae76b commit ef82675
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"
"strings"
"sync"

"github.com/PuerkitoBio/goquery"
"github.com/Shimi9999/checkbms"
Expand Down Expand Up @@ -206,18 +207,24 @@ func (w *BmsCheckerWindow) logTextArea() {
{Level_en: "WARNING", Level_ja: "警告", Color: "#e56b00"},
{Level_en: "NOTICE", Level_ja: "通知", Color: "#0000da"},
}
doc.Find("p span").Each(func(i int, s *goquery.Selection) {
for _, lc := range levelColors {
level := lc.Level_en
if w.setting.Language == "ja" {
level = lc.Level_ja
var wg sync.WaitGroup
wg.Add(1)
go func() {
defer wg.Done()
doc.Find("p span").Each(func(i int, s *goquery.Selection) {
for _, lc := range levelColors {
level := lc.Level_en
if w.setting.Language == "ja" {
level = lc.Level_ja
}
if strings.HasPrefix(s.Text(), level+": ") {
s.SetHtml(`<span style="color: ` + lc.Color + `">` + level + `</span>` + s.Text()[len(level):])
break
}
}
if strings.HasPrefix(s.Text(), level+": ") {
s.SetHtml(`<span style="color: ` + lc.Color + `">` + level + `</span>` + s.Text()[len(level):])
break
}
}
})
})
}()
wg.Wait()
w.isLogTextSet = false

_html, _ := doc.Html()
Expand Down

0 comments on commit ef82675

Please sign in to comment.