Start work on AppDefaults.swift.
This commit is contained in:
parent
0843c10bc5
commit
6c7c8c7110
|
@ -79,6 +79,7 @@
|
|||
84B0700B1ED3822600F0B54B /* RSTextDrawing.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 84B070071ED3821900F0B54B /* RSTextDrawing.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
|
||||
84BB4B771F11753300858766 /* Data.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 84BB4B681F1174D400858766 /* Data.framework */; };
|
||||
84BB4B781F11753300858766 /* Data.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 84BB4B681F1174D400858766 /* Data.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
|
||||
84E46C7D1F75EF7B005ECFB3 /* AppDefaults.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84E46C7C1F75EF7B005ECFB3 /* AppDefaults.swift */; };
|
||||
84FB9A2F1EDCD6C4003D53B9 /* Sparkle.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 84FB9A2D1EDCD6B8003D53B9 /* Sparkle.framework */; };
|
||||
84FB9A301EDCD6C4003D53B9 /* Sparkle.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 84FB9A2D1EDCD6B8003D53B9 /* Sparkle.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
|
||||
/* End PBXBuildFile section */
|
||||
|
@ -436,6 +437,7 @@
|
|||
84B06FF41ED3818000F0B54B /* RSTree.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RSTree.xcodeproj; path = Frameworks/RSTree/RSTree.xcodeproj; sourceTree = "<group>"; };
|
||||
84B070011ED3821800F0B54B /* RSTextDrawing.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RSTextDrawing.xcodeproj; path = Frameworks/RSTextDrawing/RSTextDrawing.xcodeproj; sourceTree = "<group>"; };
|
||||
84BB4B611F1174D400858766 /* Data.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = Data.xcodeproj; path = Frameworks/Data/Data.xcodeproj; sourceTree = "<group>"; };
|
||||
84E46C7C1F75EF7B005ECFB3 /* AppDefaults.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = AppDefaults.swift; path = Evergreen/AppDefaults.swift; sourceTree = "<group>"; };
|
||||
84FB9A2D1EDCD6B8003D53B9 /* Sparkle.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Sparkle.framework; path = Frameworks/Vendor/Sparkle.framework; sourceTree = SOURCE_ROOT; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
|
@ -668,6 +670,7 @@
|
|||
849C64671ED37A5D003D8FC0 /* Assets.xcassets */,
|
||||
849C64691ED37A5D003D8FC0 /* Main.storyboard */,
|
||||
842E45CD1ED8C308000A8B52 /* AppConstants.swift */,
|
||||
84E46C7C1F75EF7B005ECFB3 /* AppDefaults.swift */,
|
||||
849C64631ED37A5D003D8FC0 /* AppDelegate.swift */,
|
||||
842E45DC1ED8C54B000A8B52 /* Browser.swift */,
|
||||
842E45E11ED8C681000A8B52 /* MainWindow */,
|
||||
|
@ -1166,6 +1169,7 @@
|
|||
849A97661ED9EB96007D329B /* SidebarViewController.swift in Sources */,
|
||||
842E45E31ED8C681000A8B52 /* KeyboardDelegateProtocol.swift in Sources */,
|
||||
849A976E1ED9EBC8007D329B /* TimelineViewController.swift in Sources */,
|
||||
84E46C7D1F75EF7B005ECFB3 /* AppDefaults.swift in Sources */,
|
||||
849A978D1ED9EE4D007D329B /* FeedListWindowController.swift in Sources */,
|
||||
849A97771ED9EC04007D329B /* TimelineCellData.swift in Sources */,
|
||||
849A975C1ED9EB0D007D329B /* DefaultFeedsImporter.swift in Sources */,
|
||||
|
|
|
@ -29,15 +29,5 @@ struct AppUserInfoKey {
|
|||
static let appNavigation = "key"
|
||||
}
|
||||
|
||||
struct AppDefaultsKey {
|
||||
|
||||
static let firstRunDate = "firstRunDate"
|
||||
|
||||
static let sidebarFontSize = "sidebarFontSize"
|
||||
static let timelineFontSize = "timelineFontSize"
|
||||
static let detailFontSize = "detailFontSize"
|
||||
|
||||
static let openInBrowserInBackground = "openInBrowserInBackground"
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,74 @@
|
|||
//
|
||||
// AppDefaults.swift
|
||||
// Evergreen
|
||||
//
|
||||
// Created by Brent Simmons on 9/22/17.
|
||||
// Copyright © 2017 Ranchero Software. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
final class AppDefaults {
|
||||
|
||||
static let shared = AppDefaults()
|
||||
|
||||
private struct Key {
|
||||
|
||||
static let firstRunDate = "firstRunDate"
|
||||
|
||||
static let sidebarFontSize = "sidebarFontSize"
|
||||
static let timelineFontSize = "timelineFontSize"
|
||||
static let detailFontSize = "detailFontSize"
|
||||
|
||||
static let openInBrowserInBackground = "openInBrowserInBackground"
|
||||
}
|
||||
|
||||
var firstRunDate: Date? {
|
||||
get {
|
||||
return date(for: Key.firstRunDate)
|
||||
}
|
||||
set {
|
||||
setDate(for: key.firstRunDate, date)
|
||||
}
|
||||
}
|
||||
var openInBrowserInBackground: Bool {
|
||||
get {
|
||||
return bool(for: Key.openInBrowserInBackground)
|
||||
}
|
||||
set {
|
||||
setBool(for: Key.openInBrowserInBackground, newValue)
|
||||
}
|
||||
}
|
||||
|
||||
init() {
|
||||
|
||||
registerDefaults()
|
||||
}
|
||||
|
||||
func registerDefaults() {
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private extension AppDefaults {
|
||||
|
||||
func bool(for key: String) -> Bool {
|
||||
return UserDefaults.standard.bool(forKey: key)
|
||||
}
|
||||
|
||||
func setBool(for key: String, _ flag: Bool) {
|
||||
UserDefaults.standard.set(flag, forKey: key)
|
||||
}
|
||||
|
||||
func date(for key: String) -> Date? {
|
||||
return UserDefaults.standard.object(forKey: key) as? Date
|
||||
}
|
||||
|
||||
func setDate(for key: String, _ date: Date) {
|
||||
UserDefaults.standard.set(date, forKey: key)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -49,16 +49,6 @@ extension Article {
|
|||
}
|
||||
}
|
||||
|
||||
var status: ArticleStatus? {
|
||||
get {
|
||||
guard let status = account?.articleStatus(for: self) else {
|
||||
assertionFailure("Expected ArticleStatus for article.status.")
|
||||
return nil
|
||||
}
|
||||
return status
|
||||
}
|
||||
}
|
||||
|
||||
var preferredLink: String? {
|
||||
get {
|
||||
return url ?? externalURL
|
||||
|
@ -73,16 +63,7 @@ extension Article {
|
|||
|
||||
var logicalDatePublished: Date {
|
||||
get {
|
||||
return datePublished ?? dateModified ?? status?.dateArrived ?? Date.distantPast
|
||||
}
|
||||
}
|
||||
|
||||
var read: Bool {
|
||||
get {
|
||||
if let status = status {
|
||||
return status.read
|
||||
}
|
||||
return false
|
||||
return datePublished ?? dateModified ?? status.dateArrived
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ private let largestFontSizeRawValue = FontSize.veryLarge.rawValue
|
|||
|
||||
func registerDefaults() {
|
||||
|
||||
let defaults = [AppDefaultsKey.sidebarFontSize: FontSize.medium.rawValue, AppDefaultsKey.timelineFontSize: FontSize.medium.rawValue, AppDefaultsKey.detailFontSize, FontSize.medium.rawValue]
|
||||
let defaults = [AppDefaultsKey.sidebarFontSize: FontSize.medium.rawValue, AppDefaultsKey.timelineFontSize: FontSize.medium.rawValue, AppDefaultsKey.detailFontSize: FontSize.medium.rawValue]
|
||||
|
||||
UserDefaults.standard.register(defaults: defaults)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue