3 Commits

Author SHA1 Message Date
messypy
289337f016 Keep Win32 GUI on one OS thread
All checks were successful
build-windows-exe / build (push) Successful in 1m35s
2026-07-27 23:36:06 +09:00
messypy
dadc65065c Load GUI history asynchronously
All checks were successful
build-windows-exe / build (push) Successful in 1m12s
2026-07-27 23:32:17 +09:00
messypy
4df1a5d71a Limit release workflow tests to internal packages
All checks were successful
build-windows-exe / build (push) Successful in 1m32s
2026-07-27 23:16:14 +09:00
4 changed files with 167 additions and 15 deletions

View File

@@ -25,7 +25,7 @@ jobs:
- name: Test
shell: bash
run: |
GO111MODULE=on go test ./...
GO111MODULE=on go test ./internal/...
- name: Build executables
shell: bash

View File

@@ -89,6 +89,22 @@ type historyExportResult struct {
SelectedCount int
}
type historyRefreshResult struct {
Rows []guiWorldVisitRow
CalendarCells []historyCalendarCell
DetailRows []historyDetailRow
DetailHeightPx int32
SelectedDate time.Time
Month time.Time
SelectedKeys map[string]bool
Status string
Regex string
FromDate string
ToDate string
Err error
Elapsed time.Duration
}
var historyEventsCacheMu sync.Mutex
var historyEventsCache struct {
jsonMod time.Time
@@ -106,11 +122,7 @@ func ensureHistoryState(app *guiApp) {
app.historySelectedKeys = map[string]bool{}
}
if app.historySelectedDate.IsZero() {
if latest := latestHistoryDate(); !latest.IsZero() {
app.historySelectedDate = latest
} else {
app.historySelectedDate = time.Now()
}
app.historySelectedDate = time.Now()
}
if app.historyMonth.IsZero() {
app.historyMonth = time.Date(app.historySelectedDate.Year(), app.historySelectedDate.Month(), 1, 0, 0, 0, 0, app.historySelectedDate.Location())
@@ -757,6 +769,124 @@ func refreshHistoryCache(app *guiApp, force bool) bool {
return true
}
func startHistoryRefresh(app *guiApp, force bool) bool {
if app == nil || app.historyRefreshRunning {
return false
}
if !force && app.historyCacheLoaded && !app.historyReloadPending {
return false
}
ensureHistoryState(app)
if app.historyRefreshResultCh == nil {
app.historyRefreshResultCh = make(chan historyRefreshResult, 1)
}
work := *app
work.historySelectedKeys = cloneHistorySelection(app.historySelectedKeys)
work.historyRefreshResultCh = nil
work.historyExportResultCh = nil
app.historyRefreshRunning = true
app.historyReloadPending = true
if strings.TrimSpace(app.historyStatus) == "" {
app.historyStatus = "reloading..."
}
hwnd := app.hwnd
go func(ch chan<- historyRefreshResult, work guiApp, hwnd uintptr) {
start := time.Now()
result := historyRefreshResult{
SelectedDate: work.historySelectedDate,
Month: work.historyMonth,
SelectedKeys: cloneHistorySelection(work.historySelectedKeys),
Regex: work.historyRegex,
FromDate: work.historyFromDate,
ToDate: work.historyToDate,
}
defer func() {
result.Elapsed = time.Since(start)
if r := recover(); r != nil {
result.Err = fmt.Errorf("refresh panic: %v", r)
}
select {
case ch <- result:
default:
}
if postMessageProc != nil && hwnd != 0 {
postMessageProc.Call(hwnd, uintptr(wmHistoryRefreshDone), 0, 0)
}
}()
refreshHistoryCache(&work, true)
result.Rows = append([]guiWorldVisitRow(nil), work.historyRows...)
result.CalendarCells = append([]historyCalendarCell(nil), work.historyCalendarCells...)
result.DetailRows = cloneHistoryDetailRows(work.historyDetailRows)
result.DetailHeightPx = work.historyDetailContentHeightPx
result.SelectedDate = work.historySelectedDate
result.Month = work.historyMonth
result.SelectedKeys = cloneHistorySelection(work.historySelectedKeys)
result.Status = work.historyStatus
}(app.historyRefreshResultCh, work, hwnd)
guiLog("history refresh start")
return true
}
func drainHistoryRefreshResult(app *guiApp) bool {
if app == nil || app.historyRefreshResultCh == nil || !app.historyRefreshRunning {
return false
}
handled := false
for {
select {
case res := <-app.historyRefreshResultCh:
handled = true
app.historyRefreshRunning = false
if res.Err != nil {
app.historyStatus = "reload failed: " + res.Err.Error()
app.historyReloadPending = true
guiLog(fmt.Sprintf("history refresh failed elapsed=%s err=%v", res.Elapsed, res.Err))
invalidateHistoryPanes(app)
continue
}
stale := !sameDay(app.historySelectedDate, res.SelectedDate) ||
!sameHistoryMonth(app.historyMonth, res.Month) ||
app.historyRegex != res.Regex ||
app.historyFromDate != res.FromDate ||
app.historyToDate != res.ToDate
if stale {
app.historyReloadPending = true
guiLog("history refresh stale; scheduling another refresh")
invalidateHistoryPanes(app)
continue
}
app.historyRows = res.Rows
app.historyCalendarCells = res.CalendarCells
app.historyDetailRows = res.DetailRows
app.historyDetailContentHeightPx = res.DetailHeightPx
app.historySelectedDate = res.SelectedDate
app.historyMonth = res.Month
app.historySelectedKeys = res.SelectedKeys
if app.historySelectedKeys == nil {
app.historySelectedKeys = map[string]bool{}
}
app.historyReloadPending = false
app.historyCacheLoaded = true
if strings.TrimSpace(res.Status) != "" {
app.historyStatus = res.Status
} else {
app.historyStatus = "reloaded: " + time.Now().Format("15:04:05")
}
guiLog(fmt.Sprintf("history refresh ok elapsed=%s rows=%d details=%d", res.Elapsed, len(res.Rows), len(res.DetailRows)))
invalidateHistoryPanes(app)
default:
return handled
}
}
}
func sameHistoryMonth(a, b time.Time) bool {
if a.IsZero() || b.IsZero() {
return a.IsZero() && b.IsZero()
}
return a.Year() == b.Year() && a.Month() == b.Month()
}
func requestHistoryRefresh(app *guiApp, reason string) {
if app == nil {
return

View File

@@ -56,6 +56,8 @@ func normalizeInitialTab(tab string) string {
switch strings.ToLower(strings.TrimSpace(tab)) {
case "join", "log", "logs":
return "join"
case "history", "hist":
return "history"
case "translate", "translation":
return "join"
case "settings", "setting", "config":

View File

@@ -9,6 +9,7 @@ import (
"os"
"path/filepath"
"regexp"
"runtime"
"runtime/debug"
"sort"
"strconv"
@@ -52,6 +53,7 @@ const (
wmCommandGUI = 0x0111
wmSetFont = 0x0030
wmHistoryExportDone = 0x0401
wmHistoryRefreshDone = 0x0402
enChange = 0x0300
enKillFocus = 0x0200
bnClicked = 0x0000
@@ -251,6 +253,8 @@ type guiApp struct {
historyReloadRect winRect
historyExportRect winRect
historyReloadPending bool
historyRefreshRunning bool
historyRefreshResultCh chan historyRefreshResult
historyCacheLoaded bool
historyDetailContentHeightPx int32
settingsExportDirEdit uintptr
@@ -325,6 +329,9 @@ func guiLog(text string) {
}
func runNativeGUI(initialTab string) error {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
user32 := syscall.NewLazyDLL("user32.dll")
kernel32 := syscall.NewLazyDLL("kernel32.dll")
gdi32 := syscall.NewLazyDLL("gdi32.dll")
@@ -466,7 +473,6 @@ func runNativeGUI(initialTab string) error {
app.historyExportCustom = strings.TrimSpace(guiCfg.HistoryExportCustom)
app.historyReloadPending = true
app.hFont = createAppFont(app.fontSize)
refreshHistoryCache(&app, true)
paneWndProc := syscall.NewCallback(func(hwnd uintptr, message uint32, wParam, lParam uintptr) uintptr {
defer func() {
if r := recover(); r != nil {
@@ -851,17 +857,31 @@ func runNativeGUI(initialTab string) error {
}
case wmTimerGUI:
drainHistoryExportResult(&app)
drainHistoryRefreshResult(&app)
reloadData := app.activeTab == "join" || app.activeTab == "translate"
if app.activeTab == "history" && app.historyReloadPending {
if refreshHistoryCache(&app, true) {
refreshGUI(setWindowText, &app, false)
}
startHistoryRefresh(&app, true)
refreshGUI(setWindowText, &app, false)
refreshSettingsControls(showWindowProc, setWindowPosProc, &app)
return 0
}
refreshGUI(setWindowText, &app, reloadData)
refreshSettingsControls(showWindowProc, setWindowPosProc, &app)
return 0
case wmHistoryRefreshDone:
drainHistoryRefreshResult(&app)
if invalidateRectProc != nil {
if app.leftHwnd != 0 {
invalidateRectProc.Call(app.leftHwnd, 0, 1)
}
if app.rightHwnd != 0 {
invalidateRectProc.Call(app.rightHwnd, 0, 1)
}
if app.hwnd != 0 {
invalidateRectProc.Call(app.hwnd, 0, 1)
}
}
return 0
case wmHistoryExportDone:
drainHistoryExportResult(&app)
if invalidateRectProc != nil {
@@ -974,6 +994,10 @@ func refreshGUI(setWindowText *syscall.LazyProc, app *guiApp, reloadData bool) {
if app == nil {
return
}
if app.activeTab == "history" && !reloadData {
syncPaneVisibility(app)
return
}
start := time.Now()
defer func() {
if d := time.Since(start); d > 100*time.Millisecond {
@@ -984,11 +1008,7 @@ func refreshGUI(setWindowText *syscall.LazyProc, app *guiApp, reloadData bool) {
instanceCount := app.currentUserCount
worldLabel := app.currentWorld
state := readRuntimeSnapshot()
historyDirty := false
historyNeedsRefresh := app.activeTab == "history" && (app.historyReloadPending || !app.historyCacheLoaded)
if historyNeedsRefresh {
historyDirty = refreshHistoryCache(app, false)
}
historyDirty := app.activeTab == "history" && app.historyReloadPending
if reloadData {
if app.activeTab == "translate" {
guiLog("refreshGUI activeTab=translate light refresh")