diff options
| author | Fuwn <[email protected]> | 2025-03-01 04:37:10 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2025-03-01 04:37:10 -0800 |
| commit | ffa1c05f14400889905a450477a71443c5fe1741 (patch) | |
| tree | a03b022615fb47cf1546153a0a91a58f74ad4da3 /Sora/Views | |
| parent | feat: Development commit (diff) | |
| download | sora-testing-ffa1c05f14400889905a450477a71443c5fe1741.tar.xz sora-testing-ffa1c05f14400889905a450477a71443c5fe1741.zip | |
feat: Development commit
Diffstat (limited to 'Sora/Views')
| -rw-r--r-- | Sora/Views/Post/Details/PostDetailsCarouselView.swift | 21 | ||||
| -rw-r--r-- | Sora/Views/Settings/Section/SettingsDetailsView.swift | 12 |
2 files changed, 33 insertions, 0 deletions
diff --git a/Sora/Views/Post/Details/PostDetailsCarouselView.swift b/Sora/Views/Post/Details/PostDetailsCarouselView.swift index 378b9cc..de14477 100644 --- a/Sora/Views/Post/Details/PostDetailsCarouselView.swift +++ b/Sora/Views/Post/Details/PostDetailsCarouselView.swift @@ -7,6 +7,7 @@ struct PostDetailsCarouselView: View { let focusedPost: BooruPost? @Binding var loadingStage: BooruPostLoadingState @State private var currentIndex: Int + private let cacheManager = ImageCacheManager.shared init( posts: [BooruPost], @@ -61,9 +62,29 @@ struct PostDetailsCarouselView: View { } .onChange(of: currentIndex) { if currentIndex == posts.count - 1 { manager.loadNextPage() } + + preloadNearbyImages() } + .onAppear(perform: preloadNearbyImages) #if !os(macOS) .tabViewStyle(PageTabViewStyle(indexDisplayMode: .never)) #endif } + + private func preloadNearbyImages() { + let preloadRange = settings.preloadedCarouselImages + let startIndex = max(0, currentIndex - preloadRange) + let endIndex = min(posts.count - 1, currentIndex + preloadRange) + var urlsToPreload: [URL] = [] + + for index in startIndex...endIndex { + if let url = imageURL(post: posts[index]) { + urlsToPreload.append(url) + } + + urlsToPreload.append(posts[index].previewURL) + } + + cacheManager.preloadImages(urlsToPreload) + } } diff --git a/Sora/Views/Settings/Section/SettingsDetailsView.swift b/Sora/Views/Settings/Section/SettingsDetailsView.swift index 5abd394..885ef6f 100644 --- a/Sora/Views/Settings/Section/SettingsDetailsView.swift +++ b/Sora/Views/Settings/Section/SettingsDetailsView.swift @@ -21,5 +21,17 @@ struct SettingsDetailsView: View { Text("Saves post tags in a file alongside the downloaded image.") } #endif + + #if os(macOS) + Picker("Preloaded Images", selection: $settings.preloadedCarouselImages) { + ForEach(1...10, id: \.self) { columns in Text("\(columns)") } + } + #else + Stepper( + "Preloaded Images: \(settings.preloadedCarouselImages)", + value: $settings.preloadedCarouselImages, + in: 1...10 + ) + #endif } } |