Inject the Accounts folder name so that it can be in different locations between the iOS and Mac Apps.

This commit is contained in:
Maurice Parker 2019-09-12 10:59:26 -05:00
parent ca191c9a4e
commit 5985b00480
3 changed files with 10 additions and 6 deletions

View File

@ -14,10 +14,11 @@ import Articles
public final class AccountManager: UnreadCountProvider {
public static let shared = AccountManager()
public static var shared: AccountManager!
public let defaultAccount: Account
private let accountsFolder = RSDataSubfolder(nil, "Accounts")!
private let accountsFolder: String
private var accountsDictionary = [String: Account]()
private let defaultAccountFolderName = "OnMyMac"
@ -71,7 +72,9 @@ public final class AccountManager: UnreadCountProvider {
return CombinedRefreshProgress(downloadProgressArray: downloadProgressArray)
}
public init() {
public init(accountsFolder: String) {
self.accountsFolder = accountsFolder
// The local "On My Mac" account must always exist, even if it's empty.
let localAccountFolder = (accountsFolder as NSString).appendingPathComponent("OnMyMac")
do {

View File

@ -69,6 +69,8 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations,
NSWindow.allowsAutomaticWindowTabbing = false
super.init()
AccountManager.shared = AccountManager(accountsFolder: RSDataSubfolder(nil, "Accounts")!)
NotificationCenter.default.addObserver(self, selector: #selector(unreadCountDidChange(_:)), name: .UnreadCountDidChange, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(inspectableObjectsDidChange(_:)), name: .InspectableObjectsDidChange, object: nil)

View File

@ -52,6 +52,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDele
super.init()
appDelegate = self
AccountManager.shared = AccountManager(accountsFolder: RSDataSubfolder(nil, "Accounts")!)
registerBackgroundTasks()
@ -59,9 +61,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDele
NotificationCenter.default.addObserver(self, selector: #selector(accountRefreshDidFinish(_:)), name: .AccountRefreshDidFinish, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(userDefaultsDidChange(_:)), name: UserDefaults.didChangeNotification, object: nil)
// Reinitialize the shared state as early as possible
_ = AccountManager.shared
}
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {