diff --git a/apple/OmnivoreKit/Sources/App/MacMenuCommands.swift b/apple/OmnivoreKit/Sources/App/MacMenuCommands.swift index 2ad723125..b6201c4dc 100644 --- a/apple/OmnivoreKit/Sources/App/MacMenuCommands.swift +++ b/apple/OmnivoreKit/Sources/App/MacMenuCommands.swift @@ -15,12 +15,18 @@ import Views public var fontSizeButtons: some View { Group { Button( - action: { storedFontSize = min(storedFontSize + 2, 28) }, + action: { + storedFontSize = min(storedFontSize + 2, 28) + NSNotification.readerSettingsChanged() + }, label: { Text("Increase Reader Font Size") } ) Button( - action: { storedFontSize = max(storedFontSize - 2, 10) }, + action: { + storedFontSize = max(storedFontSize - 2, 10) + NSNotification.readerSettingsChanged() + }, label: { Text("Decrease Reader Font Size") } ) @@ -30,13 +36,19 @@ import Views public var marginSizeButtons: some View { Group { Button( - action: { storedMaxWidthPercentage = max(storedMaxWidthPercentage - 10, 40) }, + action: { + storedMaxWidthPercentage = max(storedMaxWidthPercentage - 10, 40) + NSNotification.readerSettingsChanged() + }, label: { Text("Increase Reader Margin") } ) Button( - action: { storedMaxWidthPercentage = min(storedMaxWidthPercentage + 10, 100) }, + action: { + storedMaxWidthPercentage = min(storedMaxWidthPercentage + 10, 100) + NSNotification.readerSettingsChanged() + }, label: { Text("Decrease Reader Margin") } ) @@ -46,12 +58,18 @@ import Views public var lineSpacingButtons: some View { Group { Button( - action: { storedLineSpacing = min(storedLineSpacing + 25, 300) }, + action: { + storedLineSpacing = min(storedLineSpacing + 25, 300) + NSNotification.readerSettingsChanged() + }, label: { Text("Increase Reader Line Spacing") } ) Button( - action: { storedLineSpacing = max(storedLineSpacing - 25, 100) }, + action: { + storedLineSpacing = max(storedLineSpacing - 25, 100) + NSNotification.readerSettingsChanged() + }, label: { Text("Decrease Reader Line Spacing") } ) // .keyboardShortcut("l") @@ -78,12 +96,20 @@ import Views ForEach(WebFont.allCases, id: \.self) { font in Text(font.displayValue).tag(font.rawValue) } + // TODO: fix this since it doesn't work + .onChange(of: preferredFont) { _ in + NSNotification.readerSettingsChanged() + } } Toggle( isOn: $prefersHighContrastText, label: { Text("High Contrast Text") } ) + // TODO: fix this since it doesn't work + .onChange(of: prefersHighContrastText) { _ in + NSNotification.readerSettingsChanged() + } } } } diff --git a/apple/OmnivoreKit/Sources/App/Views/WebReader/WebReaderContainer.swift b/apple/OmnivoreKit/Sources/App/Views/WebReader/WebReaderContainer.swift index 084b30d8b..66284f89c 100644 --- a/apple/OmnivoreKit/Sources/App/Views/WebReader/WebReaderContainer.swift +++ b/apple/OmnivoreKit/Sources/App/Views/WebReader/WebReaderContainer.swift @@ -233,6 +233,10 @@ struct WebReaderContainerView: View { .formSheet(isPresented: $showPreferencesPopover, useSmallDetent: false) { webPreferencesPopoverView } + #else + .onReceive(NSNotification.readerSettingsChangedPublisher) { _ in + readerSettingsChangedTransactionID = UUID() + } #endif .onDisappear { // Clear the shared webview content when exiting diff --git a/apple/OmnivoreKit/Sources/Services/NSNotification+Operation.swift b/apple/OmnivoreKit/Sources/Services/NSNotification+Operation.swift index 0616e8375..fbcf2663c 100644 --- a/apple/OmnivoreKit/Sources/Services/NSNotification+Operation.swift +++ b/apple/OmnivoreKit/Sources/Services/NSNotification+Operation.swift @@ -1,10 +1,3 @@ -// -// NSNotification+Operation.swift -// -// -// Created by Jackson Harper on 1/31/22. -// - import Foundation import Models @@ -12,6 +5,7 @@ public extension NSNotification { static let PushJSONArticle = Notification.Name("PushJSONArticle") static let OperationSuccess = Notification.Name("OperationSuccess") static let OperationFailure = Notification.Name("OperationFailure") + static let ReaderSettingsChanged = Notification.Name("ReaderSettingsChanged") static var pushFeedItemPublisher: NotificationCenter.Publisher { NotificationCenter.default.publisher(for: PushJSONArticle) @@ -25,6 +19,10 @@ public extension NSNotification { NotificationCenter.default.publisher(for: OperationFailure) } + static var readerSettingsChangedPublisher: NotificationCenter.Publisher { + NotificationCenter.default.publisher(for: ReaderSettingsChanged) + } + internal var operationMessage: String? { if let message = userInfo?["message"] as? String { return message @@ -47,4 +45,8 @@ public extension NSNotification { static func operationFailed(message: String) { NotificationCenter.default.post(name: NSNotification.OperationFailure, object: nil, userInfo: ["message": message]) } + + static func readerSettingsChanged() { + NotificationCenter.default.post(name: NSNotification.ReaderSettingsChanged, object: nil) + } }