mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2026-11-30 17:29:23 +00:00
Make AccountManager a singleton.
This commit is contained in:
1 parent
9efde554d4
commit
33a21ea482
4 files changed
+18
-12
No files matched your search
@@ -100,7 +100,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidat
|
||||
crashReporter.enable()
|
||||
|
||||
SecretsManager.provider = Secrets()
|
||||
AccountManager.shared = AccountManager(accountsFolder: Platform.dataSubfolder(forApplication: nil, folderName: "Accounts")!)
|
||||
AccountManager.shared.start()
|
||||
ArticleThemesManager.shared = ArticleThemesManager(folderPath: Platform.dataSubfolder(forApplication: nil, folderName: "Themes")!)
|
||||
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(unreadCountDidChange(_:)), name: .UnreadCountDidChange, object: nil)
|
||||
|
||||
@@ -16,9 +16,9 @@ import RSDatabase
|
||||
// Main thread only.
|
||||
|
||||
public final class AccountManager: UnreadCountProvider {
|
||||
public static var shared = AccountManager()
|
||||
|
||||
public static var shared: AccountManager!
|
||||
public static let netNewsWireNewsURL = "https://netnewswire.blog/feed.xml"
|
||||
public static let netNewsWireNewsURL = "https://netnewswire.blog/feed.xml"
|
||||
private static let jsonNetNewsWireNewsURL = "https://netnewswire.blog/feed.json"
|
||||
|
||||
public let defaultAccount: Account
|
||||
@@ -101,8 +101,10 @@ public final class AccountManager: UnreadCountProvider {
|
||||
|
||||
public let combinedRefreshProgress = CombinedRefreshProgress()
|
||||
|
||||
public init(accountsFolder: String) {
|
||||
self.accountsFolder = accountsFolder
|
||||
private var isActive = false
|
||||
|
||||
public init() {
|
||||
self.accountsFolder = AppConfig.dataSubfolder(named: "Accounts").path
|
||||
|
||||
// The local "On My Mac" account must always exist, even if it's empty.
|
||||
let localAccountFolder = (accountsFolder as NSString).appendingPathComponent("OnMyMac")
|
||||
@@ -118,6 +120,14 @@ public final class AccountManager: UnreadCountProvider {
|
||||
accountsDictionary[defaultAccount.accountID] = defaultAccount
|
||||
|
||||
readAccountsFromDisk()
|
||||
}
|
||||
|
||||
public func start() {
|
||||
guard !isActive else {
|
||||
assertionFailure("start called when isActive is already true")
|
||||
return
|
||||
}
|
||||
isActive = true
|
||||
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(unreadCountDidInitialize(_:)), name: .UnreadCountDidInitialize, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(unreadCountDidChange(_:)), name: .UnreadCountDidChange, object: nil)
|
||||
|
||||
@@ -50,11 +50,7 @@ extension Feed {
|
||||
public extension Article {
|
||||
|
||||
var account: Account? {
|
||||
// The force unwrapped shared instance was crashing Account.framework unit tests.
|
||||
guard let manager = AccountManager.shared else {
|
||||
return nil
|
||||
}
|
||||
return manager.existingAccount(with: accountID)
|
||||
return AccountManager.shared.existingAccount(with: accountID)
|
||||
}
|
||||
|
||||
var feed: Feed? {
|
||||
|
||||
@@ -57,8 +57,8 @@ final class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationC
|
||||
SecretsManager.provider = Secrets()
|
||||
let documentFolder = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
|
||||
let documentAccountsFolder = documentFolder.appendingPathComponent("Accounts").absoluteString
|
||||
let documentAccountsFolderPath = String(documentAccountsFolder.suffix(from: documentAccountsFolder.index(documentAccountsFolder.startIndex, offsetBy: 7)))
|
||||
AccountManager.shared = AccountManager(accountsFolder: documentAccountsFolderPath)
|
||||
|
||||
AccountManager.shared.start()
|
||||
|
||||
let documentThemesFolder = documentFolder.appendingPathComponent("Themes").absoluteString
|
||||
let documentThemesFolderPath = String(documentThemesFolder.suffix(from: documentAccountsFolder.index(documentThemesFolder.startIndex, offsetBy: 7)))
|
||||
|
||||
Reference in new issue
Block a user