mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2026-12-01 18:10:16 +00:00
Fix the Reader View button sometimes disappearing from the article toolbar by re-syncing its state whenever the current article page changes and by ignoring stale extractor callbacks.
This commit is contained in:
1 parent
6144c25725
commit
3da877e99d
4 files changed
+47
-31
No files matched your search
@@ -61,6 +61,9 @@ public enum ArticleExtractorState: Sendable {
|
||||
guard let self else {
|
||||
return
|
||||
}
|
||||
guard self.state != .cancelled else {
|
||||
return
|
||||
}
|
||||
|
||||
if let error = error {
|
||||
self.state = .failedToParse
|
||||
|
||||
@@ -24,27 +24,26 @@ final class ArticleExtractorButton: UIButton {
|
||||
return indicator
|
||||
}()
|
||||
|
||||
// Re-assert the visuals even when the state hasn't changed, so a stale button self-heals.
|
||||
var buttonState: ArticleExtractorButtonState = .off {
|
||||
didSet {
|
||||
if buttonState != oldValue {
|
||||
switch buttonState {
|
||||
case .error:
|
||||
activityIndicator.stopAnimating()
|
||||
isUserInteractionEnabled = true
|
||||
setImage(Assets.Images.articleExtractorError, for: .normal)
|
||||
case .animated:
|
||||
setImage(nil, for: .normal)
|
||||
activityIndicator.startAnimating()
|
||||
isUserInteractionEnabled = false
|
||||
case .on:
|
||||
activityIndicator.stopAnimating()
|
||||
isUserInteractionEnabled = true
|
||||
setImage(Assets.Images.articleExtractorOn, for: .normal)
|
||||
case .off:
|
||||
activityIndicator.stopAnimating()
|
||||
isUserInteractionEnabled = true
|
||||
setImage(Assets.Images.articleExtractorOff, for: .normal)
|
||||
}
|
||||
switch buttonState {
|
||||
case .error:
|
||||
activityIndicator.stopAnimating()
|
||||
isUserInteractionEnabled = true
|
||||
setImage(Assets.Images.articleExtractorError, for: .normal)
|
||||
case .animated:
|
||||
setImage(nil, for: .normal)
|
||||
activityIndicator.startAnimating()
|
||||
isUserInteractionEnabled = false
|
||||
case .on:
|
||||
activityIndicator.stopAnimating()
|
||||
isUserInteractionEnabled = true
|
||||
setImage(Assets.Images.articleExtractorOn, for: .normal)
|
||||
case .off:
|
||||
activityIndicator.stopAnimating()
|
||||
isUserInteractionEnabled = true
|
||||
setImage(Assets.Images.articleExtractorOff, for: .normal)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,11 +84,13 @@ final class ArticleViewController: UIViewController {
|
||||
self.pendingSetViewController = controller
|
||||
} else {
|
||||
self.pageViewController.setViewControllers([controller], direction: .forward, animated: false, completion: nil)
|
||||
self.syncArticleExtractorButtonState()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
updateUI()
|
||||
syncArticleExtractorButtonState()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -481,9 +483,10 @@ extension ArticleViewController {
|
||||
extension ArticleViewController: WebViewControllerDelegate {
|
||||
|
||||
func webViewController(_ webViewController: WebViewController, articleExtractorButtonStateDidUpdate buttonState: ArticleExtractorButtonState) {
|
||||
if webViewController === currentWebViewController {
|
||||
articleExtractorButton.buttonState = buttonState
|
||||
guard webViewController === currentWebViewController else {
|
||||
return
|
||||
}
|
||||
syncArticleExtractorButtonState()
|
||||
}
|
||||
|
||||
}
|
||||
@@ -532,15 +535,18 @@ extension ArticleViewController: UIPageViewControllerDelegate {
|
||||
self.pendingSetViewController = pending
|
||||
} else {
|
||||
self.pageViewController.setViewControllers([pending], direction: .forward, animated: false, completion: nil)
|
||||
self.syncArticleExtractorButtonState()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
syncArticleExtractorButtonState()
|
||||
|
||||
guard finished, completed else { return }
|
||||
guard let article = currentWebViewController?.article else { return }
|
||||
|
||||
coordinator.selectArticle(article, animations: [.select, .scroll, .navigation])
|
||||
articleExtractorButton.buttonState = currentWebViewController?.articleExtractorButtonState ?? .off
|
||||
syncArticleExtractorButtonState()
|
||||
|
||||
for viewController in previousViewControllers {
|
||||
if let webViewController = viewController as? WebViewController {
|
||||
@@ -580,4 +586,8 @@ private extension ArticleViewController {
|
||||
return controller
|
||||
}
|
||||
|
||||
func syncArticleExtractorButtonState() {
|
||||
articleExtractorButton.buttonState = currentWebViewController?.articleExtractorButtonState ?? .off
|
||||
}
|
||||
|
||||
}
|
||||
@@ -350,22 +350,26 @@ final class WebViewController: UIViewController {
|
||||
extension WebViewController: ArticleExtractorDelegate {
|
||||
|
||||
func articleExtractionDidFail(with: Error) {
|
||||
guard articleExtractor != nil else {
|
||||
return
|
||||
}
|
||||
stopArticleExtractor()
|
||||
articleExtractorButtonState = .error
|
||||
loadWebView()
|
||||
}
|
||||
|
||||
func articleExtractionDidComplete(extractedArticle: ExtractedArticle) {
|
||||
if articleExtractor?.state != .cancelled {
|
||||
self.extractedArticle = extractedArticle
|
||||
if let restoreWindowScrollY = restoreWindowScrollY {
|
||||
windowScrollY = restoreWindowScrollY
|
||||
self.restoreWindowScrollY = nil
|
||||
}
|
||||
isShowingExtractedArticle = true
|
||||
loadWebView()
|
||||
articleExtractorButtonState = .on
|
||||
guard let articleExtractor, articleExtractor.state != .cancelled else {
|
||||
return
|
||||
}
|
||||
self.extractedArticle = extractedArticle
|
||||
if let restoreWindowScrollY = restoreWindowScrollY {
|
||||
windowScrollY = restoreWindowScrollY
|
||||
self.restoreWindowScrollY = nil
|
||||
}
|
||||
isShowingExtractedArticle = true
|
||||
loadWebView()
|
||||
articleExtractorButtonState = .on
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user