Add shared AppDefaultsKey.
This commit is contained in:
parent
5651764907
commit
d9d47749ef
@ -21,39 +21,6 @@ final class AppDefaults {
|
|||||||
|
|
||||||
static let shared = 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 smallestFontSizeRawValue = FontSize.small.rawValue
|
||||||
private static let largestFontSizeRawValue = FontSize.veryLarge.rawValue
|
private static let largestFontSizeRawValue = FontSize.veryLarge.rawValue
|
||||||
|
|
||||||
@ -65,7 +32,7 @@ final class AppDefaults {
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
var isFirstRun: Bool = {
|
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()
|
firstRunDate = Date()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@ -74,28 +41,28 @@ final class AppDefaults {
|
|||||||
|
|
||||||
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: AppDefaultsKey.windowState) as? [AnyHashable: Any]
|
||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
UserDefaults.standard.set(newValue, forKey: Key.windowState)
|
UserDefaults.standard.set(newValue, forKey: AppDefaultsKey.windowState)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var lastImageCacheFlushDate: Date? {
|
var lastImageCacheFlushDate: Date? {
|
||||||
get {
|
get {
|
||||||
return AppDefaults.date(for: Key.lastImageCacheFlushDate)
|
return AppDefaults.date(for: AppDefaultsKey.lastImageCacheFlushDate)
|
||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
AppDefaults.setDate(for: Key.lastImageCacheFlushDate, newValue)
|
AppDefaults.setDate(for: AppDefaultsKey.lastImageCacheFlushDate, newValue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var openInBrowserInBackground: Bool {
|
var openInBrowserInBackground: Bool {
|
||||||
get {
|
get {
|
||||||
return AppDefaults.bool(for: Key.openInBrowserInBackground)
|
return AppDefaults.bool(for: AppDefaultsKey.openInBrowserInBackground)
|
||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
AppDefaults.setBool(for: Key.openInBrowserInBackground, newValue)
|
AppDefaults.setBool(for: AppDefaultsKey.openInBrowserInBackground, newValue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,195 +79,195 @@ final class AppDefaults {
|
|||||||
|
|
||||||
var subscribeToFeedsInDefaultBrowser: Bool {
|
var subscribeToFeedsInDefaultBrowser: Bool {
|
||||||
get {
|
get {
|
||||||
return subscribeToFeedDefaults.bool(forKey: Key.subscribeToFeedsInDefaultBrowser)
|
return subscribeToFeedDefaults.bool(forKey: AppDefaultsKey.subscribeToFeedsInDefaultBrowser)
|
||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
subscribeToFeedDefaults.set(newValue, forKey: Key.subscribeToFeedsInDefaultBrowser)
|
subscribeToFeedDefaults.set(newValue, forKey: AppDefaultsKey.subscribeToFeedsInDefaultBrowser)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var sidebarFontSize: FontSize {
|
var sidebarFontSize: FontSize {
|
||||||
get {
|
get {
|
||||||
return fontSize(for: Key.sidebarFontSize)
|
return fontSize(for: AppDefaultsKey.sidebarFontSize)
|
||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
AppDefaults.setFontSize(for: Key.sidebarFontSize, newValue)
|
AppDefaults.setFontSize(for: AppDefaultsKey.sidebarFontSize, newValue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var timelineFontSize: FontSize {
|
var timelineFontSize: FontSize {
|
||||||
get {
|
get {
|
||||||
return fontSize(for: Key.timelineFontSize)
|
return fontSize(for: AppDefaultsKey.timelineFontSize)
|
||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
AppDefaults.setFontSize(for: Key.timelineFontSize, newValue)
|
AppDefaults.setFontSize(for: AppDefaultsKey.timelineFontSize, newValue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var detailFontSize: FontSize {
|
var detailFontSize: FontSize {
|
||||||
get {
|
get {
|
||||||
return fontSize(for: Key.detailFontSize)
|
return fontSize(for: AppDefaultsKey.detailFontSize)
|
||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
AppDefaults.setFontSize(for: Key.detailFontSize, newValue)
|
AppDefaults.setFontSize(for: AppDefaultsKey.detailFontSize, newValue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var addFeedAccountID: String? {
|
var addFeedAccountID: String? {
|
||||||
get {
|
get {
|
||||||
return AppDefaults.string(for: Key.addFeedAccountID)
|
return AppDefaults.string(for: AppDefaultsKey.addFeedAccountID)
|
||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
AppDefaults.setString(for: Key.addFeedAccountID, newValue)
|
AppDefaults.setString(for: AppDefaultsKey.addFeedAccountID, newValue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var addFeedFolderName: String? {
|
var addFeedFolderName: String? {
|
||||||
get {
|
get {
|
||||||
return AppDefaults.string(for: Key.addFeedFolderName)
|
return AppDefaults.string(for: AppDefaultsKey.addFeedFolderName)
|
||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
AppDefaults.setString(for: Key.addFeedFolderName, newValue)
|
AppDefaults.setString(for: AppDefaultsKey.addFeedFolderName, newValue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var addFolderAccountID: String? {
|
var addFolderAccountID: String? {
|
||||||
get {
|
get {
|
||||||
return AppDefaults.string(for: Key.addFolderAccountID)
|
return AppDefaults.string(for: AppDefaultsKey.addFolderAccountID)
|
||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
AppDefaults.setString(for: Key.addFolderAccountID, newValue)
|
AppDefaults.setString(for: AppDefaultsKey.addFolderAccountID, newValue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var importOPMLAccountID: String? {
|
var importOPMLAccountID: String? {
|
||||||
get {
|
get {
|
||||||
return AppDefaults.string(for: Key.importOPMLAccountID)
|
return AppDefaults.string(for: AppDefaultsKey.importOPMLAccountID)
|
||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
AppDefaults.setString(for: Key.importOPMLAccountID, newValue)
|
AppDefaults.setString(for: AppDefaultsKey.importOPMLAccountID, newValue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var exportOPMLAccountID: String? {
|
var exportOPMLAccountID: String? {
|
||||||
get {
|
get {
|
||||||
return AppDefaults.string(for: Key.exportOPMLAccountID)
|
return AppDefaults.string(for: AppDefaultsKey.exportOPMLAccountID)
|
||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
AppDefaults.setString(for: Key.exportOPMLAccountID, newValue)
|
AppDefaults.setString(for: AppDefaultsKey.exportOPMLAccountID, newValue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var defaultBrowserID: String? {
|
var defaultBrowserID: String? {
|
||||||
get {
|
get {
|
||||||
return AppDefaults.string(for: Key.defaultBrowserID)
|
return AppDefaults.string(for: AppDefaultsKey.defaultBrowserID)
|
||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
AppDefaults.setString(for: Key.defaultBrowserID, newValue)
|
AppDefaults.setString(for: AppDefaultsKey.defaultBrowserID, newValue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var currentThemeName: String? {
|
var currentThemeName: String? {
|
||||||
get {
|
get {
|
||||||
return AppDefaults.string(for: Key.currentThemeName)
|
return AppDefaults.string(for: AppDefaultsKey.currentThemeName)
|
||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
AppDefaults.setString(for: Key.currentThemeName, newValue)
|
AppDefaults.setString(for: AppDefaultsKey.currentThemeName, newValue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var showTitleOnMainWindow: Bool {
|
var showTitleOnMainWindow: Bool {
|
||||||
return AppDefaults.bool(for: Key.showTitleOnMainWindow)
|
return AppDefaults.bool(for: AppDefaultsKey.showTitleOnMainWindow)
|
||||||
}
|
}
|
||||||
|
|
||||||
var showDebugMenu: Bool {
|
var showDebugMenu: Bool {
|
||||||
return AppDefaults.bool(for: Key.showDebugMenu)
|
return AppDefaults.bool(for: AppDefaultsKey.showDebugMenu)
|
||||||
}
|
}
|
||||||
|
|
||||||
var feedDoubleClickMarkAsRead: Bool {
|
var feedDoubleClickMarkAsRead: Bool {
|
||||||
get {
|
get {
|
||||||
return AppDefaults.bool(for: Key.feedDoubleClickMarkAsRead)
|
return AppDefaults.bool(for: AppDefaultsKey.feedDoubleClickMarkAsRead)
|
||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
AppDefaults.setBool(for: Key.feedDoubleClickMarkAsRead, newValue)
|
AppDefaults.setBool(for: AppDefaultsKey.feedDoubleClickMarkAsRead, newValue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var suppressSyncOnLaunch: Bool {
|
var suppressSyncOnLaunch: Bool {
|
||||||
get {
|
get {
|
||||||
return AppDefaults.bool(for: Key.suppressSyncOnLaunch)
|
return AppDefaults.bool(for: AppDefaultsKey.suppressSyncOnLaunch)
|
||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
AppDefaults.setBool(for: Key.suppressSyncOnLaunch, newValue)
|
AppDefaults.setBool(for: AppDefaultsKey.suppressSyncOnLaunch, newValue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var webInspectorEnabled: Bool {
|
var webInspectorEnabled: Bool {
|
||||||
get {
|
get {
|
||||||
return AppDefaults.bool(for: Key.webInspectorEnabled)
|
return AppDefaults.bool(for: AppDefaultsKey.webInspectorEnabled)
|
||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
AppDefaults.setBool(for: Key.webInspectorEnabled, newValue)
|
AppDefaults.setBool(for: AppDefaultsKey.webInspectorEnabled, newValue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var webInspectorStartsAttached: Bool {
|
var webInspectorStartsAttached: Bool {
|
||||||
get {
|
get {
|
||||||
return AppDefaults.bool(for: Key.webInspectorStartsAttached)
|
return AppDefaults.bool(for: AppDefaultsKey.webInspectorStartsAttached)
|
||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
AppDefaults.setBool(for: Key.webInspectorStartsAttached, newValue)
|
AppDefaults.setBool(for: AppDefaultsKey.webInspectorStartsAttached, newValue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var timelineSortDirection: ComparisonResult {
|
var timelineSortDirection: ComparisonResult {
|
||||||
get {
|
get {
|
||||||
return AppDefaults.sortDirection(for: Key.timelineSortDirection)
|
return AppDefaults.sortDirection(for: AppDefaultsKey.timelineSortDirection)
|
||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
AppDefaults.setSortDirection(for: Key.timelineSortDirection, newValue)
|
AppDefaults.setSortDirection(for: AppDefaultsKey.timelineSortDirection, newValue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var timelineGroupByFeed: Bool {
|
var timelineGroupByFeed: Bool {
|
||||||
get {
|
get {
|
||||||
return AppDefaults.bool(for: Key.timelineGroupByFeed)
|
return AppDefaults.bool(for: AppDefaultsKey.timelineGroupByFeed)
|
||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
AppDefaults.setBool(for: Key.timelineGroupByFeed, newValue)
|
AppDefaults.setBool(for: AppDefaultsKey.timelineGroupByFeed, newValue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var timelineShowsSeparators: Bool {
|
var timelineShowsSeparators: Bool {
|
||||||
return AppDefaults.bool(for: Key.timelineShowsSeparators)
|
return AppDefaults.bool(for: AppDefaultsKey.timelineShowsSeparators)
|
||||||
}
|
}
|
||||||
|
|
||||||
var articleTextSize: ArticleTextSize {
|
var articleTextSize: ArticleTextSize {
|
||||||
get {
|
get {
|
||||||
let rawValue = UserDefaults.standard.integer(forKey: Key.articleTextSize)
|
let rawValue = UserDefaults.standard.integer(forKey: AppDefaultsKey.articleTextSize)
|
||||||
return ArticleTextSize(rawValue: rawValue) ?? ArticleTextSize.large
|
return ArticleTextSize(rawValue: rawValue) ?? ArticleTextSize.large
|
||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
UserDefaults.standard.set(newValue.rawValue, forKey: Key.articleTextSize)
|
UserDefaults.standard.set(newValue.rawValue, forKey: AppDefaultsKey.articleTextSize)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var refreshInterval: RefreshInterval {
|
var refreshInterval: RefreshInterval {
|
||||||
get {
|
get {
|
||||||
let rawValue = UserDefaults.standard.integer(forKey: Key.refreshInterval)
|
let rawValue = UserDefaults.standard.integer(forKey: AppDefaultsKey.refreshInterval)
|
||||||
return RefreshInterval(rawValue: rawValue) ?? RefreshInterval.everyHour
|
return RefreshInterval(rawValue: rawValue) ?? RefreshInterval.everyHour
|
||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
UserDefaults.standard.set(newValue.rawValue, forKey: Key.refreshInterval)
|
UserDefaults.standard.set(newValue.rawValue, forKey: AppDefaultsKey.refreshInterval)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var isArticleContentJavascriptEnabled: Bool {
|
var isArticleContentJavascriptEnabled: Bool {
|
||||||
get {
|
get {
|
||||||
UserDefaults.standard.bool(forKey: Key.articleContentJavascriptEnabled)
|
UserDefaults.standard.bool(forKey: AppDefaultsKey.articleContentJavascriptEnabled)
|
||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
UserDefaults.standard.set(newValue, forKey: Key.articleContentJavascriptEnabled)
|
UserDefaults.standard.set(newValue, forKey: AppDefaultsKey.articleContentJavascriptEnabled)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -312,16 +279,16 @@ final class AppDefaults {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
let defaults: [String: Any] = [
|
let defaults: [String: Any] = [
|
||||||
Key.sidebarFontSize: FontSize.medium.rawValue,
|
AppDefaultsKey.sidebarFontSize: FontSize.medium.rawValue,
|
||||||
Key.timelineFontSize: FontSize.medium.rawValue,
|
AppDefaultsKey.timelineFontSize: FontSize.medium.rawValue,
|
||||||
Key.detailFontSize: FontSize.medium.rawValue,
|
AppDefaultsKey.detailFontSize: FontSize.medium.rawValue,
|
||||||
Key.timelineSortDirection: ComparisonResult.orderedDescending.rawValue,
|
AppDefaultsKey.timelineSortDirection: ComparisonResult.orderedDescending.rawValue,
|
||||||
Key.timelineGroupByFeed: false,
|
AppDefaultsKey.timelineGroupByFeed: false,
|
||||||
"NSScrollViewShouldScrollUnderTitlebar": false,
|
"NSScrollViewShouldScrollUnderTitlebar": false,
|
||||||
Key.refreshInterval: RefreshInterval.everyHour.rawValue,
|
AppDefaultsKey.refreshInterval: RefreshInterval.everyHour.rawValue,
|
||||||
Key.showDebugMenu: showDebugMenu,
|
AppDefaultsKey.showDebugMenu: showDebugMenu,
|
||||||
Key.currentThemeName: Self.defaultThemeName,
|
AppDefaultsKey.currentThemeName: Self.defaultThemeName,
|
||||||
Key.articleContentJavascriptEnabled: true
|
AppDefaultsKey.articleContentJavascriptEnabled: true
|
||||||
]
|
]
|
||||||
|
|
||||||
UserDefaults.standard.register(defaults: defaults)
|
UserDefaults.standard.register(defaults: defaults)
|
||||||
@ -358,10 +325,10 @@ private extension AppDefaults {
|
|||||||
|
|
||||||
static var firstRunDate: Date? {
|
static var firstRunDate: Date? {
|
||||||
get {
|
get {
|
||||||
return AppDefaults.date(for: Key.firstRunDate)
|
return AppDefaults.date(for: AppDefaultsKey.firstRunDate)
|
||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
AppDefaults.setDate(for: Key.firstRunDate, newValue)
|
AppDefaults.setDate(for: AppDefaultsKey.firstRunDate, newValue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -412,6 +412,7 @@
|
|||||||
84C1ECED2CDFE49100C7456A /* PBXFileSystemSynchronizedBuildFileExceptionSet */ = {
|
84C1ECED2CDFE49100C7456A /* PBXFileSystemSynchronizedBuildFileExceptionSet */ = {
|
||||||
isa = PBXFileSystemSynchronizedBuildFileExceptionSet;
|
isa = PBXFileSystemSynchronizedBuildFileExceptionSet;
|
||||||
membershipExceptions = (
|
membershipExceptions = (
|
||||||
|
AppDefaultsKey.swift,
|
||||||
Extensions/IconImage.swift,
|
Extensions/IconImage.swift,
|
||||||
"Extensions/Node-Extensions.swift",
|
"Extensions/Node-Extensions.swift",
|
||||||
ShareExtension/ExtensionContainers.swift,
|
ShareExtension/ExtensionContainers.swift,
|
||||||
@ -445,6 +446,7 @@
|
|||||||
84C1ECF02CDFE49100C7456A /* PBXFileSystemSynchronizedBuildFileExceptionSet */ = {
|
84C1ECF02CDFE49100C7456A /* PBXFileSystemSynchronizedBuildFileExceptionSet */ = {
|
||||||
isa = PBXFileSystemSynchronizedBuildFileExceptionSet;
|
isa = PBXFileSystemSynchronizedBuildFileExceptionSet;
|
||||||
membershipExceptions = (
|
membershipExceptions = (
|
||||||
|
AppDefaultsKey.swift,
|
||||||
ArticleRendering/ArticleTextSize.swift,
|
ArticleRendering/ArticleTextSize.swift,
|
||||||
ShareExtension/ExtensionContainers.swift,
|
ShareExtension/ExtensionContainers.swift,
|
||||||
ShareExtension/ExtensionContainersFile.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)!
|
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 = {
|
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
|
||||||
@ -68,7 +47,7 @@ final class AppDefaults {
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
let isFirstRun: Bool = {
|
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()
|
firstRunDate = Date()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@ -77,103 +56,103 @@ final class AppDefaults {
|
|||||||
|
|
||||||
static var userInterfaceColorPalette: UserInterfaceColorPalette {
|
static var userInterfaceColorPalette: UserInterfaceColorPalette {
|
||||||
get {
|
get {
|
||||||
if let result = UserInterfaceColorPalette(rawValue: int(for: Key.userInterfaceColorPalette)) {
|
if let result = UserInterfaceColorPalette(rawValue: int(for: AppDefaultsKey.userInterfaceColorPalette)) {
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
return .automatic
|
return .automatic
|
||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
setInt(for: Key.userInterfaceColorPalette, newValue.rawValue)
|
setInt(for: AppDefaultsKey.userInterfaceColorPalette, newValue.rawValue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var addFeedAccountID: String? {
|
var addFeedAccountID: String? {
|
||||||
get {
|
get {
|
||||||
return AppDefaults.string(for: Key.addFeedAccountID)
|
return AppDefaults.string(for: AppDefaultsKey.addFeedAccountID)
|
||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
AppDefaults.setString(for: Key.addFeedAccountID, newValue)
|
AppDefaults.setString(for: AppDefaultsKey.addFeedAccountID, newValue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var addFeedFolderName: String? {
|
var addFeedFolderName: String? {
|
||||||
get {
|
get {
|
||||||
return AppDefaults.string(for: Key.addFeedFolderName)
|
return AppDefaults.string(for: AppDefaultsKey.addFeedFolderName)
|
||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
AppDefaults.setString(for: Key.addFeedFolderName, newValue)
|
AppDefaults.setString(for: AppDefaultsKey.addFeedFolderName, newValue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var addFolderAccountID: String? {
|
var addFolderAccountID: String? {
|
||||||
get {
|
get {
|
||||||
return AppDefaults.string(for: Key.addFolderAccountID)
|
return AppDefaults.string(for: AppDefaultsKey.addFolderAccountID)
|
||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
AppDefaults.setString(for: Key.addFolderAccountID, newValue)
|
AppDefaults.setString(for: AppDefaultsKey.addFolderAccountID, newValue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var useSystemBrowser: Bool {
|
var useSystemBrowser: Bool {
|
||||||
get {
|
get {
|
||||||
return UserDefaults.standard.bool(forKey: Key.useSystemBrowser)
|
return UserDefaults.standard.bool(forKey: AppDefaultsKey.useSystemBrowser)
|
||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
UserDefaults.standard.setValue(newValue, forKey: Key.useSystemBrowser)
|
UserDefaults.standard.setValue(newValue, forKey: AppDefaultsKey.useSystemBrowser)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var lastImageCacheFlushDate: Date? {
|
var lastImageCacheFlushDate: Date? {
|
||||||
get {
|
get {
|
||||||
return AppDefaults.date(for: Key.lastImageCacheFlushDate)
|
return AppDefaults.date(for: AppDefaultsKey.lastImageCacheFlushDate)
|
||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
AppDefaults.setDate(for: Key.lastImageCacheFlushDate, newValue)
|
AppDefaults.setDate(for: AppDefaultsKey.lastImageCacheFlushDate, newValue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var timelineGroupByFeed: Bool {
|
var timelineGroupByFeed: Bool {
|
||||||
get {
|
get {
|
||||||
return AppDefaults.bool(for: Key.timelineGroupByFeed)
|
return AppDefaults.bool(for: AppDefaultsKey.timelineGroupByFeed)
|
||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
AppDefaults.setBool(for: Key.timelineGroupByFeed, newValue)
|
AppDefaults.setBool(for: AppDefaultsKey.timelineGroupByFeed, newValue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var refreshClearsReadArticles: Bool {
|
var refreshClearsReadArticles: Bool {
|
||||||
get {
|
get {
|
||||||
return AppDefaults.bool(for: Key.refreshClearsReadArticles)
|
return AppDefaults.bool(for: AppDefaultsKey.refreshClearsReadArticles)
|
||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
AppDefaults.setBool(for: Key.refreshClearsReadArticles, newValue)
|
AppDefaults.setBool(for: AppDefaultsKey.refreshClearsReadArticles, newValue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var timelineSortDirection: ComparisonResult {
|
var timelineSortDirection: ComparisonResult {
|
||||||
get {
|
get {
|
||||||
return AppDefaults.sortDirection(for: Key.timelineSortDirection)
|
return AppDefaults.sortDirection(for: AppDefaultsKey.timelineSortDirection)
|
||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
AppDefaults.setSortDirection(for: Key.timelineSortDirection, newValue)
|
AppDefaults.setSortDirection(for: AppDefaultsKey.timelineSortDirection, newValue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var articleFullscreenAvailable: Bool {
|
var articleFullscreenAvailable: Bool {
|
||||||
get {
|
get {
|
||||||
return AppDefaults.bool(for: Key.articleFullscreenAvailable)
|
return AppDefaults.bool(for: AppDefaultsKey.articleFullscreenAvailable)
|
||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
AppDefaults.setBool(for: Key.articleFullscreenAvailable, newValue)
|
AppDefaults.setBool(for: AppDefaultsKey.articleFullscreenAvailable, newValue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var articleFullscreenEnabled: Bool {
|
var articleFullscreenEnabled: Bool {
|
||||||
get {
|
get {
|
||||||
return articleFullscreenAvailable && AppDefaults.bool(for: Key.articleFullscreenEnabled)
|
return articleFullscreenAvailable && AppDefaults.bool(for: AppDefaultsKey.articleFullscreenEnabled)
|
||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
AppDefaults.setBool(for: Key.articleFullscreenEnabled, newValue)
|
AppDefaults.setBool(for: AppDefaultsKey.articleFullscreenEnabled, newValue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -183,70 +162,70 @@ final class AppDefaults {
|
|||||||
|
|
||||||
var confirmMarkAllAsRead: Bool {
|
var confirmMarkAllAsRead: Bool {
|
||||||
get {
|
get {
|
||||||
return AppDefaults.bool(for: Key.confirmMarkAllAsRead)
|
return AppDefaults.bool(for: AppDefaultsKey.confirmMarkAllAsRead)
|
||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
AppDefaults.setBool(for: Key.confirmMarkAllAsRead, newValue)
|
AppDefaults.setBool(for: AppDefaultsKey.confirmMarkAllAsRead, newValue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var lastRefresh: Date? {
|
var lastRefresh: Date? {
|
||||||
get {
|
get {
|
||||||
return AppDefaults.date(for: Key.lastRefresh)
|
return AppDefaults.date(for: AppDefaultsKey.lastRefresh)
|
||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
AppDefaults.setDate(for: Key.lastRefresh, newValue)
|
AppDefaults.setDate(for: AppDefaultsKey.lastRefresh, newValue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var timelineNumberOfLines: Int {
|
var timelineNumberOfLines: Int {
|
||||||
get {
|
get {
|
||||||
return AppDefaults.int(for: Key.timelineNumberOfLines)
|
return AppDefaults.int(for: AppDefaultsKey.timelineNumberOfLines)
|
||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
AppDefaults.setInt(for: Key.timelineNumberOfLines, newValue)
|
AppDefaults.setInt(for: AppDefaultsKey.timelineNumberOfLines, newValue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var timelineIconSize: IconSize {
|
var timelineIconSize: IconSize {
|
||||||
get {
|
get {
|
||||||
let rawValue = AppDefaults.store.integer(forKey: Key.timelineIconDimension)
|
let rawValue = AppDefaults.store.integer(forKey: AppDefaultsKey.timelineIconDimension)
|
||||||
return IconSize(rawValue: rawValue) ?? IconSize.medium
|
return IconSize(rawValue: rawValue) ?? IconSize.medium
|
||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
AppDefaults.store.set(newValue.rawValue, forKey: Key.timelineIconDimension)
|
AppDefaults.store.set(newValue.rawValue, forKey: AppDefaultsKey.timelineIconDimension)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var currentThemeName: String? {
|
var currentThemeName: String? {
|
||||||
get {
|
get {
|
||||||
return AppDefaults.string(for: Key.currentThemeName)
|
return AppDefaults.string(for: AppDefaultsKey.currentThemeName)
|
||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
AppDefaults.setString(for: Key.currentThemeName, newValue)
|
AppDefaults.setString(for: AppDefaultsKey.currentThemeName, newValue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var isArticleContentJavascriptEnabled: Bool {
|
var isArticleContentJavascriptEnabled: Bool {
|
||||||
get {
|
get {
|
||||||
UserDefaults.standard.bool(forKey: Key.articleContentJavascriptEnabled)
|
UserDefaults.standard.bool(forKey: AppDefaultsKey.articleContentJavascriptEnabled)
|
||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
UserDefaults.standard.set(newValue, forKey: Key.articleContentJavascriptEnabled)
|
UserDefaults.standard.set(newValue, forKey: AppDefaultsKey.articleContentJavascriptEnabled)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static func registerDefaults() {
|
static func registerDefaults() {
|
||||||
let defaults: [String: Any] = [Key.userInterfaceColorPalette: UserInterfaceColorPalette.automatic.rawValue,
|
let defaults: [String: Any] = [AppDefaultsKey.userInterfaceColorPalette: UserInterfaceColorPalette.automatic.rawValue,
|
||||||
Key.timelineGroupByFeed: false,
|
AppDefaultsKey.timelineGroupByFeed: false,
|
||||||
Key.refreshClearsReadArticles: false,
|
AppDefaultsKey.refreshClearsReadArticles: false,
|
||||||
Key.timelineNumberOfLines: 2,
|
AppDefaultsKey.timelineNumberOfLines: 2,
|
||||||
Key.timelineIconDimension: IconSize.medium.rawValue,
|
AppDefaultsKey.timelineIconDimension: IconSize.medium.rawValue,
|
||||||
Key.timelineSortDirection: ComparisonResult.orderedDescending.rawValue,
|
AppDefaultsKey.timelineSortDirection: ComparisonResult.orderedDescending.rawValue,
|
||||||
Key.articleFullscreenAvailable: false,
|
AppDefaultsKey.articleFullscreenAvailable: false,
|
||||||
Key.articleFullscreenEnabled: false,
|
AppDefaultsKey.articleFullscreenEnabled: false,
|
||||||
Key.confirmMarkAllAsRead: true,
|
AppDefaultsKey.confirmMarkAllAsRead: true,
|
||||||
Key.currentThemeName: Self.defaultThemeName]
|
AppDefaultsKey.currentThemeName: Self.defaultThemeName]
|
||||||
AppDefaults.store.register(defaults: defaults)
|
AppDefaults.store.register(defaults: defaults)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -256,10 +235,10 @@ private extension AppDefaults {
|
|||||||
|
|
||||||
static var firstRunDate: Date? {
|
static var firstRunDate: Date? {
|
||||||
get {
|
get {
|
||||||
return date(for: Key.firstRunDate)
|
return date(for: AppDefaultsKey.firstRunDate)
|
||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
setDate(for: Key.firstRunDate, newValue)
|
setDate(for: AppDefaultsKey.firstRunDate, newValue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user