From 23769bc3911c676f72ae122d347b617ee151f3eb Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Tue, 19 Dec 2017 17:48:30 -0800 Subject: [PATCH] =?UTF-8?q?Add=20AccountDelegate.accountDidInitialize=20me?= =?UTF-8?q?thod,=20so=20that=20the=20delegate=20can=20set=20the=20account?= =?UTF-8?q?=E2=80=99s=20nameForDisplay=20before=20anything=20else=20happen?= =?UTF-8?q?s.=20Fix=20#247.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Frameworks/Account/Account.swift | 4 +++- Frameworks/Account/AccountDelegate.swift | 4 ++++ Frameworks/Account/Feedbin/FeedbinAccountDelegate.swift | 6 +++++- Frameworks/Account/LocalAccount/LocalAccountDelegate.swift | 7 ++++++- 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/Frameworks/Account/Account.swift b/Frameworks/Account/Account.swift index 7284adbf9..7f9918455 100644 --- a/Frameworks/Account/Account.swift +++ b/Frameworks/Account/Account.swift @@ -124,7 +124,7 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container, self.settingsFile = settingsFile self.dataFolder = dataFolder self.hashValue = accountID.hashValue - + let databaseFilePath = (dataFolder as NSString).appendingPathComponent("DB.sqlite3") self.database = Database(databaseFilePath: databaseFilePath, accountID: accountID) @@ -142,6 +142,8 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container, self.updateUnreadCount() self.fetchAllUnreadCounts() } + + self.delegate.accountDidInitialize(self) } // MARK: - API diff --git a/Frameworks/Account/AccountDelegate.swift b/Frameworks/Account/AccountDelegate.swift index 9a28022b8..5da492f37 100644 --- a/Frameworks/Account/AccountDelegate.swift +++ b/Frameworks/Account/AccountDelegate.swift @@ -18,6 +18,10 @@ public protocol AccountDelegate { func refreshAll(for: Account) + // Called at the end of account’s init method. + + func accountDidInitialize(_ account: Account) + // Called at the end of initializing an Account using data from disk. // Delegate has complete control over what goes in userInfo and what it means. // Called even if userInfo is nil, since the delegate might have other diff --git a/Frameworks/Account/Feedbin/FeedbinAccountDelegate.swift b/Frameworks/Account/Feedbin/FeedbinAccountDelegate.swift index e71326e57..8083562e6 100644 --- a/Frameworks/Account/Feedbin/FeedbinAccountDelegate.swift +++ b/Frameworks/Account/Feedbin/FeedbinAccountDelegate.swift @@ -26,12 +26,16 @@ final class FeedbinAccountDelegate: AccountDelegate { // MARK: Disk - func update(account: Account, withUserInfo: NSDictionary?) { + func accountDidInitialize(_ account: Account) { // TODO: add username to account name account.nameForDisplay = NSLocalizedString("Feedbin", comment: "Feedbin Account Name") } + func update(account: Account, withUserInfo: NSDictionary?) { + + } + func userInfo(for: Account) -> NSDictionary? { // TODO: save username diff --git a/Frameworks/Account/LocalAccount/LocalAccountDelegate.swift b/Frameworks/Account/LocalAccount/LocalAccountDelegate.swift index 50cbb48b4..cdd636101 100644 --- a/Frameworks/Account/LocalAccount/LocalAccountDelegate.swift +++ b/Frameworks/Account/LocalAccount/LocalAccountDelegate.swift @@ -25,11 +25,16 @@ final class LocalAccountDelegate: AccountDelegate { refresher.refreshFeeds(account.flattenedFeeds()) } + func accountDidInitialize(_ account: Account) { + + account.nameForDisplay = NSLocalizedString("On My Mac", comment: "Local Account Name") + } + // MARK: Disk func update(account: Account, withUserInfo: NSDictionary?) { - account.nameForDisplay = NSLocalizedString("On My Mac", comment: "Local Account Name") + } func userInfo(for: Account) -> NSDictionary? {