Register AppDefaults. Issue

This commit is contained in:
Maurice Parker 2020-07-03 01:24:35 -05:00
parent 782ae1c5cd
commit 88d03586ae
6 changed files with 29 additions and 14 deletions

@ -55,11 +55,11 @@ final class AppDefaults: ObservableObject {
static let addWebFeedAccountID = "addWebFeedAccountID" static let addWebFeedAccountID = "addWebFeedAccountID"
static let addWebFeedFolderName = "addWebFeedFolderName" static let addWebFeedFolderName = "addWebFeedFolderName"
static let addFolderAccountID = "addFolderAccountID" static let addFolderAccountID = "addFolderAccountID"
static let timelineSortDirection = "timelineSortDirection"
static let userInterfaceColorPalette = "userInterfaceColorPalette" static let userInterfaceColorPalette = "userInterfaceColorPalette"
static let timelineSortDirection = "timelineSortDirection"
static let timelineGroupByFeed = "timelineGroupByFeed" static let timelineGroupByFeed = "timelineGroupByFeed"
static let timelineIconSize = "timelineIconSize" static let timelineIconDimensions = "timelineIconDimensions"
static let timelineNumberOfLines = "timelineNumberOfLines" static let timelineNumberOfLines = "timelineNumberOfLines"
// iOS Defaults // iOS Defaults
@ -178,7 +178,7 @@ final class AppDefaults: ObservableObject {
} }
} }
@AppStorage(wrappedValue: 40.0, Key.timelineIconSize, store: store) var timelineIconSize: Double { @AppStorage(wrappedValue: 40.0, Key.timelineIconDimensions, store: store) var timelineIconDimensions: Double {
didSet { didSet {
objectWillChange.send() objectWillChange.send()
} }
@ -266,6 +266,21 @@ final class AppDefaults: ObservableObject {
objectWillChange.send() objectWillChange.send()
} }
} }
static func registerDefaults() {
let defaults: [String : Any] = [Key.userInterfaceColorPalette: UserInterfaceColorPalette.automatic.rawValue,
Key.timelineGroupByFeed: false,
Key.refreshClearsReadArticles: false,
Key.timelineNumberOfLines: 2,
Key.timelineIconDimensions: 40,
Key.timelineSortDirection: ComparisonResult.orderedDescending.rawValue,
Key.articleFullscreenAvailable: false,
Key.articleFullscreenEnabled: false,
Key.confirmMarkAllAsRead: true,
"NSScrollViewShouldScrollUnderTitlebar": false,
Key.refreshInterval: RefreshInterval.everyHour.rawValue]
AppDefaults.store.register(defaults: defaults)
}
} }

@ -21,7 +21,7 @@ struct TimelineItemView: View {
TimelineItemStatusView(status: timelineItem.status) TimelineItemStatusView(status: timelineItem.status)
if let image = articleIconImageLoader.image { if let image = articleIconImageLoader.image {
IconImageView(iconImage: image) IconImageView(iconImage: image)
.frame(width: CGFloat(defaults.timelineIconSize), height: CGFloat(defaults.timelineIconSize), alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/) .frame(width: CGFloat(defaults.timelineIconDimensions), height: CGFloat(defaults.timelineIconDimensions), alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/)
} }
VStack { VStack {
Text(verbatim: timelineItem.article.title ?? "N/A") Text(verbatim: timelineItem.article.title ?? "N/A")

@ -71,7 +71,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
} }
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
//AppDefaults.registerDefaults() AppDefaults.registerDefaults()
let isFirstRun = AppDefaults.shared.isFirstRun() let isFirstRun = AppDefaults.shared.isFirstRun()
if isFirstRun { if isFirstRun {

@ -33,8 +33,8 @@ struct TimelineLayoutView: View {
} }
var iconSize: some View { var iconSize: some View {
Slider(value: $appSettings.timelineIconSize, in: 20...60, step: 10, minimumValueLabel: Text("Small"), maximumValueLabel: Text("Large"), label: { Slider(value: $appSettings.timelineIconDimensions, in: 20...60, step: 10, minimumValueLabel: Text("Small"), maximumValueLabel: Text("Large"), label: {
Text(String(appSettings.timelineIconSize)) Text(String(appSettings.timelineIconDimensions))
}) })
} }
@ -54,7 +54,7 @@ struct TimelineLayoutView: View {
Image(systemName: "paperplane.circle") Image(systemName: "paperplane.circle")
.resizable() .resizable()
.frame(width: CGFloat(appSettings.timelineIconSize), height: CGFloat(appSettings.timelineIconSize), alignment: .top) .frame(width: CGFloat(appSettings.timelineIconDimensions), height: CGFloat(appSettings.timelineIconDimensions), alignment: .top)
.foregroundColor(.accentColor) .foregroundColor(.accentColor)
VStack(alignment: .leading, spacing: 4) { VStack(alignment: .leading, spacing: 4) {

@ -133,7 +133,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCenterDele
} }
#endif #endif
//AppDefaults.registerDefaults() AppDefaults.registerDefaults()
let isFirstRun = AppDefaults.shared.isFirstRun() let isFirstRun = AppDefaults.shared.isFirstRun()
if isFirstRun { if isFirstRun {
os_log(.debug, log: log, "Is first run.") os_log(.debug, log: log, "Is first run.")

@ -45,7 +45,7 @@ final class AppDefaults {
static let timelineGroupByFeed = "timelineGroupByFeed" static let timelineGroupByFeed = "timelineGroupByFeed"
static let refreshClearsReadArticles = "refreshClearsReadArticles" static let refreshClearsReadArticles = "refreshClearsReadArticles"
static let timelineNumberOfLines = "timelineNumberOfLines" static let timelineNumberOfLines = "timelineNumberOfLines"
static let timelineIconSize = "timelineIconSize" static let timelineIconDimension = "timelineIconSize"
static let timelineSortDirection = "timelineSortDirection" static let timelineSortDirection = "timelineSortDirection"
static let articleFullscreenAvailable = "articleFullscreenAvailable" static let articleFullscreenAvailable = "articleFullscreenAvailable"
static let articleFullscreenEnabled = "articleFullscreenEnabled" static let articleFullscreenEnabled = "articleFullscreenEnabled"
@ -202,11 +202,11 @@ final class AppDefaults {
var timelineIconSize: IconSize { var timelineIconSize: IconSize {
get { get {
let rawValue = AppDefaults.store.integer(forKey: Key.timelineIconSize) let rawValue = AppDefaults.store.integer(forKey: Key.timelineIconDimension)
return IconSize(rawValue: rawValue) ?? IconSize.medium return IconSize(rawValue: rawValue) ?? IconSize.medium
} }
set { set {
AppDefaults.store.set(newValue.rawValue, forKey: Key.timelineIconSize) AppDefaults.store.set(newValue.rawValue, forKey: Key.timelineIconDimension)
} }
} }
@ -215,7 +215,7 @@ final class AppDefaults {
Key.timelineGroupByFeed: false, Key.timelineGroupByFeed: false,
Key.refreshClearsReadArticles: false, Key.refreshClearsReadArticles: false,
Key.timelineNumberOfLines: 2, Key.timelineNumberOfLines: 2,
Key.timelineIconSize: IconSize.medium.rawValue, Key.timelineIconDimension: IconSize.medium.rawValue,
Key.timelineSortDirection: ComparisonResult.orderedDescending.rawValue, Key.timelineSortDirection: ComparisonResult.orderedDescending.rawValue,
Key.articleFullscreenAvailable: false, Key.articleFullscreenAvailable: false,
Key.articleFullscreenEnabled: false, Key.articleFullscreenEnabled: false,