Merge pull request #845 from omnivore-app/fix/high-contrast-initial-value
This commit is contained in:
@ -139,6 +139,16 @@ import WebKit
|
||||
|
||||
func loadContent(webView: WKWebView) {
|
||||
let fontFamilyValue = UserDefaults.standard.string(forKey: UserDefaultKey.preferredWebFont.rawValue)
|
||||
|
||||
let prefersHighContrastText: Bool = {
|
||||
let key = UserDefaultKey.prefersHighContrastWebFont.rawValue
|
||||
if UserDefaults.standard.object(forKey: key) != nil {
|
||||
return UserDefaults.standard.bool(forKey: key)
|
||||
} else {
|
||||
return true
|
||||
}
|
||||
}()
|
||||
|
||||
let fontFamily = fontFamilyValue.flatMap { WebFont(rawValue: $0) } ?? .inter
|
||||
|
||||
webView.loadHTMLString(
|
||||
@ -149,7 +159,8 @@ import WebKit
|
||||
fontSize: fontSize(),
|
||||
lineHeight: lineHeight(),
|
||||
maxWidthPercentage: maxWidthPercentage(),
|
||||
fontFamily: fontFamily
|
||||
fontFamily: fontFamily,
|
||||
prefersHighContrastText: prefersHighContrastText
|
||||
)
|
||||
.styledContent,
|
||||
baseURL: ViewsPackage.bundleURL
|
||||
|
||||
@ -11,6 +11,7 @@ struct WebReaderContent {
|
||||
let themeKey: String
|
||||
let fontFamily: WebFont
|
||||
let articleContent: ArticleContent
|
||||
let prefersHighContrastText: Bool
|
||||
|
||||
init(
|
||||
item: LinkedItem,
|
||||
@ -19,7 +20,8 @@ struct WebReaderContent {
|
||||
fontSize: Int,
|
||||
lineHeight: Int,
|
||||
maxWidthPercentage: Int,
|
||||
fontFamily: WebFont
|
||||
fontFamily: WebFont,
|
||||
prefersHighContrastText: Bool
|
||||
) {
|
||||
self.textFontSize = fontSize
|
||||
self.lineHeight = lineHeight
|
||||
@ -28,6 +30,7 @@ struct WebReaderContent {
|
||||
self.themeKey = isDark ? "Gray" : "LightGray"
|
||||
self.fontFamily = fontFamily
|
||||
self.articleContent = articleContent
|
||||
self.prefersHighContrastText = prefersHighContrastText
|
||||
}
|
||||
|
||||
// swiftlint:disable line_length
|
||||
@ -82,6 +85,7 @@ struct WebReaderContent {
|
||||
window.maxWidthPercentage = \(maxWidthPercentage)
|
||||
window.lineHeight = \(lineHeight)
|
||||
window.localStorage.setItem("theme", "\(themeKey)")
|
||||
window.prefersHighContrastFont = \(prefersHighContrastText)
|
||||
</script>
|
||||
<script src="bundle.js"></script>
|
||||
<script src="mathJaxConfiguration.js" id="MathJax-script"></script>
|
||||
|
||||
@ -129,7 +129,7 @@ public enum WebViewManager {
|
||||
}
|
||||
|
||||
func fontSize() -> Int {
|
||||
let storedSize = UserDefaults.standard.integer(forKey: "preferredWebFontSize")
|
||||
let storedSize = UserDefaults.standard.integer(forKey: UserDefaultKey.preferredWebFontSize.rawValue)
|
||||
return storedSize <= 1 ? Int(NSFont.userFont(ofSize: 16)?.pointSize ?? 16) : storedSize
|
||||
}
|
||||
|
||||
|
||||
@ -42,7 +42,7 @@ public struct WebPreferencesPopoverView: View {
|
||||
@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 = false
|
||||
@AppStorage(UserDefaultKey.prefersHighContrastWebFont.rawValue) var prefersHighContrastText = true
|
||||
|
||||
public init(
|
||||
updateFontFamilyAction: @escaping () -> Void,
|
||||
|
||||
File diff suppressed because one or more lines are too long
@ -44,6 +44,7 @@ const App = () => {
|
||||
margin={window.margin}
|
||||
maxWidthPercentage={window.maxWidthPercentage}
|
||||
lineHeight={window.lineHeight}
|
||||
highContrastFont={window.prefersHighContrastFont ?? true}
|
||||
articleMutations={{
|
||||
createHighlightMutation: (input) =>
|
||||
mutation('createHighlight', input),
|
||||
|
||||
Reference in New Issue
Block a user