From 1e713e3bfdfb30579e13be3259933f532ad0d5fe Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Wed, 15 Nov 2017 13:26:10 -0800 Subject: [PATCH] Update Account unread count when BatchUpdate did perform. --- Evergreen.xcodeproj/project.pbxproj | 4 -- Evergreen/BatchUpdate.swift | 65 ------------------- .../Sidebar/SidebarViewController.swift | 4 +- Frameworks/Account/Account.swift | 7 ++ Importers/DefaultFeedsImporter.swift | 1 + Importers/OPMLImporter.swift | 1 + 6 files changed, 11 insertions(+), 71 deletions(-) delete mode 100644 Evergreen/BatchUpdate.swift diff --git a/Evergreen.xcodeproj/project.pbxproj b/Evergreen.xcodeproj/project.pbxproj index 4df0e4130..4ce95aa7d 100644 --- a/Evergreen.xcodeproj/project.pbxproj +++ b/Evergreen.xcodeproj/project.pbxproj @@ -14,7 +14,6 @@ 842E45E71ED8C747000A8B52 /* DB5.plist in Resources */ = {isa = PBXBuildFile; fileRef = 842E45E61ED8C747000A8B52 /* DB5.plist */; }; 84513F901FAA63950023A1A9 /* FeedListControlsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84513F8F1FAA63950023A1A9 /* FeedListControlsView.swift */; }; 845F52ED1FB2B9FC00C10BF0 /* FeedPasteboardWriter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 845F52EC1FB2B9FC00C10BF0 /* FeedPasteboardWriter.swift */; }; - 846A7BEC1F872C5600FEFD30 /* BatchUpdate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 846A7BEB1F872C5600FEFD30 /* BatchUpdate.swift */; }; 846E773D1F6EF67A00A165E2 /* Account.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 846E773A1F6EF5D700A165E2 /* Account.framework */; }; 846E773E1F6EF67A00A165E2 /* Account.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 846E773A1F6EF5D700A165E2 /* Account.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 846E77411F6EF6A100A165E2 /* Database.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 846E77211F6EF5D100A165E2 /* Database.framework */; }; @@ -396,7 +395,6 @@ 842E45E61ED8C747000A8B52 /* DB5.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = DB5.plist; path = Evergreen/Resources/DB5.plist; sourceTree = ""; }; 84513F8F1FAA63950023A1A9 /* FeedListControlsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeedListControlsView.swift; sourceTree = ""; }; 845F52EC1FB2B9FC00C10BF0 /* FeedPasteboardWriter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeedPasteboardWriter.swift; sourceTree = ""; }; - 846A7BEB1F872C5600FEFD30 /* BatchUpdate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = BatchUpdate.swift; path = Evergreen/BatchUpdate.swift; sourceTree = ""; }; 846E77161F6EF5D000A165E2 /* Database.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = Database.xcodeproj; path = Frameworks/Database/Database.xcodeproj; sourceTree = ""; }; 846E77301F6EF5D600A165E2 /* Account.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = Account.xcodeproj; path = Frameworks/Account/Account.xcodeproj; sourceTree = ""; }; 84702AA31FA27AC0006B8943 /* MarkReadOrUnreadCommand.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MarkReadOrUnreadCommand.swift; sourceTree = ""; }; @@ -725,7 +723,6 @@ 842E45CD1ED8C308000A8B52 /* AppNotifications.swift */, 84DAEE311F870B390058304B /* DockBadge.swift */, 842E45DC1ED8C54B000A8B52 /* Browser.swift */, - 846A7BEB1F872C5600FEFD30 /* BatchUpdate.swift */, 84702AB31FA27AE8006B8943 /* Commands */, 842E45E11ED8C681000A8B52 /* MainWindow */, 842E45E01ED8C587000A8B52 /* Preferences */, @@ -1257,7 +1254,6 @@ 849A97671ED9EB96007D329B /* UnreadCountView.swift in Sources */, 84E95D241FB1087500552D99 /* ArticlePasteboardWriter.swift in Sources */, 84A6B6961FB8DBD2006754AC /* DinosaursWindowController.swift in Sources */, - 846A7BEC1F872C5600FEFD30 /* BatchUpdate.swift in Sources */, 849A975B1ED9EB0D007D329B /* ArticleUtilities.swift in Sources */, 84DAEE301F86CAFE0058304B /* OPMLImporter.swift in Sources */, 849A975C1ED9EB0D007D329B /* DefaultFeedsImporter.swift in Sources */, diff --git a/Evergreen/BatchUpdate.swift b/Evergreen/BatchUpdate.swift deleted file mode 100644 index f6742adf4..000000000 --- a/Evergreen/BatchUpdate.swift +++ /dev/null @@ -1,65 +0,0 @@ -// -// BatchUpdates.swift -// DataModel -// -// Created by Brent Simmons on 9/12/16. -// Copyright © 2016 Ranchero Software, LLC. All rights reserved. -// - -import Foundation - -public typealias BatchUpdateBlock = () -> Void - -public extension Notification.Name { - - public static let BatchUpdateDidFinish = Notification.Name(rawValue: "BatchUpdateDidFinish") -} - -final class BatchUpdate { - - static let shared = BatchUpdate() - - private var count = 0 - - var isPerforming: Bool { - get { - return count > 0 - } - } - - func perform(_ batchUpdateBlock: BatchUpdateBlock) { - - incrementCount() - batchUpdateBlock() - decrementCount() - } -} - -private extension BatchUpdate { - - func incrementCount() { - - count = count + 1 - } - - func decrementCount() { - - count = count - 1 - - if count < 1 { - - if count < 0 { - assertionFailure("Expected batch updates count to be 0 or greater.") - count = 0 - } - - count = 0 - postBatchUpdateDidPerform() - } - } - - func postBatchUpdateDidPerform() { - - NotificationCenter.default.post(name: .BatchUpdateDidFinish, object: nil, userInfo: nil) - } -} diff --git a/Evergreen/MainWindow/Sidebar/SidebarViewController.swift b/Evergreen/MainWindow/Sidebar/SidebarViewController.swift index ef5cb76f9..669e75995 100644 --- a/Evergreen/MainWindow/Sidebar/SidebarViewController.swift +++ b/Evergreen/MainWindow/Sidebar/SidebarViewController.swift @@ -33,7 +33,7 @@ import RSCore NotificationCenter.default.addObserver(self, selector: #selector(unreadCountDidChange(_:)), name: .UnreadCountDidChange, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(containerChildrenDidChange(_:)), name: .ChildrenDidChange, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(userDidAddFeed(_:)), name: .UserDidAddFeed, object: nil) - NotificationCenter.default.addObserver(self, selector: #selector(batchUpdateDidFinish(_:)), name: .BatchUpdateDidFinish, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(batchUpdateDidPerform(_:)), name: .BatchUpdateDidPerform, object: nil) outlineView.reloadData() } @@ -53,7 +53,7 @@ import RSCore rebuildTreeAndReloadDataIfNeeded() } - @objc dynamic func batchUpdateDidFinish(_ notification: Notification) { + @objc dynamic func batchUpdateDidPerform(_ notification: Notification) { rebuildTreeAndReloadDataIfNeeded() } diff --git a/Frameworks/Account/Account.swift b/Frameworks/Account/Account.swift index 48abbafb3..f0ebbdc97 100644 --- a/Frameworks/Account/Account.swift +++ b/Frameworks/Account/Account.swift @@ -132,6 +132,8 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container, NotificationCenter.default.addObserver(self, selector: #selector(unreadCountDidChange(_:)), name: .UnreadCountDidChange, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(batchUpdateDidPerform(_:)), name: .BatchUpdateDidPerform, object: nil) + pullObjectsFromDisk() DispatchQueue.main.async { @@ -360,6 +362,11 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container, } } } + + @objc func batchUpdateDidPerform(_ note: Notification) { + + updateUnreadCount() + } // MARK: - Equatable diff --git a/Importers/DefaultFeedsImporter.swift b/Importers/DefaultFeedsImporter.swift index 106233686..4dd8fa7b5 100644 --- a/Importers/DefaultFeedsImporter.swift +++ b/Importers/DefaultFeedsImporter.swift @@ -9,6 +9,7 @@ import Foundation import Data import Account +import RSCore typealias DiskFeedDictionary = [String: Any] diff --git a/Importers/OPMLImporter.swift b/Importers/OPMLImporter.swift index 4006d9b5a..aa88931b9 100644 --- a/Importers/OPMLImporter.swift +++ b/Importers/OPMLImporter.swift @@ -9,6 +9,7 @@ import Foundation import RSParser import Account +import RSCore struct OPMLImporter {