Compare commits
2 Commits
v0.1.3-tes
...
v0.1.3-tes
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
70bafabee9 | ||
|
|
8e704980c1 |
@@ -228,6 +228,7 @@ func historyVisitSource() []historyVisitRecord {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
if label, since, ok := currentWorldVisitInfo(); ok && strings.TrimSpace(label) != "" && !since.IsZero() {
|
if label, since, ok := currentWorldVisitInfo(); ok && strings.TrimSpace(label) != "" && !since.IsZero() {
|
||||||
|
if !hasOpenHistoryVisit(records, label, since) {
|
||||||
records = append(records, historyVisitRecord{
|
records = append(records, historyVisitRecord{
|
||||||
Key: historyVisitKey(label, since, time.Time{}, "", "", true),
|
Key: historyVisitKey(label, since, time.Time{}, "", "", true),
|
||||||
WorldLabel: label,
|
WorldLabel: label,
|
||||||
@@ -235,6 +236,7 @@ func historyVisitSource() []historyVisitRecord {
|
|||||||
Current: true,
|
Current: true,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
}
|
||||||
sort.SliceStable(records, func(i, j int) bool {
|
sort.SliceStable(records, func(i, j int) bool {
|
||||||
ti := records[i].End
|
ti := records[i].End
|
||||||
if ti.IsZero() {
|
if ti.IsZero() {
|
||||||
@@ -252,6 +254,22 @@ func historyVisitSource() []historyVisitRecord {
|
|||||||
return records
|
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 {
|
func historyVisitKey(label string, start, end time.Time, worldID, instanceID string, current bool) string {
|
||||||
key := strings.TrimSpace(label)
|
key := strings.TrimSpace(label)
|
||||||
if worldID != "" {
|
if worldID != "" {
|
||||||
@@ -1275,9 +1293,17 @@ func paintHistoryDetailPane(hwnd uintptr, app *guiApp) uintptr {
|
|||||||
border = clrAccentGreen
|
border = clrAccentGreen
|
||||||
}
|
}
|
||||||
drawSettingsBox(hdc, row.Rect, fill, border)
|
drawSettingsBox(hdc, row.Rect, fill, border)
|
||||||
|
duration := humanDurationLabel(row.Start, row.End, row.Current)
|
||||||
|
durationWidth := measureTextWidth(hdc, duration, app.hFont)
|
||||||
|
durationX := row.Rect.Right - 12 - durationWidth
|
||||||
|
if durationX < row.Rect.Left+260 {
|
||||||
|
durationX = row.Rect.Left + 260
|
||||||
|
}
|
||||||
drawPaneText(hdc, row.Rect.Left+12, y+6, "入室 "+historyEntryTimeLabel(row.Start, false, row.Current), app.hFont, clrMutedText)
|
drawPaneText(hdc, row.Rect.Left+12, y+6, "入室 "+historyEntryTimeLabel(row.Start, false, row.Current), app.hFont, clrMutedText)
|
||||||
drawPaneText(hdc, row.Rect.Left+146, y+6, "退室 "+historyEntryTimeLabel(row.End, true, row.Current), app.hFont, clrMutedText)
|
drawPaneText(hdc, row.Rect.Left+136, y+6, "退室 "+historyEntryTimeLabel(row.End, true, row.Current), app.hFont, clrMutedText)
|
||||||
drawPaneText(hdc, row.Rect.Right-110, y+6, humanDurationLabel(row.Start, row.End, row.Current), app.hFont, clrMutedText)
|
if durationX+durationWidth < row.Rect.Right-8 {
|
||||||
|
drawPaneText(hdc, durationX, y+6, duration, app.hFont, clrMutedText)
|
||||||
|
}
|
||||||
label := ellipsizeTextToWidth(hdc, row.WorldLabel, row.Rect.Right-row.Rect.Left-150, app.joinBoldHFont)
|
label := ellipsizeTextToWidth(hdc, row.WorldLabel, row.Rect.Right-row.Rect.Left-150, app.joinBoldHFont)
|
||||||
if label == "" {
|
if label == "" {
|
||||||
label = "(unknown)"
|
label = "(unknown)"
|
||||||
@@ -1373,12 +1399,12 @@ func isMidnight(t time.Time) bool {
|
|||||||
|
|
||||||
func historyEntryTimeLabel(t time.Time, isEnd bool, current bool) string {
|
func historyEntryTimeLabel(t time.Time, isEnd bool, current bool) string {
|
||||||
if t.IsZero() {
|
if t.IsZero() {
|
||||||
if current {
|
if current && isEnd {
|
||||||
return "now"
|
return "now"
|
||||||
}
|
}
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
if current {
|
if current && isEnd {
|
||||||
return "now"
|
return "now"
|
||||||
}
|
}
|
||||||
if isEnd && isMidnight(t) {
|
if isEnd && isMidnight(t) {
|
||||||
|
|||||||
@@ -43,6 +43,8 @@ const (
|
|||||||
wmPaint = 0x000F
|
wmPaint = 0x000F
|
||||||
wmEraseBkgnd = 0x0014
|
wmEraseBkgnd = 0x0014
|
||||||
wmSize = 0x0005
|
wmSize = 0x0005
|
||||||
|
wmNCCalcSize = 0x0083
|
||||||
|
wmNCPaint = 0x0085
|
||||||
wmGetMinMaxInfo = 0x0024
|
wmGetMinMaxInfo = 0x0024
|
||||||
wmVScroll = 0x0115
|
wmVScroll = 0x0115
|
||||||
wmMouseWheel = 0x020A
|
wmMouseWheel = 0x020A
|
||||||
@@ -589,6 +591,10 @@ func runNativeGUI(initialTab string) error {
|
|||||||
return paintMainWindow(hwnd, &app)
|
return paintMainWindow(hwnd, &app)
|
||||||
case wmEraseBkgnd:
|
case wmEraseBkgnd:
|
||||||
return 1
|
return 1
|
||||||
|
case wmNCCalcSize:
|
||||||
|
return 0
|
||||||
|
case wmNCPaint:
|
||||||
|
return 0
|
||||||
case wmGetMinMaxInfo:
|
case wmGetMinMaxInfo:
|
||||||
applyMinMaxInfo(lParam)
|
applyMinMaxInfo(lParam)
|
||||||
return 0
|
return 0
|
||||||
@@ -3253,6 +3259,7 @@ type guiWorldVisitRecord struct {
|
|||||||
type guiWorldHistoryFile struct {
|
type guiWorldHistoryFile struct {
|
||||||
UpdatedAt string `json:"updated_at"`
|
UpdatedAt string `json:"updated_at"`
|
||||||
Visits []guiWorldVisitRecord `json:"visits"`
|
Visits []guiWorldVisitRecord `json:"visits"`
|
||||||
|
Current *guiWorldVisitRecord `json:"current"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func readWorldHistory() []guiWorldVisitRecord {
|
func readWorldHistory() []guiWorldVisitRecord {
|
||||||
@@ -3278,6 +3285,9 @@ func readWorldHistory() []guiWorldVisitRecord {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
visits = snap.Visits
|
visits = snap.Visits
|
||||||
|
if snap.Current != nil && !snap.Current.StartedAt.IsZero() {
|
||||||
|
visits = append(visits, *snap.Current)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
out := dedupeWorldHistory(visits)
|
out := dedupeWorldHistory(visits)
|
||||||
if info, err := os.Stat(p); err == nil {
|
if info, err := os.Stat(p); err == nil {
|
||||||
@@ -3440,7 +3450,7 @@ func humanDurationLabel(started, ended time.Time, current bool) string {
|
|||||||
}
|
}
|
||||||
d := ended.Sub(started)
|
d := ended.Sub(started)
|
||||||
if current {
|
if current {
|
||||||
return formatDurationShort(d) + " active"
|
return formatDurationShort(d)
|
||||||
}
|
}
|
||||||
return formatDurationShort(d)
|
return formatDurationShort(d)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ type WorldVisit struct {
|
|||||||
type worldHistorySnapshot struct {
|
type worldHistorySnapshot struct {
|
||||||
UpdatedAt time.Time `json:"updated_at"`
|
UpdatedAt time.Time `json:"updated_at"`
|
||||||
Visits []WorldVisit `json:"visits"`
|
Visits []WorldVisit `json:"visits"`
|
||||||
|
Current *WorldVisit `json:"current,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type WorldHistoryTracker struct {
|
type WorldHistoryTracker struct {
|
||||||
@@ -61,6 +62,10 @@ func (t *WorldHistoryTracker) load() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
t.visits = mergeWorldVisits(snap.Visits)
|
t.visits = mergeWorldVisits(snap.Visits)
|
||||||
|
if snap.Current != nil && !snap.Current.StartedAt.IsZero() {
|
||||||
|
current := *snap.Current
|
||||||
|
t.current = ¤t
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -188,6 +193,7 @@ func (t *WorldHistoryTracker) persistLocked() error {
|
|||||||
return enc.Encode(worldHistorySnapshot{
|
return enc.Encode(worldHistorySnapshot{
|
||||||
UpdatedAt: time.Now(),
|
UpdatedAt: time.Now(),
|
||||||
Visits: mergeWorldVisits(t.visits),
|
Visits: mergeWorldVisits(t.visits),
|
||||||
|
Current: t.current,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user