mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2025-08-12 06:26:36 +00:00
Make AccountManager and ArticleThemesManager self-initing.
This commit is contained in:
@@ -101,8 +101,8 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidat
|
||||
crashReporter = PLCrashReporter(configuration: crashReporterConfig)
|
||||
crashReporter.enable()
|
||||
|
||||
AccountManager.shared = AccountManager(accountsFolder: Platform.dataSubfolder(forApplication: nil, folderName: "Accounts")!)
|
||||
ArticleThemesManager.shared = ArticleThemesManager(folderPath: Platform.dataSubfolder(forApplication: nil, folderName: "Themes")!)
|
||||
_ = AccountManager.shared
|
||||
_ = ArticleThemesManager.shared
|
||||
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(unreadCountDidChange(_:)), name: .UnreadCountDidChange, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(inspectableObjectsDidChange(_:)), name: .InspectableObjectsDidChange, object: nil)
|
||||
|
||||
@@ -18,7 +18,7 @@ import RSDatabase
|
||||
|
||||
public final class AccountManager: UnreadCountProvider {
|
||||
|
||||
public static var shared: AccountManager!
|
||||
public static let shared = AccountManager()
|
||||
public static let netNewsWireNewsURL = "https://netnewswire.blog/feed.xml"
|
||||
private static let jsonNetNewsWireNewsURL = "https://netnewswire.blog/feed.json"
|
||||
|
||||
@@ -93,7 +93,10 @@ public final class AccountManager: UnreadCountProvider {
|
||||
public let combinedRefreshProgress = CombinedRefreshProgress()
|
||||
private let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "AccountManager")
|
||||
|
||||
public init(accountsFolder: String) {
|
||||
public init() {
|
||||
|
||||
let accountsFolderURL = AppConfig.dataSubfolder(named: "Accounts")
|
||||
let accountsFolder = accountsFolderURL.path
|
||||
self.accountsFolder = accountsFolder
|
||||
|
||||
// The local "On My Mac" account must always exist, even if it's empty.
|
||||
@@ -101,8 +104,7 @@ public final class AccountManager: UnreadCountProvider {
|
||||
do {
|
||||
try FileManager.default.createDirectory(atPath: localAccountFolder, withIntermediateDirectories: true, attributes: nil)
|
||||
} catch {
|
||||
assertionFailure("Could not create folder for OnMyMac account.")
|
||||
abort()
|
||||
fatalError("Could not create folder for OnMyMac account.")
|
||||
}
|
||||
|
||||
defaultAccount = Account(dataFolder: localAccountFolder, type: .onMyMac, accountID: defaultAccountIdentifier)
|
||||
|
||||
@@ -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)
|
||||
AccountManager.shared.existingAccount(with: accountID)
|
||||
}
|
||||
|
||||
var feed: Feed? {
|
||||
|
||||
@@ -16,7 +16,7 @@ public extension Notification.Name {
|
||||
|
||||
final class ArticleThemesManager: NSObject, NSFilePresenter {
|
||||
|
||||
static var shared: ArticleThemesManager!
|
||||
static let shared = ArticleThemesManager()
|
||||
public let folderPath: String
|
||||
|
||||
lazy var presentedItemOperationQueue = OperationQueue.main
|
||||
@@ -49,8 +49,9 @@ final class ArticleThemesManager: NSObject, NSFilePresenter {
|
||||
}
|
||||
}
|
||||
|
||||
init(folderPath: String) {
|
||||
self.folderPath = folderPath
|
||||
override init() {
|
||||
let folderURL = AppConfig.dataSubfolder(named: "Themes")
|
||||
self.folderPath = folderURL.path
|
||||
self.currentTheme = ArticleTheme.defaultTheme
|
||||
|
||||
super.init()
|
||||
|
||||
@@ -60,14 +60,8 @@ final class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationC
|
||||
override init() {
|
||||
super.init()
|
||||
|
||||
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)
|
||||
|
||||
let documentThemesFolder = documentFolder.appendingPathComponent("Themes").absoluteString
|
||||
let documentThemesFolderPath = String(documentThemesFolder.suffix(from: documentAccountsFolder.index(documentThemesFolder.startIndex, offsetBy: 7)))
|
||||
ArticleThemesManager.shared = ArticleThemesManager(folderPath: documentThemesFolderPath)
|
||||
_ = AccountManager.shared
|
||||
_ = ArticleThemesManager.shared
|
||||
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(unreadCountDidChange(_:)), name: .UnreadCountDidChange, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(accountRefreshDidFinish(_:)), name: .AccountRefreshDidFinish, object: nil)
|
||||
@@ -293,7 +287,7 @@ private extension AppDelegate {
|
||||
func updateUserInterfaceStyle() {
|
||||
|
||||
assert(Thread.isMainThread)
|
||||
guard let window = self.window else {
|
||||
guard let window else {
|
||||
// Could be nil legitimately — this can get called before window is set up.
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user