diff --git a/Frameworks/Account/Account.swift b/Frameworks/Account/Account.swift index b9a8b60f2..73fe3ade3 100644 --- a/Frameworks/Account/Account.swift +++ b/Frameworks/Account/Account.swift @@ -12,6 +12,7 @@ import Articles import RSParser import ArticlesDatabase import RSWeb +import RSDatabase public extension Notification.Name { @@ -57,6 +58,12 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container, var username: String? static let saveQueue = CoalescingQueue(name: "Account Save Queue", interval: 1.0) + private let settingsODB: ODB + private let settingsTable: ODBTable + + private struct SettingsKey { + static let unreadCount = "unreadCount" + } public var dirty = false { didSet { if dirty && !refreshInProgress { @@ -69,6 +76,7 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container, didSet { if unreadCount != oldValue { postUnreadCountDidChangeNotification() + settingsTable.set(unreadCount, name: SettingsKey.unreadCount) } } } @@ -109,6 +117,14 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container, let databaseFilePath = (dataFolder as NSString).appendingPathComponent("DB.sqlite3") self.database = ArticlesDatabase(databaseFilePath: databaseFilePath, accountID: accountID) + let settingsODBFilePath = (dataFolder as NSString).appendingPathComponent("Settings.odb") + self.settingsODB = ODB(filepath: settingsODBFilePath) + self.settingsODB.vacuum() + let settingsPath = ODBPath.path(["settings"]) + self.settingsTable = settingsODB.ensureTable(settingsPath)! + let unreadCount = self.settingsTable.rawValue(SettingsKey.unreadCount) as? Int ?? 0 + self.unreadCount = unreadCount + NotificationCenter.default.addObserver(self, selector: #selector(downloadProgressDidChange(_:)), name: .DownloadProgressDidChange, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(unreadCountDidChange(_:)), name: .UnreadCountDidChange, object: nil) @@ -552,11 +568,11 @@ private extension Account { children = objects(with: childrenArray) rebuildFeedDictionaries() - if let savedUnreadCount = d[Key.unreadCount] as? Int { - DispatchQueue.main.async { - self.unreadCount = savedUnreadCount - } - } +// if let savedUnreadCount = d[Key.unreadCount] as? Int { +// DispatchQueue.main.async { +// self.unreadCount = savedUnreadCount +// } +// } let userInfo = d[Key.userInfo] as? NSDictionary delegate.update(account: self, withUserInfo: userInfo) @@ -577,7 +593,7 @@ private extension Account { var d = [String: Any]() d[Key.children] = diskObjects as NSArray - d[Key.unreadCount] = unreadCount +// d[Key.unreadCount] = unreadCount if let userInfo = delegate.userInfo(for: self) { d[Key.userInfo] = userInfo diff --git a/Frameworks/Account/Account.xcodeproj/project.pbxproj b/Frameworks/Account/Account.xcodeproj/project.pbxproj index 6bee3655a..148193ee3 100644 --- a/Frameworks/Account/Account.xcodeproj/project.pbxproj +++ b/Frameworks/Account/Account.xcodeproj/project.pbxproj @@ -31,6 +31,7 @@ 84C3654A1F899F3B001EC85C /* CombinedRefreshProgress.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84C365491F899F3B001EC85C /* CombinedRefreshProgress.swift */; }; 84C8B3F41F89DE430053CCA6 /* DataExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84C8B3F31F89DE430053CCA6 /* DataExtensions.swift */; }; 84CAD7161FDF2E22000F0755 /* FeedbinArticle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84CAD7151FDF2E22000F0755 /* FeedbinArticle.swift */; }; + 84EAC4822148CC6300F154AB /* RSDatabase.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 84EAC4812148CC6300F154AB /* RSDatabase.framework */; }; 84F73CF1202788D90000BCEF /* ArticleFetcher.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84F73CF0202788D80000BCEF /* ArticleFetcher.swift */; }; /* End PBXBuildFile section */ @@ -107,6 +108,7 @@ 84C365491F899F3B001EC85C /* CombinedRefreshProgress.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CombinedRefreshProgress.swift; sourceTree = ""; }; 84C8B3F31F89DE430053CCA6 /* DataExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataExtensions.swift; sourceTree = ""; }; 84CAD7151FDF2E22000F0755 /* FeedbinArticle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeedbinArticle.swift; sourceTree = ""; }; + 84EAC4812148CC6300F154AB /* RSDatabase.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = RSDatabase.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 84F73CF0202788D80000BCEF /* ArticleFetcher.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ArticleFetcher.swift; sourceTree = ""; }; D511EEB5202422BB00712EC3 /* Account_project_debug.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Account_project_debug.xcconfig; sourceTree = ""; }; D511EEB6202422BB00712EC3 /* Account_target.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Account_target.xcconfig; sourceTree = ""; }; @@ -120,6 +122,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 84EAC4822148CC6300F154AB /* RSDatabase.framework in Frameworks */, 844B2981210CE3BF004020B3 /* RSWeb.framework in Frameworks */, 841D4D722106B40A00DD04E6 /* Articles.framework in Frameworks */, 841D4D702106B40400DD04E6 /* ArticlesDatabase.framework in Frameworks */, @@ -182,6 +185,7 @@ 8469F80F1F6DC3C10084783E /* Frameworks */ = { isa = PBXGroup; children = ( + 84EAC4812148CC6300F154AB /* RSDatabase.framework */, 844B2980210CE3BF004020B3 /* RSWeb.framework */, 841D4D712106B40A00DD04E6 /* Articles.framework */, 841D4D6F2106B40400DD04E6 /* ArticlesDatabase.framework */, diff --git a/submodules/RSDatabase b/submodules/RSDatabase index ee63138a1..b35c65044 160000 --- a/submodules/RSDatabase +++ b/submodules/RSDatabase @@ -1 +1 @@ -Subproject commit ee63138a1e36c11aa717ba733080b6394e6662d1 +Subproject commit b35c6504414bb4694aded8fc09715d4903e74b14