From ba482fa2ad52db8d1e1b5effbe10042ea2fb9649 Mon Sep 17 00:00:00 2001
From: Cola Chen <6825116+colachg@users.noreply.github.com>
Date: Thu, 26 Feb 2026 20:30:53 +0900
Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(favorites):=20sort=20favorites?=
=?UTF-8?q?=20by=20picture=20date=20instead=20of=20liked=20order?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Favorites are now displayed newest-first by Bing publication date,
replacing the previous insertion-order sorting. Bump version to 1.1.3.
---
CLAUDE.md | 10 +++++++
Resources/Info.plist | 4 +--
Sources/Wallpaper/WallpaperManager.swift | 2 +-
Tests/WallpaperTests/PreferencesTests.swift | 30 +++++++++++++++++++++
4 files changed, 43 insertions(+), 3 deletions(-)
diff --git a/CLAUDE.md b/CLAUDE.md
index 296605b..143e2a5 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -36,3 +36,13 @@ API endpoint: `https://www.bing.com/HPImageArchive.aspx?format=js&idx={idx}&n={c
- Bundle ID: `com.colachg.Wallpaper`
- `LSUIElement: true` (menu bar only, no dock icon)
- Info.plist lives in `Resources/` and is copied into the bundle by `just bundle`
+
+## Active Technologies
+- Swift 6.2+ (strict concurrency mode) + SwiftUI, AppKit (Apple frameworks only) (002-refactor-favorites-ux)
+- File-based — JSON preferences, cached JPEG images (002-refactor-favorites-ux)
+- Swift 6.2+ (strict concurrency) + SwiftUI, AppKit, Foundation (003-fix-dislike-behavior)
+- File-based (JSON preferences, cached JPEGs) (003-fix-dislike-behavior)
+- File-based — JSON preferences at `~/Library/Application Support/BingWallpaper/preferences.json` (004-sort-favorites-by-date)
+
+## Recent Changes
+- 002-refactor-favorites-ux: Added Swift 6.2+ (strict concurrency mode) + SwiftUI, AppKit (Apple frameworks only)
diff --git a/Resources/Info.plist b/Resources/Info.plist
index 0254a8f..50233db 100644
--- a/Resources/Info.plist
+++ b/Resources/Info.plist
@@ -9,9 +9,9 @@
CFBundleExecutable
Wallpaper
CFBundleVersion
- 1.1.2
+ 1.1.3
CFBundleShortVersionString
- 1.1.2
+ 1.1.3
CFBundlePackageType
APPL
CFBundleIconFile
diff --git a/Sources/Wallpaper/WallpaperManager.swift b/Sources/Wallpaper/WallpaperManager.swift
index d151efb..a7b35d2 100644
--- a/Sources/Wallpaper/WallpaperManager.swift
+++ b/Sources/Wallpaper/WallpaperManager.swift
@@ -46,7 +46,7 @@ class WallpaperManager {
}
var favoriteImages: [BingImage] {
- store.preferences.favorites
+ store.preferences.favorites.sorted { $0.startdate > $1.startdate }
}
var currentFavorite: BingImage? {
diff --git a/Tests/WallpaperTests/PreferencesTests.swift b/Tests/WallpaperTests/PreferencesTests.swift
index 3fd323c..57edca5 100644
--- a/Tests/WallpaperTests/PreferencesTests.swift
+++ b/Tests/WallpaperTests/PreferencesTests.swift
@@ -176,6 +176,36 @@ struct PreferencesStoreTests {
#expect(store.preferences.favorites.isEmpty)
}
+ @Test("favoriteImages returns favorites sorted by startdate descending")
+ @MainActor func favoritesSortedByDate() {
+ let store = makeStore()
+ // Add favorites in non-chronological order
+ store.addFavorite(BingImage(startdate: "20260215", urlbase: "/1", copyright: "©", title: "Jan 15"))
+ store.addFavorite(BingImage(startdate: "20260220", urlbase: "/2", copyright: "©", title: "Jan 20"))
+ store.addFavorite(BingImage(startdate: "20260210", urlbase: "/3", copyright: "©", title: "Jan 10"))
+
+ let sorted = store.preferences.favorites.sorted { $0.startdate > $1.startdate }
+ #expect(sorted[0].startdate == "20260220")
+ #expect(sorted[1].startdate == "20260215")
+ #expect(sorted[2].startdate == "20260210")
+ }
+
+ @Test("newly added favorite maintains date-sorted order")
+ @MainActor func newFavoriteMaintainsDateOrder() {
+ let store = makeStore()
+ // Add initial favorites
+ store.addFavorite(BingImage(startdate: "20260210", urlbase: "/1", copyright: "©", title: "Jan 10"))
+ store.addFavorite(BingImage(startdate: "20260220", urlbase: "/2", copyright: "©", title: "Jan 20"))
+ // Add a new favorite with a date between the existing ones
+ store.addFavorite(BingImage(startdate: "20260215", urlbase: "/3", copyright: "©", title: "Jan 15"))
+
+ let sorted = store.preferences.favorites.sorted { $0.startdate > $1.startdate }
+ #expect(sorted.count == 3)
+ #expect(sorted[0].startdate == "20260220")
+ #expect(sorted[1].startdate == "20260215")
+ #expect(sorted[2].startdate == "20260210")
+ }
+
@Test("load with corrupted file resets to defaults")
@MainActor func loadCorrupted() {
let url = FileManager.default.temporaryDirectory