mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2025-08-12 06:26:36 +00:00
NetNewsWire-Mac AppDefaults is now a singleton
This commit is contained in:
@@ -36,7 +36,7 @@ class AddFolderWindowController : NSWindowController {
|
||||
// MARK: - NSViewController
|
||||
|
||||
override func windowDidLoad() {
|
||||
let preferredAccountID = AppDefaults.addFolderAccountID
|
||||
let preferredAccountID = AppDefaults.shared.addFolderAccountID
|
||||
accountPopupButton.removeAllItems()
|
||||
|
||||
let menu = NSMenu()
|
||||
@@ -93,7 +93,7 @@ private extension AddFolderWindowController {
|
||||
}
|
||||
|
||||
let account = menuItem.representedObject as! Account
|
||||
AppDefaults.addFolderAccountID = account.accountID
|
||||
AppDefaults.shared.addFolderAccountID = account.accountID
|
||||
|
||||
let folderName = self.folderNameTextField.stringValue
|
||||
if folderName.isEmpty {
|
||||
|
||||
@@ -116,7 +116,7 @@ final class DetailWebViewController: NSViewController, WKUIDelegate {
|
||||
waitingForFirstReload = true
|
||||
|
||||
#if !MAC_APP_STORE
|
||||
webInspectorEnabled = AppDefaults.webInspectorEnabled
|
||||
webInspectorEnabled = AppDefaults.shared.webInspectorEnabled
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(webInspectorEnabledDidChange(_:)), name: .WebInspectorEnabledDidChange, object: nil)
|
||||
#endif
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ class MainWindowController : NSWindowController, NSUserInterfaceValidations {
|
||||
|
||||
sharingServicePickerDelegate = SharingServicePickerDelegate(self.window)
|
||||
|
||||
if !AppDefaults.showTitleOnMainWindow {
|
||||
if !AppDefaults.shared.showTitleOnMainWindow {
|
||||
window?.titleVisibility = .hidden
|
||||
}
|
||||
|
||||
@@ -116,12 +116,12 @@ class MainWindowController : NSWindowController, NSUserInterfaceValidations {
|
||||
}
|
||||
|
||||
func saveStateToUserDefaults() {
|
||||
AppDefaults.windowState = savableState()
|
||||
AppDefaults.shared.windowState = savableState()
|
||||
window?.saveFrame(usingName: windowAutosaveName)
|
||||
}
|
||||
|
||||
func restoreStateFromUserDefaults() {
|
||||
if let state = AppDefaults.windowState {
|
||||
if let state = AppDefaults.shared.windowState {
|
||||
restoreState(from: state)
|
||||
window?.setFrameUsingName(windowAutosaveName, force: true)
|
||||
}
|
||||
@@ -281,7 +281,7 @@ class MainWindowController : NSWindowController, NSUserInterfaceValidations {
|
||||
|
||||
@IBAction func openInBrowserUsingOppositeOfSettings(_ sender: Any?) {
|
||||
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 {
|
||||
guard !AppDefaults.isDeveloperBuild else {
|
||||
guard !AppDefaults.shared.isDeveloperBuild else {
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
@@ -82,7 +82,7 @@ private extension NNW3ImportController {
|
||||
guard let account = accessoryViewController.selectedAccount else {
|
||||
return
|
||||
}
|
||||
AppDefaults.importOPMLAccountID = account.accountID
|
||||
AppDefaults.shared.importOPMLAccountID = account.accountID
|
||||
|
||||
NNW3ImportController.importSubscriptionsPlist(subscriptionsPlistURL, into: account)
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ final class NNW3OpenPanelAccessoryViewController: NSViewController {
|
||||
menuItem.representedObject = account
|
||||
menu.addItem(menuItem)
|
||||
|
||||
if account.accountID == AppDefaults.importOPMLAccountID {
|
||||
if account.accountID == AppDefaults.shared.importOPMLAccountID {
|
||||
accountPopUpButton.select(menuItem)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ class ExportOPMLWindowController: NSWindowController {
|
||||
oneMenuItem.representedObject = oneAccount
|
||||
menu.addItem(oneMenuItem)
|
||||
|
||||
if oneAccount.accountID == AppDefaults.exportOPMLAccountID {
|
||||
if oneAccount.accountID == AppDefaults.shared.exportOPMLAccountID {
|
||||
accountPopUpButton.select(oneMenuItem)
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ class ExportOPMLWindowController: NSWindowController {
|
||||
}
|
||||
|
||||
let account = menuItem.representedObject as! Account
|
||||
AppDefaults.exportOPMLAccountID = account.accountID
|
||||
AppDefaults.shared.exportOPMLAccountID = account.accountID
|
||||
hostWindow!.endSheet(window!, returnCode: NSApplication.ModalResponse.OK)
|
||||
exportOPML(account: account)
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ class ImportOPMLWindowController: NSWindowController {
|
||||
oneMenuItem.representedObject = oneAccount
|
||||
menu.addItem(oneMenuItem)
|
||||
|
||||
if oneAccount.accountID == AppDefaults.importOPMLAccountID {
|
||||
if oneAccount.accountID == AppDefaults.shared.importOPMLAccountID {
|
||||
accountPopUpButton.select(oneMenuItem)
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ class ImportOPMLWindowController: NSWindowController {
|
||||
}
|
||||
|
||||
let account = menuItem.representedObject as! Account
|
||||
AppDefaults.importOPMLAccountID = account.accountID
|
||||
AppDefaults.shared.importOPMLAccountID = account.accountID
|
||||
hostWindow!.endSheet(window!, returnCode: NSApplication.ModalResponse.OK)
|
||||
importOPML(account: account)
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ struct SidebarCellAppearance: Equatable {
|
||||
let textFieldFont: NSFont
|
||||
|
||||
init(fontSize: FontSize) {
|
||||
self.textFieldFontSize = AppDefaults.actualFontSize(for: fontSize)
|
||||
self.textFieldFontSize = AppDefaults.shared.actualFontSize(for: fontSize)
|
||||
self.textFieldFont = NSFont.systemFont(ofSize: textFieldFontSize)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ protocol SidebarDelegate: class {
|
||||
// MARK: - NSViewController
|
||||
|
||||
override func viewDidLoad() {
|
||||
sidebarCellAppearance = SidebarCellAppearance(fontSize: AppDefaults.sidebarFontSize)
|
||||
sidebarCellAppearance = SidebarCellAppearance(fontSize: AppDefaults.shared.sidebarFontSize)
|
||||
|
||||
outlineView.dataSource = dataSource
|
||||
outlineView.doubleAction = #selector(doubleClickedSidebar(_:))
|
||||
|
||||
@@ -44,7 +44,7 @@ struct TimelineCellAppearance: Equatable {
|
||||
|
||||
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 largeItemFontSize = actualFontSize
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ class TimelineTableCellView: NSTableCellView {
|
||||
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 {
|
||||
separatorView.isHidden = !showsSeparator
|
||||
}
|
||||
@@ -85,7 +85,7 @@ class TimelineTableCellView: NSTableCellView {
|
||||
}
|
||||
|
||||
func timelineShowsSeparatorsDefaultDidChange() {
|
||||
showsSeparator = AppDefaults.timelineShowsSeparators
|
||||
showsSeparator = AppDefaults.shared.timelineShowsSeparators
|
||||
}
|
||||
|
||||
override func setFrameSize(_ newSize: NSSize) {
|
||||
@@ -209,7 +209,7 @@ private extension TimelineTableCellView {
|
||||
addSubviewAtInit(feedNameView, hidden: true)
|
||||
addSubviewAtInit(iconView, hidden: true)
|
||||
addSubviewAtInit(starView, hidden: true)
|
||||
addSubviewAtInit(separatorView, hidden: !AppDefaults.timelineShowsSeparators)
|
||||
addSubviewAtInit(separatorView, hidden: !AppDefaults.shared.timelineShowsSeparators)
|
||||
|
||||
makeTextFieldColorsNormal()
|
||||
}
|
||||
|
||||
@@ -167,7 +167,7 @@ private extension TimelineContainerViewController {
|
||||
func updateViewOptionsPopUpButton() {
|
||||
let localizedTitle = NSLocalizedString("Sort %@", comment: "Sort")
|
||||
|
||||
if AppDefaults.timelineSortDirection == .orderedAscending {
|
||||
if AppDefaults.shared.timelineSortDirection == .orderedAscending {
|
||||
newestToOldestMenuItem.state = .off
|
||||
oldestToNewestMenuItem.state = .on
|
||||
let title = NSString.localizedStringWithFormat(localizedTitle as NSString, oldestToNewestMenuItem.title) as String
|
||||
@@ -179,7 +179,7 @@ private extension TimelineContainerViewController {
|
||||
viewOptionsPopUpButton.setTitle(title)
|
||||
}
|
||||
|
||||
if AppDefaults.timelineGroupByFeed == true {
|
||||
if AppDefaults.shared.timelineGroupByFeed == true {
|
||||
groupByFeedMenuItem.state = .on
|
||||
} else {
|
||||
groupByFeedMenuItem.state = .off
|
||||
|
||||
@@ -142,21 +142,21 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr
|
||||
private var didRegisterForNotifications = false
|
||||
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 {
|
||||
if sortDirection != oldValue {
|
||||
sortParametersDidChange()
|
||||
}
|
||||
}
|
||||
}
|
||||
private var groupByFeed = AppDefaults.timelineGroupByFeed {
|
||||
private var groupByFeed = AppDefaults.shared.timelineGroupByFeed {
|
||||
didSet {
|
||||
if groupByFeed != oldValue {
|
||||
sortParametersDidChange()
|
||||
}
|
||||
}
|
||||
}
|
||||
private var fontSize: FontSize = AppDefaults.timelineFontSize {
|
||||
private var fontSize: FontSize = AppDefaults.shared.timelineFontSize {
|
||||
didSet {
|
||||
if fontSize != oldValue {
|
||||
fontSizeDidChange()
|
||||
@@ -611,9 +611,9 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr
|
||||
}
|
||||
|
||||
@objc func userDefaultsDidChange(_ note: Notification) {
|
||||
self.fontSize = AppDefaults.timelineFontSize
|
||||
self.sortDirection = AppDefaults.timelineSortDirection
|
||||
self.groupByFeed = AppDefaults.timelineGroupByFeed
|
||||
self.fontSize = AppDefaults.shared.timelineFontSize
|
||||
self.sortDirection = AppDefaults.shared.timelineSortDirection
|
||||
self.groupByFeed = AppDefaults.shared.timelineGroupByFeed
|
||||
}
|
||||
|
||||
// MARK: - Reloading Data
|
||||
|
||||
Reference in New Issue
Block a user