Add ability to log items to AppDelegate.
This commit is contained in:
parent
bf45c3bdd9
commit
60ee139451
|
@ -17,6 +17,7 @@ import RSCore
|
||||||
|
|
||||||
let appName = "Evergreen"
|
let appName = "Evergreen"
|
||||||
var currentTheme: VSTheme!
|
var currentTheme: VSTheme!
|
||||||
|
var appDelegate: AppDelegate!
|
||||||
|
|
||||||
@NSApplicationMain
|
@NSApplicationMain
|
||||||
class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations {
|
class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations {
|
||||||
|
@ -30,7 +31,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations {
|
||||||
var addFeedController: AddFeedController?
|
var addFeedController: AddFeedController?
|
||||||
var addFolderWindowController: AddFolderWindowController?
|
var addFolderWindowController: AddFolderWindowController?
|
||||||
var keyboardShortcutsWindowController: WebViewWindowController?
|
var keyboardShortcutsWindowController: WebViewWindowController?
|
||||||
|
let log = Log()
|
||||||
let themeLoader = VSThemeLoader()
|
let themeLoader = VSThemeLoader()
|
||||||
private let appNewsURLString = "https://ranchero.com/evergreen/feed.json"
|
private let appNewsURLString = "https://ranchero.com/evergreen/feed.json"
|
||||||
private let dockBadge = DockBadge()
|
private let dockBadge = DockBadge()
|
||||||
|
@ -50,6 +51,18 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations {
|
||||||
dockBadge.appDelegate = self
|
dockBadge.appDelegate = self
|
||||||
|
|
||||||
NotificationCenter.default.addObserver(self, selector: #selector(unreadCountDidChange(_:)), name: .UnreadCountDidChange, object: nil)
|
NotificationCenter.default.addObserver(self, selector: #selector(unreadCountDidChange(_:)), name: .UnreadCountDidChange, object: nil)
|
||||||
|
appDelegate = self
|
||||||
|
}
|
||||||
|
|
||||||
|
func logMessage(_ message: String, type: LogItem.ItemType) {
|
||||||
|
|
||||||
|
let logItem = LogItem(type: type, message: message)
|
||||||
|
log.add(logItem)
|
||||||
|
}
|
||||||
|
|
||||||
|
func logDebugMessage(_ message: String) {
|
||||||
|
|
||||||
|
logMessage(message, type: .debug)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - NSApplicationDelegate
|
// MARK: - NSApplicationDelegate
|
||||||
|
@ -57,6 +70,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations {
|
||||||
func applicationDidFinishLaunching(_ note: Notification) {
|
func applicationDidFinishLaunching(_ note: Notification) {
|
||||||
|
|
||||||
let isFirstRun = AppDefaults.shared.isFirstRun
|
let isFirstRun = AppDefaults.shared.isFirstRun
|
||||||
|
logDebugMessage(isFirstRun ? "Is first run." : "Is not first run.")
|
||||||
let localAccount = AccountManager.shared.localAccount
|
let localAccount = AccountManager.shared.localAccount
|
||||||
DefaultFeedsImporter.importIfNeeded(isFirstRun, account: localAccount)
|
DefaultFeedsImporter.importIfNeeded(isFirstRun, account: localAccount)
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,11 @@ import Foundation
|
||||||
|
|
||||||
public class Log {
|
public class Log {
|
||||||
|
|
||||||
var logItems = [LogItem]()
|
public var logItems = [LogItem]()
|
||||||
|
|
||||||
|
public init() {
|
||||||
|
// Satisfy compiler
|
||||||
|
}
|
||||||
|
|
||||||
public func add(_ logItem: LogItem) {
|
public func add(_ logItem: LogItem) {
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ import Foundation
|
||||||
public struct LogItem: Hashable {
|
public struct LogItem: Hashable {
|
||||||
|
|
||||||
public enum ItemType {
|
public enum ItemType {
|
||||||
case notification, warning, error
|
case debug, notification, warning, error
|
||||||
}
|
}
|
||||||
|
|
||||||
public let type: ItemType
|
public let type: ItemType
|
||||||
|
|
Loading…
Reference in New Issue