NetNewsWire-Mac AppDefaults is now a singleton

This commit is contained in:
Stuart Breckenridge 2020-07-02 11:17:38 +08:00
parent f92b219cdc
commit a57f98e4e7
18 changed files with 110 additions and 107 deletions

View File

@ -15,6 +15,9 @@ enum FontSize: Int {
} }
struct AppDefaults { struct AppDefaults {
static var shared = AppDefaults()
private init() {}
struct Key { struct Key {
static let firstRunDate = "firstRunDate" static let firstRunDate = "firstRunDate"
@ -50,14 +53,14 @@ struct AppDefaults {
private static let smallestFontSizeRawValue = FontSize.small.rawValue private static let smallestFontSizeRawValue = FontSize.small.rawValue
private static let largestFontSizeRawValue = FontSize.veryLarge.rawValue private static let largestFontSizeRawValue = FontSize.veryLarge.rawValue
static let isDeveloperBuild: Bool = { let isDeveloperBuild: Bool = {
if let dev = Bundle.main.object(forInfoDictionaryKey: "DeveloperEntitlements") as? String, dev == "-dev" { if let dev = Bundle.main.object(forInfoDictionaryKey: "DeveloperEntitlements") as? String, dev == "-dev" {
return true return true
} }
return false return false
}() }()
static let isFirstRun: Bool = { var isFirstRun: Bool = {
if let _ = UserDefaults.standard.object(forKey: Key.firstRunDate) as? Date { if let _ = UserDefaults.standard.object(forKey: Key.firstRunDate) as? Date {
return false return false
} }
@ -65,7 +68,7 @@ struct AppDefaults {
return true return true
}() }()
static var windowState: [AnyHashable : Any]? { var windowState: [AnyHashable : Any]? {
get { get {
return UserDefaults.standard.object(forKey: Key.windowState) as? [AnyHashable : Any] return UserDefaults.standard.object(forKey: Key.windowState) as? [AnyHashable : Any]
} }
@ -74,7 +77,7 @@ struct AppDefaults {
} }
} }
static var activeExtensionPointIDs: [[AnyHashable : AnyHashable]]? { var activeExtensionPointIDs: [[AnyHashable : AnyHashable]]? {
get { get {
return UserDefaults.standard.object(forKey: Key.activeExtensionPointIDs) as? [[AnyHashable : AnyHashable]] return UserDefaults.standard.object(forKey: Key.activeExtensionPointIDs) as? [[AnyHashable : AnyHashable]]
} }
@ -83,160 +86,160 @@ struct AppDefaults {
} }
} }
static var lastImageCacheFlushDate: Date? { var lastImageCacheFlushDate: Date? {
get { get {
return date(for: Key.lastImageCacheFlushDate) return AppDefaults.date(for: Key.lastImageCacheFlushDate)
} }
set { set {
setDate(for: Key.lastImageCacheFlushDate, newValue) AppDefaults.setDate(for: Key.lastImageCacheFlushDate, newValue)
} }
} }
static var openInBrowserInBackground: Bool { var openInBrowserInBackground: Bool {
get { get {
return bool(for: Key.openInBrowserInBackground) return AppDefaults.bool(for: Key.openInBrowserInBackground)
} }
set { set {
setBool(for: Key.openInBrowserInBackground, newValue) AppDefaults.setBool(for: Key.openInBrowserInBackground, newValue)
} }
} }
static var sidebarFontSize: FontSize { var sidebarFontSize: FontSize {
get { get {
return fontSize(for: Key.sidebarFontSize) return fontSize(for: Key.sidebarFontSize)
} }
set { set {
setFontSize(for: Key.sidebarFontSize, newValue) AppDefaults.setFontSize(for: Key.sidebarFontSize, newValue)
} }
} }
static var timelineFontSize: FontSize { var timelineFontSize: FontSize {
get { get {
return fontSize(for: Key.timelineFontSize) return fontSize(for: Key.timelineFontSize)
} }
set { set {
setFontSize(for: Key.timelineFontSize, newValue) AppDefaults.setFontSize(for: Key.timelineFontSize, newValue)
} }
} }
static var detailFontSize: FontSize { var detailFontSize: FontSize {
get { get {
return fontSize(for: Key.detailFontSize) return fontSize(for: Key.detailFontSize)
} }
set { set {
setFontSize(for: Key.detailFontSize, newValue) AppDefaults.setFontSize(for: Key.detailFontSize, newValue)
} }
} }
static var addWebFeedAccountID: String? { var addWebFeedAccountID: String? {
get { get {
return string(for: Key.addWebFeedAccountID) return AppDefaults.string(for: Key.addWebFeedAccountID)
} }
set { set {
setString(for: Key.addWebFeedAccountID, newValue) AppDefaults.setString(for: Key.addWebFeedAccountID, newValue)
} }
} }
static var addWebFeedFolderName: String? { var addWebFeedFolderName: String? {
get { get {
return string(for: Key.addWebFeedFolderName) return AppDefaults.string(for: Key.addWebFeedFolderName)
} }
set { set {
setString(for: Key.addWebFeedFolderName, newValue) AppDefaults.setString(for: Key.addWebFeedFolderName, newValue)
} }
} }
static var addFolderAccountID: String? { var addFolderAccountID: String? {
get { get {
return string(for: Key.addFolderAccountID) return AppDefaults.string(for: Key.addFolderAccountID)
} }
set { set {
setString(for: Key.addFolderAccountID, newValue) AppDefaults.setString(for: Key.addFolderAccountID, newValue)
} }
} }
static var importOPMLAccountID: String? { var importOPMLAccountID: String? {
get { get {
return string(for: Key.importOPMLAccountID) return AppDefaults.string(for: Key.importOPMLAccountID)
} }
set { set {
setString(for: Key.importOPMLAccountID, newValue) AppDefaults.setString(for: Key.importOPMLAccountID, newValue)
} }
} }
static var exportOPMLAccountID: String? { var exportOPMLAccountID: String? {
get { get {
return string(for: Key.exportOPMLAccountID) return AppDefaults.string(for: Key.exportOPMLAccountID)
} }
set { set {
setString(for: Key.exportOPMLAccountID, newValue) AppDefaults.setString(for: Key.exportOPMLAccountID, newValue)
} }
} }
static var defaultBrowserID: String? { var defaultBrowserID: String? {
get { get {
return string(for: Key.defaultBrowserID) return AppDefaults.string(for: Key.defaultBrowserID)
} }
set { set {
setString(for: Key.defaultBrowserID, newValue) AppDefaults.setString(for: Key.defaultBrowserID, newValue)
} }
} }
static var showTitleOnMainWindow: Bool { var showTitleOnMainWindow: Bool {
return bool(for: Key.showTitleOnMainWindow) return AppDefaults.bool(for: Key.showTitleOnMainWindow)
} }
static var showDebugMenu: Bool { var showDebugMenu: Bool {
return bool(for: Key.showDebugMenu) return AppDefaults.bool(for: Key.showDebugMenu)
} }
static var hideDockUnreadCount: Bool { var hideDockUnreadCount: Bool {
return bool(for: Key.hideDockUnreadCount) return AppDefaults.bool(for: Key.hideDockUnreadCount)
} }
#if !MAC_APP_STORE #if !MAC_APP_STORE
static var webInspectorEnabled: Bool { var webInspectorEnabled: Bool {
get { get {
return bool(for: Key.webInspectorEnabled) return AppDefaults.bool(for: Key.webInspectorEnabled)
} }
set { set {
setBool(for: Key.webInspectorEnabled, newValue) AppDefaults.setBool(for: Key.webInspectorEnabled, newValue)
} }
} }
static var webInspectorStartsAttached: Bool { var webInspectorStartsAttached: Bool {
get { get {
return bool(for: Key.webInspectorStartsAttached) return AppDefaults.bool(for: Key.webInspectorStartsAttached)
} }
set { set {
setBool(for: Key.webInspectorStartsAttached, newValue) AppDefaults.setBool(for: Key.webInspectorStartsAttached, newValue)
} }
} }
#endif #endif
static var timelineSortDirection: ComparisonResult { var timelineSortDirection: ComparisonResult {
get { get {
return sortDirection(for: Key.timelineSortDirection) return AppDefaults.sortDirection(for: Key.timelineSortDirection)
} }
set { set {
setSortDirection(for: Key.timelineSortDirection, newValue) AppDefaults.setSortDirection(for: Key.timelineSortDirection, newValue)
} }
} }
static var timelineGroupByFeed: Bool { var timelineGroupByFeed: Bool {
get { get {
return bool(for: Key.timelineGroupByFeed) return AppDefaults.bool(for: Key.timelineGroupByFeed)
} }
set { set {
setBool(for: Key.timelineGroupByFeed, newValue) AppDefaults.setBool(for: Key.timelineGroupByFeed, newValue)
} }
} }
static var timelineShowsSeparators: Bool { var timelineShowsSeparators: Bool {
return bool(for: Key.timelineShowsSeparators) return AppDefaults.bool(for: Key.timelineShowsSeparators)
} }
static var refreshInterval: RefreshInterval { var refreshInterval: RefreshInterval {
get { get {
let rawValue = UserDefaults.standard.integer(forKey: Key.refreshInterval) let rawValue = UserDefaults.standard.integer(forKey: Key.refreshInterval)
return RefreshInterval(rawValue: rawValue) ?? RefreshInterval.everyHour return RefreshInterval(rawValue: rawValue) ?? RefreshInterval.everyHour
@ -246,7 +249,7 @@ struct AppDefaults {
} }
} }
static func registerDefaults() { func registerDefaults() {
#if DEBUG #if DEBUG
let showDebugMenu = true let showDebugMenu = true
#else #else
@ -278,7 +281,7 @@ struct AppDefaults {
// TODO: revisit the above when coming back to state restoration issues. // TODO: revisit the above when coming back to state restoration issues.
} }
static func actualFontSize(for fontSize: FontSize) -> CGFloat { func actualFontSize(for fontSize: FontSize) -> CGFloat {
switch fontSize { switch fontSize {
case .small: case .small:
return NSFont.systemFontSize return NSFont.systemFontSize
@ -296,14 +299,14 @@ private extension AppDefaults {
static var firstRunDate: Date? { static var firstRunDate: Date? {
get { get {
return date(for: Key.firstRunDate) return AppDefaults.date(for: Key.firstRunDate)
} }
set { set {
setDate(for: Key.firstRunDate, newValue) AppDefaults.setDate(for: Key.firstRunDate, newValue)
} }
} }
static func fontSize(for key: String) -> FontSize { func fontSize(for key: String) -> FontSize {
// Punted till after 1.0. // Punted till after 1.0.
return .medium return .medium

View File

@ -191,8 +191,8 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations,
} }
#endif #endif
AppDefaults.registerDefaults() AppDefaults.shared.registerDefaults()
let isFirstRun = AppDefaults.isFirstRun let isFirstRun = AppDefaults.shared.isFirstRun
if isFirstRun { if isFirstRun {
logDebugMessage("Is first run.") logDebugMessage("Is first run.")
} }
@ -237,7 +237,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations,
UNUserNotificationCenter.current().delegate = self UNUserNotificationCenter.current().delegate = self
userNotificationManager = UserNotificationManager() userNotificationManager = UserNotificationManager()
if AppDefaults.showDebugMenu { if AppDefaults.shared.showDebugMenu {
refreshTimer!.update() refreshTimer!.update()
syncTimer!.update() syncTimer!.update()
@ -417,7 +417,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations,
} }
#if !MAC_APP_STORE #if !MAC_APP_STORE
if item.action == #selector(toggleWebInspectorEnabled(_:)) { if item.action == #selector(toggleWebInspectorEnabled(_:)) {
(item as! NSMenuItem).state = AppDefaults.webInspectorEnabled ? .on : .off (item as! NSMenuItem).state = AppDefaults.shared.webInspectorEnabled ? .on : .off
} }
#endif #endif
return true return true
@ -447,7 +447,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations,
// MARK: - Dock Badge // MARK: - Dock Badge
@objc func updateDockBadge() { @objc func updateDockBadge() {
let label = unreadCount > 0 && !AppDefaults.hideDockUnreadCount ? "\(unreadCount)" : "" let label = unreadCount > 0 && !AppDefaults.shared.hideDockUnreadCount ? "\(unreadCount)" : ""
NSApplication.shared.dockTile.badgeLabel = label NSApplication.shared.dockTile.badgeLabel = label
} }
@ -624,16 +624,16 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations,
@IBAction func sortByOldestArticleOnTop(_ sender: Any?) { @IBAction func sortByOldestArticleOnTop(_ sender: Any?) {
AppDefaults.timelineSortDirection = .orderedAscending AppDefaults.shared.timelineSortDirection = .orderedAscending
} }
@IBAction func sortByNewestArticleOnTop(_ sender: Any?) { @IBAction func sortByNewestArticleOnTop(_ sender: Any?) {
AppDefaults.timelineSortDirection = .orderedDescending AppDefaults.shared.timelineSortDirection = .orderedDescending
} }
@IBAction func groupByFeedToggled(_ sender: NSMenuItem) { @IBAction func groupByFeedToggled(_ sender: NSMenuItem) {
AppDefaults.timelineGroupByFeed.toggle() AppDefaults.shared.timelineGroupByFeed.toggle()
} }
@IBAction func checkForUpdates(_ sender: Any?) { @IBAction func checkForUpdates(_ sender: Any?) {
@ -680,13 +680,13 @@ extension AppDelegate {
@IBAction func toggleWebInspectorEnabled(_ sender: Any?) { @IBAction func toggleWebInspectorEnabled(_ sender: Any?) {
#if !MAC_APP_STORE #if !MAC_APP_STORE
let newValue = !AppDefaults.webInspectorEnabled let newValue = !AppDefaults.shared.webInspectorEnabled
AppDefaults.webInspectorEnabled = newValue AppDefaults.shared.webInspectorEnabled = newValue
// An attached inspector can display incorrectly on certain setups (like mine); default to displaying in a separate window, // An attached inspector can display incorrectly on certain setups (like mine); default to displaying in a separate window,
// and reset the default to a separate window when the preference is toggled off and on again in case the inspector is // and reset the default to a separate window when the preference is toggled off and on again in case the inspector is
// accidentally reattached. // accidentally reattached.
AppDefaults.webInspectorStartsAttached = false AppDefaults.shared.webInspectorStartsAttached = false
NotificationCenter.default.post(name: .WebInspectorEnabledDidChange, object: newValue) NotificationCenter.default.post(name: .WebInspectorEnabledDidChange, object: newValue)
#endif #endif
} }
@ -717,13 +717,13 @@ private extension AppDelegate {
func updateSortMenuItems() { func updateSortMenuItems() {
let sortByNewestOnTop = AppDefaults.timelineSortDirection == .orderedDescending let sortByNewestOnTop = AppDefaults.shared.timelineSortDirection == .orderedDescending
sortByNewestArticleOnTopMenuItem.state = sortByNewestOnTop ? .on : .off sortByNewestArticleOnTopMenuItem.state = sortByNewestOnTop ? .on : .off
sortByOldestArticleOnTopMenuItem.state = sortByNewestOnTop ? .off : .on sortByOldestArticleOnTopMenuItem.state = sortByNewestOnTop ? .off : .on
} }
func updateGroupByFeedMenuItem() { func updateGroupByFeedMenuItem() {
let groupByFeedEnabled = AppDefaults.timelineGroupByFeed let groupByFeedEnabled = AppDefaults.shared.timelineGroupByFeed
groupArticlesByFeedMenuItem.state = groupByFeedEnabled ? .on : .off groupArticlesByFeedMenuItem.state = groupByFeedEnabled ? .on : .off
} }
} }

View File

@ -16,7 +16,7 @@ struct Browser {
/// The user-assigned default browser, or `nil` if none was assigned /// The user-assigned default browser, or `nil` if none was assigned
/// (i.e., the system default should be used). /// (i.e., the system default should be used).
static var defaultBrowser: MacWebBrowser? { static var defaultBrowser: MacWebBrowser? {
if let bundleID = AppDefaults.defaultBrowserID, let browser = MacWebBrowser(bundleIdentifier: bundleID) { if let bundleID = AppDefaults.shared.defaultBrowserID, let browser = MacWebBrowser(bundleIdentifier: bundleID) {
return browser return browser
} }
@ -31,7 +31,7 @@ struct Browser {
/// - invert: Whether to invert the "open in background in browser" preference /// - invert: Whether to invert the "open in background in browser" preference
static func open(_ urlString: String, invertPreference invert: Bool = false) { static func open(_ urlString: String, invertPreference invert: Bool = false) {
// Opens according to prefs. // Opens according to prefs.
open(urlString, inBackground: invert ? !AppDefaults.openInBrowserInBackground : AppDefaults.openInBrowserInBackground) open(urlString, inBackground: invert ? !AppDefaults.shared.openInBrowserInBackground : AppDefaults.shared.openInBrowserInBackground)
} }
@ -56,7 +56,7 @@ struct Browser {
extension Browser { extension Browser {
static var titleForOpenInBrowserInverted: String { static var titleForOpenInBrowserInverted: String {
let openInBackgroundPref = AppDefaults.openInBrowserInBackground let openInBackgroundPref = AppDefaults.shared.openInBrowserInBackground
return openInBackgroundPref ? return openInBackgroundPref ?
NSLocalizedString("Open in Browser in Foreground", comment: "Open in Browser in Foreground menu item title") : NSLocalizedString("Open in Browser in Foreground", comment: "Open in Browser in Foreground menu item title") :

View File

@ -36,7 +36,7 @@ class AddFolderWindowController : NSWindowController {
// MARK: - NSViewController // MARK: - NSViewController
override func windowDidLoad() { override func windowDidLoad() {
let preferredAccountID = AppDefaults.addFolderAccountID let preferredAccountID = AppDefaults.shared.addFolderAccountID
accountPopupButton.removeAllItems() accountPopupButton.removeAllItems()
let menu = NSMenu() let menu = NSMenu()
@ -93,7 +93,7 @@ private extension AddFolderWindowController {
} }
let account = menuItem.representedObject as! Account let account = menuItem.representedObject as! Account
AppDefaults.addFolderAccountID = account.accountID AppDefaults.shared.addFolderAccountID = account.accountID
let folderName = self.folderNameTextField.stringValue let folderName = self.folderNameTextField.stringValue
if folderName.isEmpty { if folderName.isEmpty {

View File

@ -116,7 +116,7 @@ final class DetailWebViewController: NSViewController, WKUIDelegate {
waitingForFirstReload = true waitingForFirstReload = true
#if !MAC_APP_STORE #if !MAC_APP_STORE
webInspectorEnabled = AppDefaults.webInspectorEnabled webInspectorEnabled = AppDefaults.shared.webInspectorEnabled
NotificationCenter.default.addObserver(self, selector: #selector(webInspectorEnabledDidChange(_:)), name: .WebInspectorEnabledDidChange, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(webInspectorEnabledDidChange(_:)), name: .WebInspectorEnabledDidChange, object: nil)
#endif #endif

View File

@ -61,7 +61,7 @@ class MainWindowController : NSWindowController, NSUserInterfaceValidations {
sharingServicePickerDelegate = SharingServicePickerDelegate(self.window) sharingServicePickerDelegate = SharingServicePickerDelegate(self.window)
if !AppDefaults.showTitleOnMainWindow { if !AppDefaults.shared.showTitleOnMainWindow {
window?.titleVisibility = .hidden window?.titleVisibility = .hidden
} }
@ -116,12 +116,12 @@ class MainWindowController : NSWindowController, NSUserInterfaceValidations {
} }
func saveStateToUserDefaults() { func saveStateToUserDefaults() {
AppDefaults.windowState = savableState() AppDefaults.shared.windowState = savableState()
window?.saveFrame(usingName: windowAutosaveName) window?.saveFrame(usingName: windowAutosaveName)
} }
func restoreStateFromUserDefaults() { func restoreStateFromUserDefaults() {
if let state = AppDefaults.windowState { if let state = AppDefaults.shared.windowState {
restoreState(from: state) restoreState(from: state)
window?.setFrameUsingName(windowAutosaveName, force: true) window?.setFrameUsingName(windowAutosaveName, force: true)
} }
@ -281,7 +281,7 @@ class MainWindowController : NSWindowController, NSUserInterfaceValidations {
@IBAction func openInBrowserUsingOppositeOfSettings(_ sender: Any?) { @IBAction func openInBrowserUsingOppositeOfSettings(_ sender: Any?) {
if let link = currentLink { if let link = currentLink {
Browser.open(link, inBackground: !AppDefaults.openInBrowserInBackground) Browser.open(link, inBackground: !AppDefaults.shared.openInBrowserInBackground)
} }
} }
@ -819,7 +819,7 @@ private extension MainWindowController {
} }
func validateToggleArticleExtractor(_ item: NSValidatedUserInterfaceItem) -> Bool { func validateToggleArticleExtractor(_ item: NSValidatedUserInterfaceItem) -> Bool {
guard !AppDefaults.isDeveloperBuild else { guard !AppDefaults.shared.isDeveloperBuild else {
return false return false
} }

View File

@ -82,7 +82,7 @@ private extension NNW3ImportController {
guard let account = accessoryViewController.selectedAccount else { guard let account = accessoryViewController.selectedAccount else {
return return
} }
AppDefaults.importOPMLAccountID = account.accountID AppDefaults.shared.importOPMLAccountID = account.accountID
NNW3ImportController.importSubscriptionsPlist(subscriptionsPlistURL, into: account) NNW3ImportController.importSubscriptionsPlist(subscriptionsPlistURL, into: account)
} }

View File

@ -39,7 +39,7 @@ final class NNW3OpenPanelAccessoryViewController: NSViewController {
menuItem.representedObject = account menuItem.representedObject = account
menu.addItem(menuItem) menu.addItem(menuItem)
if account.accountID == AppDefaults.importOPMLAccountID { if account.accountID == AppDefaults.shared.importOPMLAccountID {
accountPopUpButton.select(menuItem) accountPopUpButton.select(menuItem)
} }
} }

View File

@ -31,7 +31,7 @@ class ExportOPMLWindowController: NSWindowController {
oneMenuItem.representedObject = oneAccount oneMenuItem.representedObject = oneAccount
menu.addItem(oneMenuItem) menu.addItem(oneMenuItem)
if oneAccount.accountID == AppDefaults.exportOPMLAccountID { if oneAccount.accountID == AppDefaults.shared.exportOPMLAccountID {
accountPopUpButton.select(oneMenuItem) accountPopUpButton.select(oneMenuItem)
} }
@ -66,7 +66,7 @@ class ExportOPMLWindowController: NSWindowController {
} }
let account = menuItem.representedObject as! Account let account = menuItem.representedObject as! Account
AppDefaults.exportOPMLAccountID = account.accountID AppDefaults.shared.exportOPMLAccountID = account.accountID
hostWindow!.endSheet(window!, returnCode: NSApplication.ModalResponse.OK) hostWindow!.endSheet(window!, returnCode: NSApplication.ModalResponse.OK)
exportOPML(account: account) exportOPML(account: account)

View File

@ -35,7 +35,7 @@ class ImportOPMLWindowController: NSWindowController {
oneMenuItem.representedObject = oneAccount oneMenuItem.representedObject = oneAccount
menu.addItem(oneMenuItem) menu.addItem(oneMenuItem)
if oneAccount.accountID == AppDefaults.importOPMLAccountID { if oneAccount.accountID == AppDefaults.shared.importOPMLAccountID {
accountPopUpButton.select(oneMenuItem) accountPopUpButton.select(oneMenuItem)
} }
@ -70,7 +70,7 @@ class ImportOPMLWindowController: NSWindowController {
} }
let account = menuItem.representedObject as! Account let account = menuItem.representedObject as! Account
AppDefaults.importOPMLAccountID = account.accountID AppDefaults.shared.importOPMLAccountID = account.accountID
hostWindow!.endSheet(window!, returnCode: NSApplication.ModalResponse.OK) hostWindow!.endSheet(window!, returnCode: NSApplication.ModalResponse.OK)
importOPML(account: account) importOPML(account: account)

View File

@ -17,7 +17,7 @@ struct SidebarCellAppearance: Equatable {
let textFieldFont: NSFont let textFieldFont: NSFont
init(fontSize: FontSize) { init(fontSize: FontSize) {
self.textFieldFontSize = AppDefaults.actualFontSize(for: fontSize) self.textFieldFontSize = AppDefaults.shared.actualFontSize(for: fontSize)
self.textFieldFont = NSFont.systemFont(ofSize: textFieldFontSize) self.textFieldFont = NSFont.systemFont(ofSize: textFieldFontSize)
} }
} }

View File

@ -57,7 +57,7 @@ protocol SidebarDelegate: class {
// MARK: - NSViewController // MARK: - NSViewController
override func viewDidLoad() { override func viewDidLoad() {
sidebarCellAppearance = SidebarCellAppearance(fontSize: AppDefaults.sidebarFontSize) sidebarCellAppearance = SidebarCellAppearance(fontSize: AppDefaults.shared.sidebarFontSize)
outlineView.dataSource = dataSource outlineView.dataSource = dataSource
outlineView.doubleAction = #selector(doubleClickedSidebar(_:)) outlineView.doubleAction = #selector(doubleClickedSidebar(_:))

View File

@ -44,7 +44,7 @@ struct TimelineCellAppearance: Equatable {
init(showIcon: Bool, fontSize: FontSize) { init(showIcon: Bool, fontSize: FontSize) {
let actualFontSize = AppDefaults.actualFontSize(for: fontSize) let actualFontSize = AppDefaults.shared.actualFontSize(for: fontSize)
let smallItemFontSize = floor(actualFontSize * 0.90) let smallItemFontSize = floor(actualFontSize * 0.90)
let largeItemFontSize = actualFontSize let largeItemFontSize = actualFontSize

View File

@ -27,7 +27,7 @@ class TimelineTableCellView: NSTableCellView {
return [self.dateView, self.feedNameView, self.titleView, self.summaryView, self.textView] return [self.dateView, self.feedNameView, self.titleView, self.summaryView, self.textView]
}() }()
private var showsSeparator: Bool = AppDefaults.timelineShowsSeparators { private var showsSeparator: Bool = AppDefaults.shared.timelineShowsSeparators {
didSet { didSet {
separatorView.isHidden = !showsSeparator separatorView.isHidden = !showsSeparator
} }
@ -85,7 +85,7 @@ class TimelineTableCellView: NSTableCellView {
} }
func timelineShowsSeparatorsDefaultDidChange() { func timelineShowsSeparatorsDefaultDidChange() {
showsSeparator = AppDefaults.timelineShowsSeparators showsSeparator = AppDefaults.shared.timelineShowsSeparators
} }
override func setFrameSize(_ newSize: NSSize) { override func setFrameSize(_ newSize: NSSize) {
@ -209,7 +209,7 @@ private extension TimelineTableCellView {
addSubviewAtInit(feedNameView, hidden: true) addSubviewAtInit(feedNameView, hidden: true)
addSubviewAtInit(iconView, hidden: true) addSubviewAtInit(iconView, hidden: true)
addSubviewAtInit(starView, hidden: true) addSubviewAtInit(starView, hidden: true)
addSubviewAtInit(separatorView, hidden: !AppDefaults.timelineShowsSeparators) addSubviewAtInit(separatorView, hidden: !AppDefaults.shared.timelineShowsSeparators)
makeTextFieldColorsNormal() makeTextFieldColorsNormal()
} }

View File

@ -167,7 +167,7 @@ private extension TimelineContainerViewController {
func updateViewOptionsPopUpButton() { func updateViewOptionsPopUpButton() {
let localizedTitle = NSLocalizedString("Sort %@", comment: "Sort") let localizedTitle = NSLocalizedString("Sort %@", comment: "Sort")
if AppDefaults.timelineSortDirection == .orderedAscending { if AppDefaults.shared.timelineSortDirection == .orderedAscending {
newestToOldestMenuItem.state = .off newestToOldestMenuItem.state = .off
oldestToNewestMenuItem.state = .on oldestToNewestMenuItem.state = .on
let title = NSString.localizedStringWithFormat(localizedTitle as NSString, oldestToNewestMenuItem.title) as String let title = NSString.localizedStringWithFormat(localizedTitle as NSString, oldestToNewestMenuItem.title) as String
@ -179,7 +179,7 @@ private extension TimelineContainerViewController {
viewOptionsPopUpButton.setTitle(title) viewOptionsPopUpButton.setTitle(title)
} }
if AppDefaults.timelineGroupByFeed == true { if AppDefaults.shared.timelineGroupByFeed == true {
groupByFeedMenuItem.state = .on groupByFeedMenuItem.state = .on
} else { } else {
groupByFeedMenuItem.state = .off groupByFeedMenuItem.state = .off

View File

@ -142,21 +142,21 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr
private var didRegisterForNotifications = false private var didRegisterForNotifications = false
static let fetchAndMergeArticlesQueue = CoalescingQueue(name: "Fetch and Merge Articles", interval: 0.5, maxInterval: 2.0) static let fetchAndMergeArticlesQueue = CoalescingQueue(name: "Fetch and Merge Articles", interval: 0.5, maxInterval: 2.0)
private var sortDirection = AppDefaults.timelineSortDirection { private var sortDirection = AppDefaults.shared.timelineSortDirection {
didSet { didSet {
if sortDirection != oldValue { if sortDirection != oldValue {
sortParametersDidChange() sortParametersDidChange()
} }
} }
} }
private var groupByFeed = AppDefaults.timelineGroupByFeed { private var groupByFeed = AppDefaults.shared.timelineGroupByFeed {
didSet { didSet {
if groupByFeed != oldValue { if groupByFeed != oldValue {
sortParametersDidChange() sortParametersDidChange()
} }
} }
} }
private var fontSize: FontSize = AppDefaults.timelineFontSize { private var fontSize: FontSize = AppDefaults.shared.timelineFontSize {
didSet { didSet {
if fontSize != oldValue { if fontSize != oldValue {
fontSizeDidChange() fontSizeDidChange()
@ -611,9 +611,9 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr
} }
@objc func userDefaultsDidChange(_ note: Notification) { @objc func userDefaultsDidChange(_ note: Notification) {
self.fontSize = AppDefaults.timelineFontSize self.fontSize = AppDefaults.shared.timelineFontSize
self.sortDirection = AppDefaults.timelineSortDirection self.sortDirection = AppDefaults.shared.timelineSortDirection
self.groupByFeed = AppDefaults.timelineGroupByFeed self.groupByFeed = AppDefaults.shared.timelineGroupByFeed
} }
// MARK: - Reloading Data // MARK: - Reloading Data

View File

@ -171,7 +171,7 @@ private extension AccountsAddViewController {
} }
} }
if AppDefaults.isDeveloperBuild { if AppDefaults.shared.isDeveloperBuild {
removeAccountType(.cloudKit) removeAccountType(.cloudKit)
removeAccountType(.feedly) removeAccountType(.feedly)
removeAccountType(.feedWrangler) removeAccountType(.feedWrangler)

View File

@ -55,7 +55,7 @@ final class GeneralPreferencesViewController: NSViewController {
return return
} }
let bundleID = menuItem.representedObject as? String let bundleID = menuItem.representedObject as? String
AppDefaults.defaultBrowserID = bundleID AppDefaults.shared.defaultBrowserID = bundleID
updateUI() updateUI()
} }
} }
@ -164,7 +164,7 @@ private extension GeneralPreferencesViewController {
menu.addItem(item) menu.addItem(item)
} }
defaultBrowserPopup.selectItem(at: defaultBrowserPopup.indexOfItem(withRepresentedObject: AppDefaults.defaultBrowserID)) defaultBrowserPopup.selectItem(at: defaultBrowserPopup.indexOfItem(withRepresentedObject: AppDefaults.shared.defaultBrowserID))
} }
} }