mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2026-12-06 04:07:54 +00:00
Merge branch 'main' of https://github.com/Ranchero-Software/NetNewsWire
This commit is contained in:
commit
63e08f34e8
5 files changed
+65
-29
No files matched your search
@@ -75,7 +75,7 @@ extension Notification.Name {
|
||||
|
||||
@MainActor func checkFeedIconURL() {
|
||||
if let iconURL = feed.iconURL, !Self.shouldIgnoreFeedIconURL(feed) {
|
||||
icon(forURL: iconURL, feed: feed) { (image) in
|
||||
icon(forURL: iconURL, feed: feed) { (image, isDefinitive) in
|
||||
Task { @MainActor in
|
||||
if self.cache[feed] != nil {
|
||||
return // already cached
|
||||
@@ -84,7 +84,10 @@ extension Notification.Name {
|
||||
self.cache[feed] = IconImage(image)
|
||||
self.cacheIconURLForFeedURL(iconURL: iconURL, feedURL: feed.url)
|
||||
self.postFeedIconDidBecomeAvailableNotification(feed)
|
||||
} else {
|
||||
} else if isDefinitive {
|
||||
// The declared icon failed or isn’t an image. A still-downloading
|
||||
// icon is no reason to fall back to the home page’s icon.
|
||||
// <https://github.com/Ranchero-Software/NetNewsWire/issues/5376>
|
||||
checkHomePageURL()
|
||||
}
|
||||
}
|
||||
@@ -94,16 +97,19 @@ extension Notification.Name {
|
||||
}
|
||||
}
|
||||
|
||||
if let previouslyFoundIconURL = ImageMetadataDatabase.shared.iconURL(forFeedURL: feed.url) {
|
||||
icon(forURL: previouslyFoundIconURL, feed: feed) { image in
|
||||
MainActor.assumeIsolated {
|
||||
if self.cache[feed] != nil {
|
||||
return // already cached
|
||||
}
|
||||
if let image {
|
||||
self.cache[feed] = IconImage(image)
|
||||
self.postFeedIconDidBecomeAvailableNotification(feed)
|
||||
}
|
||||
// The stored icon URL remembers an icon discovered via the home page. A feed
|
||||
// that declares its own icon supersedes it.
|
||||
// <https://github.com/Ranchero-Software/NetNewsWire/issues/5376>
|
||||
let feedDeclaresIconURL = feed.iconURL != nil && !Self.shouldIgnoreFeedIconURL(feed)
|
||||
|
||||
if !feedDeclaresIconURL, let previouslyFoundIconURL = ImageMetadataDatabase.shared.iconURL(forFeedURL: feed.url) {
|
||||
icon(forURL: previouslyFoundIconURL, feed: feed) { image, _ in
|
||||
if self.cache[feed] != nil {
|
||||
return // already cached
|
||||
}
|
||||
if let image {
|
||||
self.cache[feed] = IconImage(image)
|
||||
self.postFeedIconDidBecomeAvailableNotification(feed)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -206,7 +212,7 @@ private extension FeedIconDownloader {
|
||||
|
||||
if let url = metadata.bestWebsiteIconURL() {
|
||||
homePagesWithNoIconURL.remove(homePageURL)
|
||||
icon(forURL: url, feed: feed) { image in
|
||||
icon(forURL: url, feed: feed) { image, _ in
|
||||
Task { @MainActor in
|
||||
resultBlock(image, url)
|
||||
}
|
||||
@@ -218,18 +224,28 @@ private extension FeedIconDownloader {
|
||||
resultBlock(nil, nil)
|
||||
}
|
||||
|
||||
func icon(forURL url: String, feed: Feed, _ imageResultBlock: @escaping ImageResultBlock) {
|
||||
/// `isDefinitive` is false when the image is still downloading — imageDidBecomeAvailable
|
||||
/// re-runs icon(for:) when it arrives.
|
||||
func icon(forURL url: String, feed: Feed, _ imageResultBlock: @escaping @MainActor (RSImage?, _ isDefinitive: Bool) -> Void) {
|
||||
|
||||
let url = Self.sanitizedIconURL(url)
|
||||
|
||||
let kind = ActivityKind.downloadFeedImage(feedURL: url)
|
||||
if let imageData = imageDownloader.image(for: url, activityOwner: .feedImageDownloader, activityKind: kind, activityDetail: feed.nameForDisplay) {
|
||||
RSImage.image(with: imageData, imageResultBlock: imageResultBlock)
|
||||
RSImage.image(with: imageData) { image in
|
||||
imageResultBlock(image, true)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
let urlIsUnfetchable = !url.hasPrefix("http://") && !url.hasPrefix("https://")
|
||||
if urlIsUnfetchable || ImageMetadataDatabase.shared.recentlyFailed(url: url) {
|
||||
imageResultBlock(nil, true)
|
||||
return
|
||||
}
|
||||
|
||||
waitingForFeedURLs[url, default: Set<Feed>()].insert(feed)
|
||||
imageResultBlock(nil)
|
||||
imageResultBlock(nil, false)
|
||||
}
|
||||
|
||||
func postFeedIconDidBecomeAvailableNotification(_ feed: Feed) {
|
||||
|
||||
@@ -133,20 +133,25 @@ private extension IconImageCache {
|
||||
if Self.isNetNewsWireBrandedFeed(feed) {
|
||||
return IconImage.nnwFeedIcon
|
||||
}
|
||||
if let iconImage = feedIconImageCache[feedID] {
|
||||
return iconImage
|
||||
}
|
||||
|
||||
// The downloaders are the source of truth — consult them ahead of the local
|
||||
// dictionaries so a newly arrived icon replaces a stale one. The dictionaries
|
||||
// keep the last known icons across the downloaders’ low-memory and background flushes.
|
||||
// <https://github.com/Ranchero-Software/NetNewsWire/issues/5376>
|
||||
if let iconImage = FeedIconDownloader.shared.cachedIcon(for: feed) {
|
||||
feedIconImageCache[feedID] = iconImage
|
||||
return iconImage
|
||||
}
|
||||
if let faviconImage = faviconImageCache[feedID] {
|
||||
return faviconImage
|
||||
if let iconImage = feedIconImageCache[feedID] {
|
||||
return iconImage
|
||||
}
|
||||
if let faviconImage = FaviconDownloader.shared.cachedFaviconAsIcon(for: feed) {
|
||||
faviconImageCache[feedID] = faviconImage
|
||||
return faviconImage
|
||||
}
|
||||
if let faviconImage = faviconImageCache[feedID] {
|
||||
return faviconImage
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -61,6 +61,12 @@ final class ArticleViewController: UIViewController {
|
||||
didSet {
|
||||
Self.logger.debug("ArticleViewController: article didSet: \(self.article?.accountID ?? "nil") \(self.article?.articleID ?? "nil") \(self.article?.title ?? "nil")")
|
||||
|
||||
if oldValue != article {
|
||||
// The launch-restoration scroll position belongs only to the restored article.
|
||||
// <https://github.com/Ranchero-Software/NetNewsWire/issues/5243>
|
||||
restoreScrollPosition = nil
|
||||
}
|
||||
|
||||
if let controller = currentWebViewController, controller.article != article {
|
||||
controller.setArticle(article)
|
||||
if isPageTransitionInProgress {
|
||||
|
||||
@@ -156,6 +156,9 @@ final class WebViewController: UIViewController {
|
||||
|
||||
if article != self.article {
|
||||
self.article = article
|
||||
// A restoration offset belongs only to the article it was saved for.
|
||||
// <https://github.com/Ranchero-Software/NetNewsWire/issues/5243>
|
||||
restoreWindowScrollY = nil
|
||||
if updateView {
|
||||
if article?.feed?.readerViewAlwaysEnabled == true {
|
||||
startArticleExtractor()
|
||||
@@ -343,6 +346,7 @@ extension WebViewController: ArticleExtractorDelegate {
|
||||
self.extractedArticle = extractedArticle
|
||||
if let restoreWindowScrollY = restoreWindowScrollY {
|
||||
windowScrollY = restoreWindowScrollY
|
||||
self.restoreWindowScrollY = nil
|
||||
}
|
||||
isShowingExtractedArticle = true
|
||||
loadWebView()
|
||||
@@ -529,8 +533,14 @@ extension WebViewController: UIScrollViewDelegate {
|
||||
}
|
||||
|
||||
@objc func scrollPositionDidChange() {
|
||||
let articleIDWhenAsked = article?.articleID
|
||||
webView?.evaluateJavaScript("window.scrollY") { (scrollY, error) in
|
||||
guard error == nil else { return }
|
||||
// A late callback must not record the previous article’s offset.
|
||||
// <https://github.com/Ranchero-Software/NetNewsWire/issues/5243>
|
||||
guard articleIDWhenAsked == self.article?.articleID else {
|
||||
return
|
||||
}
|
||||
let javascriptScrollY = scrollY as? Int ?? 0
|
||||
// I don't know why this value gets returned sometimes, but it is in error
|
||||
guard javascriptScrollY != 33554432 else { return }
|
||||
|
||||
@@ -2547,21 +2547,20 @@ private extension SceneCoordinator {
|
||||
return false
|
||||
}
|
||||
|
||||
// Read values from UserDefaults (migration happens in restoreWindowState)
|
||||
let isShowingExtractedArticle = AppDefaults.shared.isShowingExtractedArticle
|
||||
let articleWindowScrollY = AppDefaults.shared.articleWindowScrollY
|
||||
|
||||
// A handoff or deep link opens the article at the top — the persisted scroll
|
||||
// position belongs to launch state restoration, not to this article.
|
||||
// <https://github.com/Ranchero-Software/NetNewsWire/issues/5243>
|
||||
switch sidebarItemID {
|
||||
|
||||
case .smartFeed, .folder:
|
||||
let found = selectSidebarItemAndArticle(sidebarItemID: sidebarItemID, articleID: articleID, isShowingExtractedArticle: isShowingExtractedArticle, articleWindowScrollY: articleWindowScrollY)
|
||||
let found = selectSidebarItemAndArticle(sidebarItemID: sidebarItemID, articleID: articleID)
|
||||
if found {
|
||||
treeControllerDelegate.addFilterException(sidebarItemID)
|
||||
}
|
||||
return found
|
||||
|
||||
case .feed:
|
||||
let found = selectSidebarItemAndArticle(sidebarItemID: sidebarItemID, articleID: articleID, isShowingExtractedArticle: isShowingExtractedArticle, articleWindowScrollY: articleWindowScrollY)
|
||||
let found = selectSidebarItemAndArticle(sidebarItemID: sidebarItemID, articleID: articleID)
|
||||
if found {
|
||||
treeControllerDelegate.addFilterException(sidebarItemID)
|
||||
if let sidebarItemNode = nodeFor(sidebarItemID: sidebarItemID), let folder = sidebarItemNode.parent?.representedObject as? Folder, let folderSidebarItemID = folder.sidebarItemID {
|
||||
@@ -2599,13 +2598,13 @@ private extension SceneCoordinator {
|
||||
return nil
|
||||
}
|
||||
|
||||
func selectSidebarItemAndArticle(sidebarItemID: SidebarItemIdentifier, articleID: String, isShowingExtractedArticle: Bool, articleWindowScrollY: Int) -> Bool {
|
||||
func selectSidebarItemAndArticle(sidebarItemID: SidebarItemIdentifier, articleID: String) -> Bool {
|
||||
guard let sidebarItemNode = nodeFor(sidebarItemID: sidebarItemID), let sidebarItemIndexPath = indexPathFor(sidebarItemNode) else {
|
||||
return false
|
||||
}
|
||||
|
||||
selectSidebarItem(indexPath: sidebarItemIndexPath) {
|
||||
self.selectArticleInCurrentFeed(articleID, isShowingExtractedArticle: isShowingExtractedArticle, articleWindowScrollY: articleWindowScrollY)
|
||||
self.selectArticleInCurrentFeed(articleID)
|
||||
}
|
||||
|
||||
return true
|
||||
|
||||
Reference in new issue
Block a user