From 70bafabee9243d2f954477ecc29abf77f3382898 Mon Sep 17 00:00:00 2001 From: messypy Date: Tue, 28 Jul 2026 00:51:15 +0900 Subject: [PATCH] Persist current world history --- cmd/vrc_osc_gui/history_view_windows.go | 30 ++++++++++++++++++++----- cmd/vrc_osc_gui/window_windows.go | 10 +++++++++ internal/app/world_history.go | 6 +++++ 3 files changed, 40 insertions(+), 6 deletions(-) diff --git a/cmd/vrc_osc_gui/history_view_windows.go b/cmd/vrc_osc_gui/history_view_windows.go index bcff799..8755df1 100644 --- a/cmd/vrc_osc_gui/history_view_windows.go +++ b/cmd/vrc_osc_gui/history_view_windows.go @@ -228,12 +228,14 @@ func historyVisitSource() []historyVisitRecord { }) } if label, since, ok := currentWorldVisitInfo(); ok && strings.TrimSpace(label) != "" && !since.IsZero() { - records = append(records, historyVisitRecord{ - Key: historyVisitKey(label, since, time.Time{}, "", "", true), - WorldLabel: label, - Start: since, - Current: true, - }) + if !hasOpenHistoryVisit(records, label, since) { + records = append(records, historyVisitRecord{ + Key: historyVisitKey(label, since, time.Time{}, "", "", true), + WorldLabel: label, + Start: since, + Current: true, + }) + } } sort.SliceStable(records, func(i, j int) bool { ti := records[i].End @@ -252,6 +254,22 @@ func historyVisitSource() []historyVisitRecord { return records } +func hasOpenHistoryVisit(records []historyVisitRecord, label string, since time.Time) bool { + label = strings.TrimSpace(label) + for _, record := range records { + if !record.End.IsZero() || record.Start.IsZero() { + continue + } + if !record.Start.Equal(since) { + continue + } + if strings.EqualFold(strings.TrimSpace(record.WorldLabel), label) { + return true + } + } + return false +} + func historyVisitKey(label string, start, end time.Time, worldID, instanceID string, current bool) string { key := strings.TrimSpace(label) if worldID != "" { diff --git a/cmd/vrc_osc_gui/window_windows.go b/cmd/vrc_osc_gui/window_windows.go index eef537f..aca517b 100644 --- a/cmd/vrc_osc_gui/window_windows.go +++ b/cmd/vrc_osc_gui/window_windows.go @@ -43,6 +43,8 @@ const ( wmPaint = 0x000F wmEraseBkgnd = 0x0014 wmSize = 0x0005 + wmNCCalcSize = 0x0083 + wmNCPaint = 0x0085 wmGetMinMaxInfo = 0x0024 wmVScroll = 0x0115 wmMouseWheel = 0x020A @@ -589,6 +591,10 @@ func runNativeGUI(initialTab string) error { return paintMainWindow(hwnd, &app) case wmEraseBkgnd: return 1 + case wmNCCalcSize: + return 0 + case wmNCPaint: + return 0 case wmGetMinMaxInfo: applyMinMaxInfo(lParam) return 0 @@ -3253,6 +3259,7 @@ type guiWorldVisitRecord struct { type guiWorldHistoryFile struct { UpdatedAt string `json:"updated_at"` Visits []guiWorldVisitRecord `json:"visits"` + Current *guiWorldVisitRecord `json:"current"` } func readWorldHistory() []guiWorldVisitRecord { @@ -3278,6 +3285,9 @@ func readWorldHistory() []guiWorldVisitRecord { return nil } visits = snap.Visits + if snap.Current != nil && !snap.Current.StartedAt.IsZero() { + visits = append(visits, *snap.Current) + } } out := dedupeWorldHistory(visits) if info, err := os.Stat(p); err == nil { diff --git a/internal/app/world_history.go b/internal/app/world_history.go index 7f2040d..a0972a7 100644 --- a/internal/app/world_history.go +++ b/internal/app/world_history.go @@ -25,6 +25,7 @@ type WorldVisit struct { type worldHistorySnapshot struct { UpdatedAt time.Time `json:"updated_at"` Visits []WorldVisit `json:"visits"` + Current *WorldVisit `json:"current,omitempty"` } type WorldHistoryTracker struct { @@ -61,6 +62,10 @@ func (t *WorldHistoryTracker) load() error { return err } t.visits = mergeWorldVisits(snap.Visits) + if snap.Current != nil && !snap.Current.StartedAt.IsZero() { + current := *snap.Current + t.current = ¤t + } return nil } @@ -188,6 +193,7 @@ func (t *WorldHistoryTracker) persistLocked() error { return enc.Encode(worldHistorySnapshot{ UpdatedAt: time.Now(), Visits: mergeWorldVisits(t.visits), + Current: t.current, }) }