Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 2 additions & 2 deletions Resources/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
<key>CFBundleExecutable</key>
<string>Wallpaper</string>
<key>CFBundleVersion</key>
<string>1.1.2</string>
<string>1.1.3</string>
<key>CFBundleShortVersionString</key>
<string>1.1.2</string>
<string>1.1.3</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleIconFile</key>
Expand Down
2 changes: 1 addition & 1 deletion Sources/Wallpaper/WallpaperManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class WallpaperManager {
}

var favoriteImages: [BingImage] {
store.preferences.favorites
store.preferences.favorites.sorted { $0.startdate > $1.startdate }
}

var currentFavorite: BingImage? {
Expand Down
30 changes: 30 additions & 0 deletions Tests/WallpaperTests/PreferencesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down