修复: Bing壁纸浏览方向改为旧到新并保最新2000张

- 历史排序改为日期升序, 左键更旧右键更新, 位置显示 idx+1/total
- 修复排序翻转后裁剪逻辑误删最新图的问题, 改为淘汰最旧
- dislike跳过与定时切换同步改为向更新方向推进
This commit is contained in:
lxy
2026-10-03 10:19:26 +08:00
parent 2036c9c89a
commit 9b29dff067
3 changed files with 16 additions and 13 deletions
+13 -10
View File
@@ -315,23 +315,24 @@ func fetchBingHistory() {
allMap[k] = r
}
// Sort by date descending, then by market for determinism
// Sort by date ascending (oldest first), so index 0 = oldest, index N = newest
// Left-to-right navigation: left = older (smaller idx), right = newer (larger idx)
var records []BingRecord
for _, r := range allMap {
records = append(records, r)
}
sort.Slice(records, func(i, j int) bool {
if records[i].Date != records[j].Date {
return records[i].Date > records[j].Date
return records[i].Date < records[j].Date
}
return records[i].Market < records[j].Market
})
// ---- Phase 3: Enforce 2000 cap ----
if len(records) > maxBingRecords {
// Remove oldest records and their files
toRemove := records[maxBingRecords:]
records = records[:maxBingRecords]
// Records sorted oldest-first, so oldest are at the head
toRemove := records[:len(records)-maxBingRecords]
records = records[len(records)-maxBingRecords:]
for _, r := range toRemove {
p := filepath.Join(bingDir(), r.Filename)
os.Remove(p)
@@ -380,6 +381,7 @@ func getCurrentBingRecord() *BingRecord {
}
// bingPrev moves to the previous (older) image, skipping hidden ones.
// Records sorted oldest-first, so prev = decrement index.
func bingPrev() {
bingMu.Lock()
defer bingMu.Unlock()
@@ -390,7 +392,7 @@ func bingPrev() {
}
attempts := 0
for {
h.CurrentIdx = (h.CurrentIdx + 1) % len(h.Records)
h.CurrentIdx = (h.CurrentIdx - 1 + len(h.Records)) % len(h.Records)
if !h.Records[h.CurrentIdx].Hidden {
break
}
@@ -405,6 +407,7 @@ func bingPrev() {
}
// bingNext moves to the next (newer) image, skipping hidden ones.
// Records sorted oldest-first, so next = increment index.
func bingNext() {
bingMu.Lock()
defer bingMu.Unlock()
@@ -415,7 +418,7 @@ func bingNext() {
}
attempts := 0
for {
h.CurrentIdx = (h.CurrentIdx - 1 + len(h.Records)) % len(h.Records)
h.CurrentIdx = (h.CurrentIdx + 1) % len(h.Records)
if !h.Records[h.CurrentIdx].Hidden {
break
}
@@ -464,10 +467,10 @@ func bingToggleDislike() string {
if r.Hidden {
log.Printf("Bing 壁纸: 已隐藏 (date=%s)", r.Date)
// Advance to next visible
// Advance to next visible (newer = +1)
attempts := 0
for {
h.CurrentIdx = (h.CurrentIdx - 1 + len(h.Records)) % len(h.Records)
h.CurrentIdx = (h.CurrentIdx + 1) % len(h.Records)
if !h.Records[h.CurrentIdx].Hidden {
break
}
@@ -587,7 +590,7 @@ func bingWallpaperLoop() {
// Move to next (newer) image, skip hidden
attempts := 0
for {
h.CurrentIdx = (h.CurrentIdx - 1 + len(h.Records)) % len(h.Records)
h.CurrentIdx = (h.CurrentIdx + 1) % len(h.Records)
if !h.Records[h.CurrentIdx].Hidden {
break
}
@@ -84,7 +84,7 @@
<img v-if="bing.url" :src="bingThumb" class="w-16 h-10 object-cover rounded flex-shrink-0">
<div class="min-w-0">
<div class="text-xs font-medium text-[var(--text-muted)] truncate">{{ bing.copyright || 'Bing 每日壁纸' }}</div>
<div class="text-[10px] text-[var(--text-weak)]">{{ bing.idx > 0 ? `${bing.idx} / ${bing.total}` : '' }}</div>
<div class="text-[10px] text-[var(--text-weak)]">{{ bing.total > 0 ? `${bing.idx + 1} / ${bing.total}` : '' }}</div>
</div>
</div>
<div class="flex gap-1 flex-shrink-0">
+2 -2
View File
File diff suppressed because one or more lines are too long