Skip to content

🐛 fix: resolve 11 correctness and efficiency issues from code review - #8

Merged
colachg merged 1 commit into
mainfrom
fix/code-review-findings
Aug 16, 2026
Merged

colachg merged 1 commit into
mainfrom
fix/code-review-findings

Conversation

@colachg

@colachg colachg commented Aug 16, 2026

Copy link
Copy Markdown
Owner

Summary

Full-project code review surfaced 11 issues; this PR fixes all of them. swift build clean, all 27 tests pass (5 suites).

Correctness

  • cleanOldCache calendar bug — DateFormatter now pinned to en_US_POSIX + Gregorian + GMT. Before, a non-Gregorian system calendar (e.g. Thai Buddhist) parsed 20260218 as 1483 CE and deleted the entire cache on every refresh.
  • Favorites desktop restore — browsing favorites snapshots the current desktop image and restores it when the panel closes. Before, the last-browsed favorite stayed on the desktop while the image card showed something else.
  • Background refresh vs favorites panel — timer/wake refresh no longer replaces the desktop while the favorites panel is open.
  • refresh() insert logic — only strictly newer dates are inserted at the head (preserving descending order), and currentIndex is shifted and clamped so subsequent like/dislike actions target the image actually shown.
  • Force-unwrapped URLs — API request built via URLComponents; image URL guarded. Malformed remote data now throws WallpaperError.invalidURL instead of crashing.
  • Navigation race — previous()/next()/applyFavorite() set isLoading, so rapid clicks can't launch overlapping downloads where the last to finish wins.
  • Locale-keyed cache — cache filenames derive from the image's urlbase instead of the current locale, so changing the system region no longer orphans cached favorites.
  • Preferences data loss — an unreadable preferences.json is moved aside as .corrupt before resetting, so the next save can't silently destroy all favorites and dislikes.
  • Semver parsing — isNewer parses components strictly (tolerating -rc suffixes). Before, compactMap dropped non-numeric parts and misaligned positions, so 1.beta.5 compared as newer than 1.2.0.
  • Launch-at-login drift — status re-read from SMAppService on window open and after toggling, so the UI tracks changes made in System Settings.

Efficiency

  • Favorites sorting — PreferencesStore maintains a pre-sorted favorites list updated on mutation; the view no longer performs ~5 full sorts per render pass (re-triggered on every hover).

Test plan

  • swift build — clean
  • swift test — 27/27 pass (requires Xcode toolchain: DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer swift test, or sudo xcode-select -s /Applications/Xcode.app/Contents/Developer once)
  • isNewer verified against all 9 existing cases plus 3 regression cases

Note

The cache-key change re-downloads currently cached images once. Old locale-keyed files age out via cleanOldCache, except those whose date matches a favorite — those linger as orphans since cleanup protects by date prefix.

🤖 Generated with Claude Code

- cleanOldCache: pin DateFormatter to en_US_POSIX/Gregorian/GMT so
  non-Gregorian system calendars can't parse cache dates as ancient
  and wipe the cache every refresh
- favorites: snapshot the desktop before browsing and restore it on
  exit, instead of leaving the last-browsed favorite behind while the
  card shows a different image
- refresh: skip auto-apply while the favorites panel is open; accept
  only strictly newer dates at the head; shift and clamp currentIndex
  on insert so actions target the image actually shown
- URLs: build the API request via URLComponents and guard the image
  URL instead of force-unwrapping remote-derived strings (new
  WallpaperError.invalidURL)
- navigation: set isLoading in previous()/next()/applyFavorite so
  rapid clicks can't race concurrent downloads and desktop writes
- cache keys: derive filenames from the image's urlbase instead of the
  current locale so a region change doesn't orphan cached favorites
- PreferencesStore: move an unreadable preferences.json aside as
  .corrupt before resetting, so the next save can't destroy all
  favorites and dislikes; maintain a pre-sorted favorites list so the
  view no longer re-sorts on every render
- UpdateChecker.isNewer: parse version components strictly (tolerating
  -rc suffixes) instead of compactMap silently dropping and
  misaligning parts
- launch-at-login: re-read SMAppService status on window open and
  after toggling, so the UI tracks System Settings

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@colachg colachg self-assigned this Aug 16, 2026
@colachg
colachg merged commit 56f76b8 into main Aug 16, 2026
2 checks passed
@colachg
colachg deleted the fix/code-review-findings branch August 16, 2026 07:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant