observe font change and contrast change in main app for macos

This commit is contained in:
Satindar Dhillon 2022-07-03 22:38:12 -07:00
parent 6b5f8b7443
commit f4706205b0
2 changed files with 24 additions and 13 deletions

View file

@ -9,8 +9,9 @@ import Views
)
@AppStorage(UserDefaultKey.preferredWebLineSpacing.rawValue) var storedLineSpacing = 150
@AppStorage(UserDefaultKey.preferredWebMaxWidthPercentage.rawValue) var storedMaxWidthPercentage = 100
@AppStorage(UserDefaultKey.preferredWebFont.rawValue) var preferredFont = WebFont.inter.rawValue
@AppStorage(UserDefaultKey.prefersHighContrastWebFont.rawValue) var prefersHighContrastText = true
@Binding var preferredFont: String
@Binding var prefersHighContrastText: Bool
public var fontSizeButtons: some View {
Group {
@ -76,7 +77,13 @@ import Views
}
}
public init() {}
public init(
preferredFont: Binding<String>,
prefersHighContrastText: Binding<Bool>
) {
self._preferredFont = preferredFont
self._prefersHighContrastText = prefersHighContrastText
}
public var body: some Commands {
CommandMenu("Reader Settings") {
@ -96,20 +103,12 @@ 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()
}
}
}
}

View file

@ -1,19 +1,22 @@
// swiftlint:disable weak_delegate
import App
import SwiftUI
import Utils
#if os(macOS)
import AppKit
import Views
#elseif os(iOS)
import Intercom
import UIKit
import Utils
#endif
@main
struct MainApp: App {
#if os(macOS)
@NSApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
@AppStorage(UserDefaultKey.preferredWebFont.rawValue) var preferredFont = WebFont.inter.rawValue
@AppStorage(UserDefaultKey.prefersHighContrastWebFont.rawValue) var prefersHighContrastText = true
#elseif os(iOS)
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
#endif
@ -34,7 +37,16 @@ struct MainApp: App {
RootView(intercomProvider: nil)
}
.commands {
MacMenuCommands()
MacMenuCommands(
preferredFont: $preferredFont,
prefersHighContrastText: $prefersHighContrastText
)
}
.onChange(of: preferredFont) { _ in
NSNotification.readerSettingsChanged()
}
.onChange(of: prefersHighContrastText) { _ in
NSNotification.readerSettingsChanged()
}
#endif
}