From 88d03586ae56792e99312d20a3f1f8d7f32b7921 Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Fri, 3 Jul 2020 01:24:35 -0500 Subject: [PATCH] Register AppDefaults. Issue #2190 --- Multiplatform/Shared/AppDefaults.swift | 23 +++++++++++++++---- .../Shared/Timeline/TimelineItemView.swift | 2 +- Multiplatform/iOS/AppDelegate.swift | 2 +- .../Submenus/TimelineLayoutView.swift | 6 ++--- Multiplatform/macOS/AppDelegate.swift | 2 +- iOS/AppDefaults.swift | 8 +++---- 6 files changed, 29 insertions(+), 14 deletions(-) diff --git a/Multiplatform/Shared/AppDefaults.swift b/Multiplatform/Shared/AppDefaults.swift index 9e96f843b..270841646 100644 --- a/Multiplatform/Shared/AppDefaults.swift +++ b/Multiplatform/Shared/AppDefaults.swift @@ -55,11 +55,11 @@ final class AppDefaults: ObservableObject { static let addWebFeedAccountID = "addWebFeedAccountID" static let addWebFeedFolderName = "addWebFeedFolderName" static let addFolderAccountID = "addFolderAccountID" - static let timelineSortDirection = "timelineSortDirection" - + static let userInterfaceColorPalette = "userInterfaceColorPalette" + static let timelineSortDirection = "timelineSortDirection" static let timelineGroupByFeed = "timelineGroupByFeed" - static let timelineIconSize = "timelineIconSize" + static let timelineIconDimensions = "timelineIconDimensions" static let timelineNumberOfLines = "timelineNumberOfLines" // 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 { objectWillChange.send() } @@ -266,6 +266,21 @@ final class AppDefaults: ObservableObject { 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) + } } diff --git a/Multiplatform/Shared/Timeline/TimelineItemView.swift b/Multiplatform/Shared/Timeline/TimelineItemView.swift index d4f4f172a..1e1a25ae8 100644 --- a/Multiplatform/Shared/Timeline/TimelineItemView.swift +++ b/Multiplatform/Shared/Timeline/TimelineItemView.swift @@ -21,7 +21,7 @@ struct TimelineItemView: View { TimelineItemStatusView(status: timelineItem.status) if let image = articleIconImageLoader.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 { Text(verbatim: timelineItem.article.title ?? "N/A") diff --git a/Multiplatform/iOS/AppDelegate.swift b/Multiplatform/iOS/AppDelegate.swift index 3df75f60d..b9d62d6c1 100644 --- a/Multiplatform/iOS/AppDelegate.swift +++ b/Multiplatform/iOS/AppDelegate.swift @@ -71,7 +71,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD } func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { - //AppDefaults.registerDefaults() + AppDefaults.registerDefaults() let isFirstRun = AppDefaults.shared.isFirstRun() if isFirstRun { diff --git a/Multiplatform/iOS/Settings/Submenus/TimelineLayoutView.swift b/Multiplatform/iOS/Settings/Submenus/TimelineLayoutView.swift index 2b064917c..679d65e4a 100644 --- a/Multiplatform/iOS/Settings/Submenus/TimelineLayoutView.swift +++ b/Multiplatform/iOS/Settings/Submenus/TimelineLayoutView.swift @@ -33,8 +33,8 @@ struct TimelineLayoutView: View { } var iconSize: some View { - Slider(value: $appSettings.timelineIconSize, in: 20...60, step: 10, minimumValueLabel: Text("Small"), maximumValueLabel: Text("Large"), label: { - Text(String(appSettings.timelineIconSize)) + Slider(value: $appSettings.timelineIconDimensions, in: 20...60, step: 10, minimumValueLabel: Text("Small"), maximumValueLabel: Text("Large"), label: { + Text(String(appSettings.timelineIconDimensions)) }) } @@ -54,7 +54,7 @@ struct TimelineLayoutView: View { Image(systemName: "paperplane.circle") .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) VStack(alignment: .leading, spacing: 4) { diff --git a/Multiplatform/macOS/AppDelegate.swift b/Multiplatform/macOS/AppDelegate.swift index e01a4f244..2ad541197 100644 --- a/Multiplatform/macOS/AppDelegate.swift +++ b/Multiplatform/macOS/AppDelegate.swift @@ -133,7 +133,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCenterDele } #endif - //AppDefaults.registerDefaults() + AppDefaults.registerDefaults() let isFirstRun = AppDefaults.shared.isFirstRun() if isFirstRun { os_log(.debug, log: log, "Is first run.") diff --git a/iOS/AppDefaults.swift b/iOS/AppDefaults.swift index a9ad904d0..d1e7ec909 100644 --- a/iOS/AppDefaults.swift +++ b/iOS/AppDefaults.swift @@ -45,7 +45,7 @@ final class AppDefaults { static let timelineGroupByFeed = "timelineGroupByFeed" static let refreshClearsReadArticles = "refreshClearsReadArticles" static let timelineNumberOfLines = "timelineNumberOfLines" - static let timelineIconSize = "timelineIconSize" + static let timelineIconDimension = "timelineIconSize" static let timelineSortDirection = "timelineSortDirection" static let articleFullscreenAvailable = "articleFullscreenAvailable" static let articleFullscreenEnabled = "articleFullscreenEnabled" @@ -202,11 +202,11 @@ final class AppDefaults { var timelineIconSize: IconSize { get { - let rawValue = AppDefaults.store.integer(forKey: Key.timelineIconSize) + let rawValue = AppDefaults.store.integer(forKey: Key.timelineIconDimension) return IconSize(rawValue: rawValue) ?? IconSize.medium } 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.refreshClearsReadArticles: false, Key.timelineNumberOfLines: 2, - Key.timelineIconSize: IconSize.medium.rawValue, + Key.timelineIconDimension: IconSize.medium.rawValue, Key.timelineSortDirection: ComparisonResult.orderedDescending.rawValue, Key.articleFullscreenAvailable: false, Key.articleFullscreenEnabled: false,