Do some cleanups on app code.
This commit is contained in:
parent
96bc93612e
commit
1ab282c23a
|
@ -23,6 +23,8 @@ final class AppDefaults {
|
|||
static let openInBrowserInBackground = "openInBrowserInBackground"
|
||||
}
|
||||
|
||||
let isFirstRun: Bool
|
||||
|
||||
var firstRunDate: Date? {
|
||||
get {
|
||||
return date(for: Key.firstRunDate)
|
||||
|
@ -43,6 +45,14 @@ final class AppDefaults {
|
|||
init() {
|
||||
|
||||
registerDefaults()
|
||||
|
||||
if self.firstRunDate == nil {
|
||||
self.isFirstRun = true
|
||||
self.firstRunDate = Date()
|
||||
}
|
||||
else {
|
||||
self.isFirstRun = false
|
||||
}
|
||||
}
|
||||
|
||||
func registerDefaults() {
|
||||
|
|
|
@ -15,6 +15,7 @@ import RSParser
|
|||
import RSWeb
|
||||
import Account
|
||||
|
||||
let appName = "Evergreen"
|
||||
var currentTheme: VSTheme!
|
||||
|
||||
@NSApplicationMain
|
||||
|
@ -45,19 +46,13 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations {
|
|||
|
||||
func applicationDidFinishLaunching(_ note: Notification) {
|
||||
|
||||
registerDefaults()
|
||||
let isFirstRun = AppDefaults.shared.isFirstRun
|
||||
|
||||
currentTheme = themeLoader.defaultTheme
|
||||
|
||||
let _ = AccountManager.sharedInstance
|
||||
|
||||
var isFirstRun = false
|
||||
if UserDefaults.standard.object(forKey: AppDefaultsKey.firstRunDate) == nil {
|
||||
isFirstRun = true
|
||||
UserDefaults.standard.set(Date(), forKey: AppDefaultsKey.firstRunDate)
|
||||
}
|
||||
|
||||
importDefaultFeedsIfNeeded(isFirstRun, account: AccountManager.sharedInstance.localAccount)
|
||||
importDefaultFeedsIfNeeded(isFirstRun, account: AccountManager.shared.localAccount)
|
||||
createAndShowMainWindow()
|
||||
|
||||
#if RELEASE
|
||||
|
@ -104,7 +99,6 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: Badge
|
||||
|
||||
private func updateBadgeCoalesced() {
|
||||
|
@ -122,7 +116,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations {
|
|||
|
||||
func unreadCountDidChange(_ note: Notification) {
|
||||
|
||||
let updatedUnreadCount = AccountManager.sharedInstance.unreadCount
|
||||
let updatedUnreadCount = AccountManager.shared.unreadCount
|
||||
if updatedUnreadCount != unreadCount {
|
||||
unreadCount = updatedUnreadCount
|
||||
}
|
||||
|
@ -150,10 +144,10 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations {
|
|||
func validateUserInterfaceItem(_ item: NSValidatedUserInterfaceItem) -> Bool {
|
||||
|
||||
if item.action == #selector(refreshAll(_:)) {
|
||||
return !AccountManager.sharedInstance.refreshInProgress
|
||||
return !AccountManager.shared.refreshInProgress
|
||||
}
|
||||
if item.action == #selector(addAppNews(_:)) {
|
||||
return !AccountManager.sharedInstance.anyAccountHasFeedWithURL(appNewsURLString)
|
||||
return !AccountManager.shared.anyAccountHasFeedWithURL(appNewsURLString)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
@ -168,7 +162,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations {
|
|||
addFeedController?.showAddFeedSheet(urlString, name)
|
||||
}
|
||||
|
||||
// MARK: Actions
|
||||
// MARK: - Actions
|
||||
|
||||
@IBAction func showPreferences(_ sender: AnyObject) {
|
||||
|
||||
|
@ -223,15 +217,13 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations {
|
|||
panel.allowsOtherFileTypes = false
|
||||
|
||||
let result = panel.runModal()
|
||||
if result == NSApplication.ModalResponse.OK {
|
||||
if let url = panel.url {
|
||||
DispatchQueue.main.async {
|
||||
self.parseAndImportOPML(url, AccountManager.sharedInstance.localAccount)
|
||||
}
|
||||
if result == NSApplication.ModalResponse.OK, let url = panel.url {
|
||||
DispatchQueue.main.async {
|
||||
self.parseAndImportOPML(url, AccountManager.sharedInstance.localAccount)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@IBAction func importOPMLFromURL(_ sender: AnyObject) {
|
||||
|
||||
}
|
||||
|
@ -249,21 +241,19 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations {
|
|||
panel.nameFieldStringValue = "MySubscriptions.opml"
|
||||
|
||||
let result = panel.runModal()
|
||||
if result.rawValue == NSFileHandlingPanelOKButton {
|
||||
if let url = panel.url {
|
||||
DispatchQueue.main.async {
|
||||
let opmlString = AccountManager.sharedInstance.localAccount.OPMLString(indentLevel: 0)
|
||||
do {
|
||||
try opmlString.write(to: url, atomically: true, encoding: String.Encoding.utf8)
|
||||
}
|
||||
catch let error as NSError {
|
||||
NSApplication.shared.presentError(error)
|
||||
}
|
||||
if result.rawValue == NSFileHandlingPanelOKButton, let url = panel.url {
|
||||
DispatchQueue.main.async {
|
||||
let opmlString = AccountManager.sharedInstance.localAccount.OPMLString(indentLevel: 0)
|
||||
do {
|
||||
try opmlString.write(to: url, atomically: true, encoding: String.Encoding.utf8)
|
||||
}
|
||||
catch let error as NSError {
|
||||
NSApplication.shared.presentError(error)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@IBAction func emailSupport(_ sender: AnyObject) {
|
||||
|
||||
let escapedAppName = appName.replacingOccurrences(of: " ", with: "%20")
|
||||
|
@ -276,7 +266,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations {
|
|||
|
||||
@IBAction func addAppNews(_ sender: AnyObject) {
|
||||
|
||||
if AccountManager.sharedInstance.anyAccountHasFeedWithURL(appNewsURLString) {
|
||||
if AccountManager.shared.anyAccountHasFeedWithURL(appNewsURLString) {
|
||||
return
|
||||
}
|
||||
addFeed(appNewsURLString, "Evergreen News")
|
||||
|
@ -303,6 +293,8 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations {
|
|||
}
|
||||
}
|
||||
|
||||
// MARK: -
|
||||
|
||||
private extension AppDelegate {
|
||||
|
||||
func parseAndImportOPML(_ url: URL, _ account: Account) {
|
||||
|
|
|
@ -8,8 +8,6 @@
|
|||
|
||||
import Foundation
|
||||
|
||||
let appName = "Evergreen"
|
||||
|
||||
extension Notification.Name {
|
||||
|
||||
static let SidebarSelectionDidChange = Notification.Name("SidebarSelectionDidChangeNotification")
|
||||
|
|
|
@ -17,7 +17,7 @@ private let localAccountIdentifier = "OnMyMac"
|
|||
|
||||
public final class AccountManager: UnreadCountProvider {
|
||||
|
||||
public static let sharedInstance = AccountManager()
|
||||
public static let shared = AccountManager()
|
||||
public let localAccount: Account
|
||||
private let accountsFolder = RSDataSubfolder(nil, "Accounts")!
|
||||
private var accountsDictionary = [String: Account]()
|
||||
|
|
Loading…
Reference in New Issue