Add shared AppDefaultsKey.
This commit is contained in:
parent
5651764907
commit
d9d47749ef
Mac
NetNewsWire.xcodeproj
Shared
iOS
@ -21,39 +21,6 @@ final class AppDefaults {
|
||||
|
||||
static let shared = AppDefaults()
|
||||
|
||||
struct Key {
|
||||
static let firstRunDate = "firstRunDate"
|
||||
static let windowState = "windowState"
|
||||
static let lastImageCacheFlushDate = "lastImageCacheFlushDate"
|
||||
static let sidebarFontSize = "sidebarFontSize"
|
||||
static let timelineFontSize = "timelineFontSize"
|
||||
static let timelineSortDirection = "timelineSortDirection"
|
||||
static let timelineGroupByFeed = "timelineGroupByFeed"
|
||||
static let detailFontSize = "detailFontSize"
|
||||
static let openInBrowserInBackground = "openInBrowserInBackground"
|
||||
static let subscribeToFeedsInDefaultBrowser = "subscribeToFeedsInDefaultBrowser"
|
||||
static let articleTextSize = "articleTextSize"
|
||||
static let refreshInterval = "refreshInterval"
|
||||
static let addFeedAccountID = "addFeedAccountID"
|
||||
static let addFeedFolderName = "addFeedFolderName"
|
||||
static let addFolderAccountID = "addFolderAccountID"
|
||||
static let importOPMLAccountID = "importOPMLAccountID"
|
||||
static let exportOPMLAccountID = "exportOPMLAccountID"
|
||||
static let defaultBrowserID = "defaultBrowserID"
|
||||
static let currentThemeName = "currentThemeName"
|
||||
static let articleContentJavascriptEnabled = "articleContentJavascriptEnabled"
|
||||
|
||||
// Hidden prefs
|
||||
static let showDebugMenu = "ShowDebugMenu"
|
||||
static let timelineShowsSeparators = "CorreiaSeparators"
|
||||
static let showTitleOnMainWindow = "KafasisTitleMode"
|
||||
static let feedDoubleClickMarkAsRead = "GruberFeedDoubleClickMarkAsRead"
|
||||
static let suppressSyncOnLaunch = "DevroeSuppressSyncOnLaunch"
|
||||
|
||||
static let webInspectorEnabled = "WebInspectorEnabled"
|
||||
static let webInspectorStartsAttached = "__WebInspectorPageGroupLevel1__.WebKit2InspectorStartsAttached"
|
||||
}
|
||||
|
||||
private static let smallestFontSizeRawValue = FontSize.small.rawValue
|
||||
private static let largestFontSizeRawValue = FontSize.veryLarge.rawValue
|
||||
|
||||
@ -65,7 +32,7 @@ final class AppDefaults {
|
||||
}()
|
||||
|
||||
var isFirstRun: Bool = {
|
||||
if UserDefaults.standard.object(forKey: Key.firstRunDate) as? Date == nil {
|
||||
if UserDefaults.standard.object(forKey: AppDefaultsKey.firstRunDate) as? Date == nil {
|
||||
firstRunDate = Date()
|
||||
return true
|
||||
}
|
||||
@ -74,28 +41,28 @@ final class AppDefaults {
|
||||
|
||||
var windowState: [AnyHashable: Any]? {
|
||||
get {
|
||||
return UserDefaults.standard.object(forKey: Key.windowState) as? [AnyHashable: Any]
|
||||
return UserDefaults.standard.object(forKey: AppDefaultsKey.windowState) as? [AnyHashable: Any]
|
||||
}
|
||||
set {
|
||||
UserDefaults.standard.set(newValue, forKey: Key.windowState)
|
||||
UserDefaults.standard.set(newValue, forKey: AppDefaultsKey.windowState)
|
||||
}
|
||||
}
|
||||
|
||||
var lastImageCacheFlushDate: Date? {
|
||||
get {
|
||||
return AppDefaults.date(for: Key.lastImageCacheFlushDate)
|
||||
return AppDefaults.date(for: AppDefaultsKey.lastImageCacheFlushDate)
|
||||
}
|
||||
set {
|
||||
AppDefaults.setDate(for: Key.lastImageCacheFlushDate, newValue)
|
||||
AppDefaults.setDate(for: AppDefaultsKey.lastImageCacheFlushDate, newValue)
|
||||
}
|
||||
}
|
||||
|
||||
var openInBrowserInBackground: Bool {
|
||||
get {
|
||||
return AppDefaults.bool(for: Key.openInBrowserInBackground)
|
||||
return AppDefaults.bool(for: AppDefaultsKey.openInBrowserInBackground)
|
||||
}
|
||||
set {
|
||||
AppDefaults.setBool(for: Key.openInBrowserInBackground, newValue)
|
||||
AppDefaults.setBool(for: AppDefaultsKey.openInBrowserInBackground, newValue)
|
||||
}
|
||||
}
|
||||
|
||||
@ -112,195 +79,195 @@ final class AppDefaults {
|
||||
|
||||
var subscribeToFeedsInDefaultBrowser: Bool {
|
||||
get {
|
||||
return subscribeToFeedDefaults.bool(forKey: Key.subscribeToFeedsInDefaultBrowser)
|
||||
return subscribeToFeedDefaults.bool(forKey: AppDefaultsKey.subscribeToFeedsInDefaultBrowser)
|
||||
}
|
||||
set {
|
||||
subscribeToFeedDefaults.set(newValue, forKey: Key.subscribeToFeedsInDefaultBrowser)
|
||||
subscribeToFeedDefaults.set(newValue, forKey: AppDefaultsKey.subscribeToFeedsInDefaultBrowser)
|
||||
}
|
||||
}
|
||||
|
||||
var sidebarFontSize: FontSize {
|
||||
get {
|
||||
return fontSize(for: Key.sidebarFontSize)
|
||||
return fontSize(for: AppDefaultsKey.sidebarFontSize)
|
||||
}
|
||||
set {
|
||||
AppDefaults.setFontSize(for: Key.sidebarFontSize, newValue)
|
||||
AppDefaults.setFontSize(for: AppDefaultsKey.sidebarFontSize, newValue)
|
||||
}
|
||||
}
|
||||
|
||||
var timelineFontSize: FontSize {
|
||||
get {
|
||||
return fontSize(for: Key.timelineFontSize)
|
||||
return fontSize(for: AppDefaultsKey.timelineFontSize)
|
||||
}
|
||||
set {
|
||||
AppDefaults.setFontSize(for: Key.timelineFontSize, newValue)
|
||||
AppDefaults.setFontSize(for: AppDefaultsKey.timelineFontSize, newValue)
|
||||
}
|
||||
}
|
||||
|
||||
var detailFontSize: FontSize {
|
||||
get {
|
||||
return fontSize(for: Key.detailFontSize)
|
||||
return fontSize(for: AppDefaultsKey.detailFontSize)
|
||||
}
|
||||
set {
|
||||
AppDefaults.setFontSize(for: Key.detailFontSize, newValue)
|
||||
AppDefaults.setFontSize(for: AppDefaultsKey.detailFontSize, newValue)
|
||||
}
|
||||
}
|
||||
|
||||
var addFeedAccountID: String? {
|
||||
get {
|
||||
return AppDefaults.string(for: Key.addFeedAccountID)
|
||||
return AppDefaults.string(for: AppDefaultsKey.addFeedAccountID)
|
||||
}
|
||||
set {
|
||||
AppDefaults.setString(for: Key.addFeedAccountID, newValue)
|
||||
AppDefaults.setString(for: AppDefaultsKey.addFeedAccountID, newValue)
|
||||
}
|
||||
}
|
||||
|
||||
var addFeedFolderName: String? {
|
||||
get {
|
||||
return AppDefaults.string(for: Key.addFeedFolderName)
|
||||
return AppDefaults.string(for: AppDefaultsKey.addFeedFolderName)
|
||||
}
|
||||
set {
|
||||
AppDefaults.setString(for: Key.addFeedFolderName, newValue)
|
||||
AppDefaults.setString(for: AppDefaultsKey.addFeedFolderName, newValue)
|
||||
}
|
||||
}
|
||||
|
||||
var addFolderAccountID: String? {
|
||||
get {
|
||||
return AppDefaults.string(for: Key.addFolderAccountID)
|
||||
return AppDefaults.string(for: AppDefaultsKey.addFolderAccountID)
|
||||
}
|
||||
set {
|
||||
AppDefaults.setString(for: Key.addFolderAccountID, newValue)
|
||||
AppDefaults.setString(for: AppDefaultsKey.addFolderAccountID, newValue)
|
||||
}
|
||||
}
|
||||
|
||||
var importOPMLAccountID: String? {
|
||||
get {
|
||||
return AppDefaults.string(for: Key.importOPMLAccountID)
|
||||
return AppDefaults.string(for: AppDefaultsKey.importOPMLAccountID)
|
||||
}
|
||||
set {
|
||||
AppDefaults.setString(for: Key.importOPMLAccountID, newValue)
|
||||
AppDefaults.setString(for: AppDefaultsKey.importOPMLAccountID, newValue)
|
||||
}
|
||||
}
|
||||
|
||||
var exportOPMLAccountID: String? {
|
||||
get {
|
||||
return AppDefaults.string(for: Key.exportOPMLAccountID)
|
||||
return AppDefaults.string(for: AppDefaultsKey.exportOPMLAccountID)
|
||||
}
|
||||
set {
|
||||
AppDefaults.setString(for: Key.exportOPMLAccountID, newValue)
|
||||
AppDefaults.setString(for: AppDefaultsKey.exportOPMLAccountID, newValue)
|
||||
}
|
||||
}
|
||||
|
||||
var defaultBrowserID: String? {
|
||||
get {
|
||||
return AppDefaults.string(for: Key.defaultBrowserID)
|
||||
return AppDefaults.string(for: AppDefaultsKey.defaultBrowserID)
|
||||
}
|
||||
set {
|
||||
AppDefaults.setString(for: Key.defaultBrowserID, newValue)
|
||||
AppDefaults.setString(for: AppDefaultsKey.defaultBrowserID, newValue)
|
||||
}
|
||||
}
|
||||
|
||||
var currentThemeName: String? {
|
||||
get {
|
||||
return AppDefaults.string(for: Key.currentThemeName)
|
||||
return AppDefaults.string(for: AppDefaultsKey.currentThemeName)
|
||||
}
|
||||
set {
|
||||
AppDefaults.setString(for: Key.currentThemeName, newValue)
|
||||
AppDefaults.setString(for: AppDefaultsKey.currentThemeName, newValue)
|
||||
}
|
||||
}
|
||||
|
||||
var showTitleOnMainWindow: Bool {
|
||||
return AppDefaults.bool(for: Key.showTitleOnMainWindow)
|
||||
return AppDefaults.bool(for: AppDefaultsKey.showTitleOnMainWindow)
|
||||
}
|
||||
|
||||
var showDebugMenu: Bool {
|
||||
return AppDefaults.bool(for: Key.showDebugMenu)
|
||||
return AppDefaults.bool(for: AppDefaultsKey.showDebugMenu)
|
||||
}
|
||||
|
||||
var feedDoubleClickMarkAsRead: Bool {
|
||||
get {
|
||||
return AppDefaults.bool(for: Key.feedDoubleClickMarkAsRead)
|
||||
return AppDefaults.bool(for: AppDefaultsKey.feedDoubleClickMarkAsRead)
|
||||
}
|
||||
set {
|
||||
AppDefaults.setBool(for: Key.feedDoubleClickMarkAsRead, newValue)
|
||||
AppDefaults.setBool(for: AppDefaultsKey.feedDoubleClickMarkAsRead, newValue)
|
||||
}
|
||||
}
|
||||
|
||||
var suppressSyncOnLaunch: Bool {
|
||||
get {
|
||||
return AppDefaults.bool(for: Key.suppressSyncOnLaunch)
|
||||
return AppDefaults.bool(for: AppDefaultsKey.suppressSyncOnLaunch)
|
||||
}
|
||||
set {
|
||||
AppDefaults.setBool(for: Key.suppressSyncOnLaunch, newValue)
|
||||
AppDefaults.setBool(for: AppDefaultsKey.suppressSyncOnLaunch, newValue)
|
||||
}
|
||||
}
|
||||
|
||||
var webInspectorEnabled: Bool {
|
||||
get {
|
||||
return AppDefaults.bool(for: Key.webInspectorEnabled)
|
||||
return AppDefaults.bool(for: AppDefaultsKey.webInspectorEnabled)
|
||||
}
|
||||
set {
|
||||
AppDefaults.setBool(for: Key.webInspectorEnabled, newValue)
|
||||
AppDefaults.setBool(for: AppDefaultsKey.webInspectorEnabled, newValue)
|
||||
}
|
||||
}
|
||||
|
||||
var webInspectorStartsAttached: Bool {
|
||||
get {
|
||||
return AppDefaults.bool(for: Key.webInspectorStartsAttached)
|
||||
return AppDefaults.bool(for: AppDefaultsKey.webInspectorStartsAttached)
|
||||
}
|
||||
set {
|
||||
AppDefaults.setBool(for: Key.webInspectorStartsAttached, newValue)
|
||||
AppDefaults.setBool(for: AppDefaultsKey.webInspectorStartsAttached, newValue)
|
||||
}
|
||||
}
|
||||
|
||||
var timelineSortDirection: ComparisonResult {
|
||||
get {
|
||||
return AppDefaults.sortDirection(for: Key.timelineSortDirection)
|
||||
return AppDefaults.sortDirection(for: AppDefaultsKey.timelineSortDirection)
|
||||
}
|
||||
set {
|
||||
AppDefaults.setSortDirection(for: Key.timelineSortDirection, newValue)
|
||||
AppDefaults.setSortDirection(for: AppDefaultsKey.timelineSortDirection, newValue)
|
||||
}
|
||||
}
|
||||
|
||||
var timelineGroupByFeed: Bool {
|
||||
get {
|
||||
return AppDefaults.bool(for: Key.timelineGroupByFeed)
|
||||
return AppDefaults.bool(for: AppDefaultsKey.timelineGroupByFeed)
|
||||
}
|
||||
set {
|
||||
AppDefaults.setBool(for: Key.timelineGroupByFeed, newValue)
|
||||
AppDefaults.setBool(for: AppDefaultsKey.timelineGroupByFeed, newValue)
|
||||
}
|
||||
}
|
||||
|
||||
var timelineShowsSeparators: Bool {
|
||||
return AppDefaults.bool(for: Key.timelineShowsSeparators)
|
||||
return AppDefaults.bool(for: AppDefaultsKey.timelineShowsSeparators)
|
||||
}
|
||||
|
||||
var articleTextSize: ArticleTextSize {
|
||||
get {
|
||||
let rawValue = UserDefaults.standard.integer(forKey: Key.articleTextSize)
|
||||
let rawValue = UserDefaults.standard.integer(forKey: AppDefaultsKey.articleTextSize)
|
||||
return ArticleTextSize(rawValue: rawValue) ?? ArticleTextSize.large
|
||||
}
|
||||
set {
|
||||
UserDefaults.standard.set(newValue.rawValue, forKey: Key.articleTextSize)
|
||||
UserDefaults.standard.set(newValue.rawValue, forKey: AppDefaultsKey.articleTextSize)
|
||||
}
|
||||
}
|
||||
|
||||
var refreshInterval: RefreshInterval {
|
||||
get {
|
||||
let rawValue = UserDefaults.standard.integer(forKey: Key.refreshInterval)
|
||||
let rawValue = UserDefaults.standard.integer(forKey: AppDefaultsKey.refreshInterval)
|
||||
return RefreshInterval(rawValue: rawValue) ?? RefreshInterval.everyHour
|
||||
}
|
||||
set {
|
||||
UserDefaults.standard.set(newValue.rawValue, forKey: Key.refreshInterval)
|
||||
UserDefaults.standard.set(newValue.rawValue, forKey: AppDefaultsKey.refreshInterval)
|
||||
}
|
||||
}
|
||||
|
||||
var isArticleContentJavascriptEnabled: Bool {
|
||||
get {
|
||||
UserDefaults.standard.bool(forKey: Key.articleContentJavascriptEnabled)
|
||||
UserDefaults.standard.bool(forKey: AppDefaultsKey.articleContentJavascriptEnabled)
|
||||
}
|
||||
set {
|
||||
UserDefaults.standard.set(newValue, forKey: Key.articleContentJavascriptEnabled)
|
||||
UserDefaults.standard.set(newValue, forKey: AppDefaultsKey.articleContentJavascriptEnabled)
|
||||
}
|
||||
}
|
||||
|
||||
@ -312,16 +279,16 @@ final class AppDefaults {
|
||||
#endif
|
||||
|
||||
let defaults: [String: Any] = [
|
||||
Key.sidebarFontSize: FontSize.medium.rawValue,
|
||||
Key.timelineFontSize: FontSize.medium.rawValue,
|
||||
Key.detailFontSize: FontSize.medium.rawValue,
|
||||
Key.timelineSortDirection: ComparisonResult.orderedDescending.rawValue,
|
||||
Key.timelineGroupByFeed: false,
|
||||
AppDefaultsKey.sidebarFontSize: FontSize.medium.rawValue,
|
||||
AppDefaultsKey.timelineFontSize: FontSize.medium.rawValue,
|
||||
AppDefaultsKey.detailFontSize: FontSize.medium.rawValue,
|
||||
AppDefaultsKey.timelineSortDirection: ComparisonResult.orderedDescending.rawValue,
|
||||
AppDefaultsKey.timelineGroupByFeed: false,
|
||||
"NSScrollViewShouldScrollUnderTitlebar": false,
|
||||
Key.refreshInterval: RefreshInterval.everyHour.rawValue,
|
||||
Key.showDebugMenu: showDebugMenu,
|
||||
Key.currentThemeName: Self.defaultThemeName,
|
||||
Key.articleContentJavascriptEnabled: true
|
||||
AppDefaultsKey.refreshInterval: RefreshInterval.everyHour.rawValue,
|
||||
AppDefaultsKey.showDebugMenu: showDebugMenu,
|
||||
AppDefaultsKey.currentThemeName: Self.defaultThemeName,
|
||||
AppDefaultsKey.articleContentJavascriptEnabled: true
|
||||
]
|
||||
|
||||
UserDefaults.standard.register(defaults: defaults)
|
||||
@ -358,10 +325,10 @@ private extension AppDefaults {
|
||||
|
||||
static var firstRunDate: Date? {
|
||||
get {
|
||||
return AppDefaults.date(for: Key.firstRunDate)
|
||||
return AppDefaults.date(for: AppDefaultsKey.firstRunDate)
|
||||
}
|
||||
set {
|
||||
AppDefaults.setDate(for: Key.firstRunDate, newValue)
|
||||
AppDefaults.setDate(for: AppDefaultsKey.firstRunDate, newValue)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -412,6 +412,7 @@
|
||||
84C1ECED2CDFE49100C7456A /* PBXFileSystemSynchronizedBuildFileExceptionSet */ = {
|
||||
isa = PBXFileSystemSynchronizedBuildFileExceptionSet;
|
||||
membershipExceptions = (
|
||||
AppDefaultsKey.swift,
|
||||
Extensions/IconImage.swift,
|
||||
"Extensions/Node-Extensions.swift",
|
||||
ShareExtension/ExtensionContainers.swift,
|
||||
@ -445,6 +446,7 @@
|
||||
84C1ECF02CDFE49100C7456A /* PBXFileSystemSynchronizedBuildFileExceptionSet */ = {
|
||||
isa = PBXFileSystemSynchronizedBuildFileExceptionSet;
|
||||
membershipExceptions = (
|
||||
AppDefaultsKey.swift,
|
||||
ArticleRendering/ArticleTextSize.swift,
|
||||
ShareExtension/ExtensionContainers.swift,
|
||||
ShareExtension/ExtensionContainersFile.swift,
|
||||
|
60
Shared/AppDefaultsKey.swift
Normal file
60
Shared/AppDefaultsKey.swift
Normal file
@ -0,0 +1,60 @@
|
||||
//
|
||||
// AppDefaultsKey.swift
|
||||
// NetNewsWire
|
||||
//
|
||||
// Created by Brent Simmons on 1/25/25.
|
||||
// Copyright © 2025 Ranchero Software. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
struct AppDefaultsKey {
|
||||
|
||||
static let firstRunDate = "firstRunDate"
|
||||
static let lastImageCacheFlushDate = "lastImageCacheFlushDate"
|
||||
static let timelineGroupByFeed = "timelineGroupByFeed"
|
||||
static let timelineSortDirection = "timelineSortDirection"
|
||||
static let addFeedAccountID = "addFeedAccountID"
|
||||
static let addFeedFolderName = "addFeedFolderName"
|
||||
static let addFolderAccountID = "addFolderAccountID"
|
||||
static let currentThemeName = "currentThemeName"
|
||||
static let articleContentJavascriptEnabled = "articleContentJavascriptEnabled"
|
||||
|
||||
#if os(macOS)
|
||||
|
||||
static let windowState = "windowState"
|
||||
static let sidebarFontSize = "sidebarFontSize"
|
||||
static let timelineFontSize = "timelineFontSize"
|
||||
static let detailFontSize = "detailFontSize"
|
||||
static let openInBrowserInBackground = "openInBrowserInBackground"
|
||||
static let subscribeToFeedsInDefaultBrowser = "subscribeToFeedsInDefaultBrowser"
|
||||
static let articleTextSize = "articleTextSize"
|
||||
static let refreshInterval = "refreshInterval"
|
||||
static let importOPMLAccountID = "importOPMLAccountID"
|
||||
static let exportOPMLAccountID = "exportOPMLAccountID"
|
||||
static let defaultBrowserID = "defaultBrowserID"
|
||||
|
||||
// Hidden prefs
|
||||
static let showDebugMenu = "ShowDebugMenu"
|
||||
static let timelineShowsSeparators = "CorreiaSeparators"
|
||||
static let showTitleOnMainWindow = "KafasisTitleMode"
|
||||
static let feedDoubleClickMarkAsRead = "GruberFeedDoubleClickMarkAsRead"
|
||||
static let suppressSyncOnLaunch = "DevroeSuppressSyncOnLaunch"
|
||||
|
||||
static let webInspectorEnabled = "WebInspectorEnabled"
|
||||
static let webInspectorStartsAttached = "__WebInspectorPageGroupLevel1__.WebKit2InspectorStartsAttached"
|
||||
|
||||
#elseif os(iOS)
|
||||
|
||||
static let userInterfaceColorPalette = "userInterfaceColorPalette"
|
||||
static let refreshClearsReadArticles = "refreshClearsReadArticles"
|
||||
static let timelineNumberOfLines = "timelineNumberOfLines"
|
||||
static let timelineIconDimension = "timelineIconSize"
|
||||
static let articleFullscreenAvailable = "articleFullscreenAvailable"
|
||||
static let articleFullscreenEnabled = "articleFullscreenEnabled"
|
||||
static let confirmMarkAllAsRead = "confirmMarkAllAsRead"
|
||||
static let lastRefresh = "lastRefresh"
|
||||
static let useSystemBrowser = "useSystemBrowser"
|
||||
|
||||
#endif
|
||||
}
|
@ -39,27 +39,6 @@ final class AppDefaults {
|
||||
return UserDefaults.init(suiteName: suiteName)!
|
||||
}()
|
||||
|
||||
struct Key {
|
||||
static let userInterfaceColorPalette = "userInterfaceColorPalette"
|
||||
static let lastImageCacheFlushDate = "lastImageCacheFlushDate"
|
||||
static let firstRunDate = "firstRunDate"
|
||||
static let timelineGroupByFeed = "timelineGroupByFeed"
|
||||
static let refreshClearsReadArticles = "refreshClearsReadArticles"
|
||||
static let timelineNumberOfLines = "timelineNumberOfLines"
|
||||
static let timelineIconDimension = "timelineIconSize"
|
||||
static let timelineSortDirection = "timelineSortDirection"
|
||||
static let articleFullscreenAvailable = "articleFullscreenAvailable"
|
||||
static let articleFullscreenEnabled = "articleFullscreenEnabled"
|
||||
static let confirmMarkAllAsRead = "confirmMarkAllAsRead"
|
||||
static let lastRefresh = "lastRefresh"
|
||||
static let addFeedAccountID = "addFeedAccountID"
|
||||
static let addFeedFolderName = "addFeedFolderName"
|
||||
static let addFolderAccountID = "addFolderAccountID"
|
||||
static let useSystemBrowser = "useSystemBrowser"
|
||||
static let currentThemeName = "currentThemeName"
|
||||
static let articleContentJavascriptEnabled = "articleContentJavascriptEnabled"
|
||||
}
|
||||
|
||||
let isDeveloperBuild: Bool = {
|
||||
if let dev = Bundle.main.object(forInfoDictionaryKey: "DeveloperEntitlements") as? String, dev == "-dev" {
|
||||
return true
|
||||
@ -68,7 +47,7 @@ final class AppDefaults {
|
||||
}()
|
||||
|
||||
let isFirstRun: Bool = {
|
||||
if AppDefaults.store.object(forKey: Key.firstRunDate) as? Date == nil {
|
||||
if AppDefaults.store.object(forKey: AppDefaultsKey.firstRunDate) as? Date == nil {
|
||||
firstRunDate = Date()
|
||||
return true
|
||||
}
|
||||
@ -77,103 +56,103 @@ final class AppDefaults {
|
||||
|
||||
static var userInterfaceColorPalette: UserInterfaceColorPalette {
|
||||
get {
|
||||
if let result = UserInterfaceColorPalette(rawValue: int(for: Key.userInterfaceColorPalette)) {
|
||||
if let result = UserInterfaceColorPalette(rawValue: int(for: AppDefaultsKey.userInterfaceColorPalette)) {
|
||||
return result
|
||||
}
|
||||
return .automatic
|
||||
}
|
||||
set {
|
||||
setInt(for: Key.userInterfaceColorPalette, newValue.rawValue)
|
||||
setInt(for: AppDefaultsKey.userInterfaceColorPalette, newValue.rawValue)
|
||||
}
|
||||
}
|
||||
|
||||
var addFeedAccountID: String? {
|
||||
get {
|
||||
return AppDefaults.string(for: Key.addFeedAccountID)
|
||||
return AppDefaults.string(for: AppDefaultsKey.addFeedAccountID)
|
||||
}
|
||||
set {
|
||||
AppDefaults.setString(for: Key.addFeedAccountID, newValue)
|
||||
AppDefaults.setString(for: AppDefaultsKey.addFeedAccountID, newValue)
|
||||
}
|
||||
}
|
||||
|
||||
var addFeedFolderName: String? {
|
||||
get {
|
||||
return AppDefaults.string(for: Key.addFeedFolderName)
|
||||
return AppDefaults.string(for: AppDefaultsKey.addFeedFolderName)
|
||||
}
|
||||
set {
|
||||
AppDefaults.setString(for: Key.addFeedFolderName, newValue)
|
||||
AppDefaults.setString(for: AppDefaultsKey.addFeedFolderName, newValue)
|
||||
}
|
||||
}
|
||||
|
||||
var addFolderAccountID: String? {
|
||||
get {
|
||||
return AppDefaults.string(for: Key.addFolderAccountID)
|
||||
return AppDefaults.string(for: AppDefaultsKey.addFolderAccountID)
|
||||
}
|
||||
set {
|
||||
AppDefaults.setString(for: Key.addFolderAccountID, newValue)
|
||||
AppDefaults.setString(for: AppDefaultsKey.addFolderAccountID, newValue)
|
||||
}
|
||||
}
|
||||
|
||||
var useSystemBrowser: Bool {
|
||||
get {
|
||||
return UserDefaults.standard.bool(forKey: Key.useSystemBrowser)
|
||||
return UserDefaults.standard.bool(forKey: AppDefaultsKey.useSystemBrowser)
|
||||
}
|
||||
set {
|
||||
UserDefaults.standard.setValue(newValue, forKey: Key.useSystemBrowser)
|
||||
UserDefaults.standard.setValue(newValue, forKey: AppDefaultsKey.useSystemBrowser)
|
||||
}
|
||||
}
|
||||
|
||||
var lastImageCacheFlushDate: Date? {
|
||||
get {
|
||||
return AppDefaults.date(for: Key.lastImageCacheFlushDate)
|
||||
return AppDefaults.date(for: AppDefaultsKey.lastImageCacheFlushDate)
|
||||
}
|
||||
set {
|
||||
AppDefaults.setDate(for: Key.lastImageCacheFlushDate, newValue)
|
||||
AppDefaults.setDate(for: AppDefaultsKey.lastImageCacheFlushDate, newValue)
|
||||
}
|
||||
}
|
||||
|
||||
var timelineGroupByFeed: Bool {
|
||||
get {
|
||||
return AppDefaults.bool(for: Key.timelineGroupByFeed)
|
||||
return AppDefaults.bool(for: AppDefaultsKey.timelineGroupByFeed)
|
||||
}
|
||||
set {
|
||||
AppDefaults.setBool(for: Key.timelineGroupByFeed, newValue)
|
||||
AppDefaults.setBool(for: AppDefaultsKey.timelineGroupByFeed, newValue)
|
||||
}
|
||||
}
|
||||
|
||||
var refreshClearsReadArticles: Bool {
|
||||
get {
|
||||
return AppDefaults.bool(for: Key.refreshClearsReadArticles)
|
||||
return AppDefaults.bool(for: AppDefaultsKey.refreshClearsReadArticles)
|
||||
}
|
||||
set {
|
||||
AppDefaults.setBool(for: Key.refreshClearsReadArticles, newValue)
|
||||
AppDefaults.setBool(for: AppDefaultsKey.refreshClearsReadArticles, newValue)
|
||||
}
|
||||
}
|
||||
|
||||
var timelineSortDirection: ComparisonResult {
|
||||
get {
|
||||
return AppDefaults.sortDirection(for: Key.timelineSortDirection)
|
||||
return AppDefaults.sortDirection(for: AppDefaultsKey.timelineSortDirection)
|
||||
}
|
||||
set {
|
||||
AppDefaults.setSortDirection(for: Key.timelineSortDirection, newValue)
|
||||
AppDefaults.setSortDirection(for: AppDefaultsKey.timelineSortDirection, newValue)
|
||||
}
|
||||
}
|
||||
|
||||
var articleFullscreenAvailable: Bool {
|
||||
get {
|
||||
return AppDefaults.bool(for: Key.articleFullscreenAvailable)
|
||||
return AppDefaults.bool(for: AppDefaultsKey.articleFullscreenAvailable)
|
||||
}
|
||||
set {
|
||||
AppDefaults.setBool(for: Key.articleFullscreenAvailable, newValue)
|
||||
AppDefaults.setBool(for: AppDefaultsKey.articleFullscreenAvailable, newValue)
|
||||
}
|
||||
}
|
||||
|
||||
var articleFullscreenEnabled: Bool {
|
||||
get {
|
||||
return articleFullscreenAvailable && AppDefaults.bool(for: Key.articleFullscreenEnabled)
|
||||
return articleFullscreenAvailable && AppDefaults.bool(for: AppDefaultsKey.articleFullscreenEnabled)
|
||||
}
|
||||
set {
|
||||
AppDefaults.setBool(for: Key.articleFullscreenEnabled, newValue)
|
||||
AppDefaults.setBool(for: AppDefaultsKey.articleFullscreenEnabled, newValue)
|
||||
}
|
||||
}
|
||||
|
||||
@ -183,70 +162,70 @@ final class AppDefaults {
|
||||
|
||||
var confirmMarkAllAsRead: Bool {
|
||||
get {
|
||||
return AppDefaults.bool(for: Key.confirmMarkAllAsRead)
|
||||
return AppDefaults.bool(for: AppDefaultsKey.confirmMarkAllAsRead)
|
||||
}
|
||||
set {
|
||||
AppDefaults.setBool(for: Key.confirmMarkAllAsRead, newValue)
|
||||
AppDefaults.setBool(for: AppDefaultsKey.confirmMarkAllAsRead, newValue)
|
||||
}
|
||||
}
|
||||
|
||||
var lastRefresh: Date? {
|
||||
get {
|
||||
return AppDefaults.date(for: Key.lastRefresh)
|
||||
return AppDefaults.date(for: AppDefaultsKey.lastRefresh)
|
||||
}
|
||||
set {
|
||||
AppDefaults.setDate(for: Key.lastRefresh, newValue)
|
||||
AppDefaults.setDate(for: AppDefaultsKey.lastRefresh, newValue)
|
||||
}
|
||||
}
|
||||
|
||||
var timelineNumberOfLines: Int {
|
||||
get {
|
||||
return AppDefaults.int(for: Key.timelineNumberOfLines)
|
||||
return AppDefaults.int(for: AppDefaultsKey.timelineNumberOfLines)
|
||||
}
|
||||
set {
|
||||
AppDefaults.setInt(for: Key.timelineNumberOfLines, newValue)
|
||||
AppDefaults.setInt(for: AppDefaultsKey.timelineNumberOfLines, newValue)
|
||||
}
|
||||
}
|
||||
|
||||
var timelineIconSize: IconSize {
|
||||
get {
|
||||
let rawValue = AppDefaults.store.integer(forKey: Key.timelineIconDimension)
|
||||
let rawValue = AppDefaults.store.integer(forKey: AppDefaultsKey.timelineIconDimension)
|
||||
return IconSize(rawValue: rawValue) ?? IconSize.medium
|
||||
}
|
||||
set {
|
||||
AppDefaults.store.set(newValue.rawValue, forKey: Key.timelineIconDimension)
|
||||
AppDefaults.store.set(newValue.rawValue, forKey: AppDefaultsKey.timelineIconDimension)
|
||||
}
|
||||
}
|
||||
|
||||
var currentThemeName: String? {
|
||||
get {
|
||||
return AppDefaults.string(for: Key.currentThemeName)
|
||||
return AppDefaults.string(for: AppDefaultsKey.currentThemeName)
|
||||
}
|
||||
set {
|
||||
AppDefaults.setString(for: Key.currentThemeName, newValue)
|
||||
AppDefaults.setString(for: AppDefaultsKey.currentThemeName, newValue)
|
||||
}
|
||||
}
|
||||
|
||||
var isArticleContentJavascriptEnabled: Bool {
|
||||
get {
|
||||
UserDefaults.standard.bool(forKey: Key.articleContentJavascriptEnabled)
|
||||
UserDefaults.standard.bool(forKey: AppDefaultsKey.articleContentJavascriptEnabled)
|
||||
}
|
||||
set {
|
||||
UserDefaults.standard.set(newValue, forKey: Key.articleContentJavascriptEnabled)
|
||||
UserDefaults.standard.set(newValue, forKey: AppDefaultsKey.articleContentJavascriptEnabled)
|
||||
}
|
||||
}
|
||||
|
||||
static func registerDefaults() {
|
||||
let defaults: [String: Any] = [Key.userInterfaceColorPalette: UserInterfaceColorPalette.automatic.rawValue,
|
||||
Key.timelineGroupByFeed: false,
|
||||
Key.refreshClearsReadArticles: false,
|
||||
Key.timelineNumberOfLines: 2,
|
||||
Key.timelineIconDimension: IconSize.medium.rawValue,
|
||||
Key.timelineSortDirection: ComparisonResult.orderedDescending.rawValue,
|
||||
Key.articleFullscreenAvailable: false,
|
||||
Key.articleFullscreenEnabled: false,
|
||||
Key.confirmMarkAllAsRead: true,
|
||||
Key.currentThemeName: Self.defaultThemeName]
|
||||
let defaults: [String: Any] = [AppDefaultsKey.userInterfaceColorPalette: UserInterfaceColorPalette.automatic.rawValue,
|
||||
AppDefaultsKey.timelineGroupByFeed: false,
|
||||
AppDefaultsKey.refreshClearsReadArticles: false,
|
||||
AppDefaultsKey.timelineNumberOfLines: 2,
|
||||
AppDefaultsKey.timelineIconDimension: IconSize.medium.rawValue,
|
||||
AppDefaultsKey.timelineSortDirection: ComparisonResult.orderedDescending.rawValue,
|
||||
AppDefaultsKey.articleFullscreenAvailable: false,
|
||||
AppDefaultsKey.articleFullscreenEnabled: false,
|
||||
AppDefaultsKey.confirmMarkAllAsRead: true,
|
||||
AppDefaultsKey.currentThemeName: Self.defaultThemeName]
|
||||
AppDefaults.store.register(defaults: defaults)
|
||||
}
|
||||
|
||||
@ -256,10 +235,10 @@ private extension AppDefaults {
|
||||
|
||||
static var firstRunDate: Date? {
|
||||
get {
|
||||
return date(for: Key.firstRunDate)
|
||||
return date(for: AppDefaultsKey.firstRunDate)
|
||||
}
|
||||
set {
|
||||
setDate(for: Key.firstRunDate, newValue)
|
||||
setDate(for: AppDefaultsKey.firstRunDate, newValue)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user