Keep track of refresh beginning and finishing. Validate the refreshAll command (menu, toolbar).

This commit is contained in:
Brent Simmons 2017-10-07 14:40:14 -07:00
parent ea63f5e343
commit 5d8aa94dc3
7 changed files with 65 additions and 16 deletions

View File

@ -1,7 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="13526" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="13526"/>
<capability name="box content view" minToolsVersion="7.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>

View File

@ -8,6 +8,7 @@
import Cocoa
import Data
import Account
private let kWindowFrameKey = "MainWindow"
@ -29,7 +30,8 @@ class MainWindowController : NSWindowController, NSUserInterfaceValidations {
NotificationCenter.default.addObserver(self, selector: #selector(appNavigationKeyPressed(_:)), name: .AppNavigationKeyPressed, object: nil)
// NotificationCenter.default.addObserver(self, selector: #selector(refreshProgressDidChange(_:)), name: .AccountRefreshProgressDidChange, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(refreshProgressDidChange(_:)), name: .AccountRefreshDidBegin, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(refreshProgressDidChange(_:)), name: .AccountRefreshDidFinish, object: nil)
}
// MARK: Notifications

View File

@ -12,6 +12,12 @@ import Data
import RSParser
import Database
public extension Notification.Name {
public static let AccountRefreshDidBegin = Notification.Name(rawValue: "AccountRefreshDidBegin")
public static let AccountRefreshDidFinish = Notification.Name(rawValue: "AccountRefreshDidFinish")
}
public enum AccountType: Int {
// Raw values should not change since theyre stored on disk.
@ -28,7 +34,6 @@ public final class Account: DisplayNameProvider, Hashable {
public let accountID: String
public let type: AccountType
public var nameForDisplay = ""
public let delegate: AccountDelegate
public let hashValue: Int
let settingsFile: String
let dataFolder: String
@ -36,7 +41,19 @@ public final class Account: DisplayNameProvider, Hashable {
var topLevelObjects = [AnyObject]()
var feedIDDictionary = [String: Feed]()
var username: String?
var refreshInProgress = false
var refreshInProgress = false {
didSet {
if refreshInProgress != oldValue {
if refreshInProgress {
NotificationCenter.default.post(name: .AccountRefreshDidBegin, object: self)
}
else {
NotificationCenter.default.post(name: .AccountRefreshDidFinish, object: self)
}
}
}
}
var hasAtLeastOneFeed: Bool {
get {
@ -50,15 +67,20 @@ public final class Account: DisplayNameProvider, Hashable {
}
}
init?(dataFolder: String, settingsFile: String, type: AccountType, accountID: String) {
public lazy var delegate: AccountDelegate! = {
// TODO: support various syncing systems.
switch type {
case .onMyMac:
self.delegate = LocalAccountDelegate()
return LocalAccountDelegate(account: self)
default:
return nil
}
}()
init?(dataFolder: String, settingsFile: String, type: AccountType, accountID: String) {
self.accountID = accountID
self.type = type
@ -76,7 +98,7 @@ public final class Account: DisplayNameProvider, Hashable {
public func refreshAll() {
delegate.refreshAll(for: self)
delegate.refreshAll()
}
func update(_ feed: Feed, with parsedFeed: ParsedFeed, _ completion: RSVoidCompletionBlock) {

View File

@ -13,6 +13,8 @@ public protocol AccountDelegate {
// Local account does not; some synced accounts might.
var supportsSubFolders: Bool { get }
func refreshAll(for account: Account)
init(account: Account)
func refreshAll()
}

View File

@ -44,8 +44,8 @@ public final class AccountManager: UnreadCountProvider {
public var refreshInProgress: Bool {
get {
for oneAccount in accountsDictionary.values {
if oneAccount.refreshInProgress {
for account in accounts {
if account.refreshInProgress {
return true
}
}

View File

@ -8,13 +8,37 @@
import Foundation
struct LocalAccountDelegate: AccountDelegate {
final class LocalAccountDelegate: AccountDelegate {
let supportsSubFolders = false
private let refresher = LocalAccountRefresher()
private weak var account: Account?
func refreshAll(for account: Account) {
init(account: Account) {
self.account = account
NotificationCenter.default.addObserver(self, selector: #selector(downloadProgressDidChange(_:)), name: .DownloadProgressDidChange, object: refresher.progress)
}
func refreshAll() {
guard let account = account else {
return
}
account.refreshInProgress = true
refresher.refreshFeeds(account.flattenedFeeds())
}
// MARK: - Notifications
@objc func downloadProgressDidChange(_ note: Notification) {
if refresher.progress.numberRemaining < 1 {
account?.refreshInProgress = false
}
else {
account?.refreshInProgress = true
}
}
}