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"?> <?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"> <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> <dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="13526"/> <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="13526"/>
<capability name="box content view" minToolsVersion="7.0"/> <capability name="box content view" minToolsVersion="7.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>

View File

@ -8,6 +8,7 @@
import Cocoa import Cocoa
import Data import Data
import Account
private let kWindowFrameKey = "MainWindow" 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(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 // MARK: Notifications

View File

@ -12,6 +12,12 @@ import Data
import RSParser import RSParser
import Database 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 { public enum AccountType: Int {
// Raw values should not change since theyre stored on disk. // 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 accountID: String
public let type: AccountType public let type: AccountType
public var nameForDisplay = "" public var nameForDisplay = ""
public let delegate: AccountDelegate
public let hashValue: Int public let hashValue: Int
let settingsFile: String let settingsFile: String
let dataFolder: String let dataFolder: String
@ -36,7 +41,19 @@ public final class Account: DisplayNameProvider, Hashable {
var topLevelObjects = [AnyObject]() var topLevelObjects = [AnyObject]()
var feedIDDictionary = [String: Feed]() var feedIDDictionary = [String: Feed]()
var username: String? 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 { var hasAtLeastOneFeed: Bool {
get { get {
@ -49,16 +66,21 @@ public final class Account: DisplayNameProvider, Hashable {
return delegate.supportsSubFolders return delegate.supportsSubFolders
} }
} }
init?(dataFolder: String, settingsFile: String, type: AccountType, accountID: String) { public lazy var delegate: AccountDelegate! = {
// TODO: support various syncing systems.
switch type { switch type {
case .onMyMac: case .onMyMac:
self.delegate = LocalAccountDelegate() return LocalAccountDelegate(account: self)
default: default:
return nil return nil
} }
}()
init?(dataFolder: String, settingsFile: String, type: AccountType, accountID: String) {
self.accountID = accountID self.accountID = accountID
self.type = type self.type = type
@ -76,7 +98,7 @@ public final class Account: DisplayNameProvider, Hashable {
public func refreshAll() { public func refreshAll() {
delegate.refreshAll(for: self) delegate.refreshAll()
} }
func update(_ feed: Feed, with parsedFeed: ParsedFeed, _ completion: RSVoidCompletionBlock) { 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. // Local account does not; some synced accounts might.
var supportsSubFolders: Bool { get } 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 { public var refreshInProgress: Bool {
get { get {
for oneAccount in accountsDictionary.values { for account in accounts {
if oneAccount.refreshInProgress { if account.refreshInProgress {
return true return true
} }
} }

View File

@ -8,13 +8,37 @@
import Foundation import Foundation
struct LocalAccountDelegate: AccountDelegate { final class LocalAccountDelegate: AccountDelegate {
let supportsSubFolders = false let supportsSubFolders = false
private let refresher = LocalAccountRefresher() 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()) refresher.refreshFeeds(account.flattenedFeeds())
} }
// MARK: - Notifications
@objc func downloadProgressDidChange(_ note: Notification) {
if refresher.progress.numberRemaining < 1 {
account?.refreshInProgress = false
}
else {
account?.refreshInProgress = true
}
}
} }

View File

@ -23,7 +23,7 @@ final class LocalAccountRefresher {
return downloadSession.progress return downloadSession.progress
} }
} }
public func refreshFeeds(_ feeds: Set<Feed>) { public func refreshFeeds(_ feeds: Set<Feed>) {
downloadSession.downloadObjects(feeds as NSSet) downloadSession.downloadObjects(feeds as NSSet)