From 24032eaae395700e71b28629e62f79fd140b0db2 Mon Sep 17 00:00:00 2001 From: Satindar Dhillon Date: Sun, 3 Jul 2022 13:12:55 -0700 Subject: [PATCH] add mac commands menu file --- .../Sources/App/MacMenuCommands.swift | 90 +++++++++++++++++++ .../Sources/App/Views/WelcomeView.swift | 3 + .../Views/FontSizeAdjustmentPopoverView.swift | 2 +- apple/Sources/MainApp.swift | 3 + 4 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 apple/OmnivoreKit/Sources/App/MacMenuCommands.swift diff --git a/apple/OmnivoreKit/Sources/App/MacMenuCommands.swift b/apple/OmnivoreKit/Sources/App/MacMenuCommands.swift new file mode 100644 index 000000000..2ad723125 --- /dev/null +++ b/apple/OmnivoreKit/Sources/App/MacMenuCommands.swift @@ -0,0 +1,90 @@ +import SwiftUI +import Utils +import Views + +#if os(macOS) + public struct MacMenuCommands: Commands { + @AppStorage(UserDefaultKey.preferredWebFontSize.rawValue) var storedFontSize = Int( + NSFont.userFont(ofSize: 16)?.pointSize ?? 16 + ) + @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 + + public var fontSizeButtons: some View { + Group { + Button( + action: { storedFontSize = min(storedFontSize + 2, 28) }, + label: { Text("Increase Reader Font Size") } + ) + + Button( + action: { storedFontSize = max(storedFontSize - 2, 10) }, + label: { Text("Decrease Reader Font Size") + } + ) + } + } + + public var marginSizeButtons: some View { + Group { + Button( + action: { storedMaxWidthPercentage = max(storedMaxWidthPercentage - 10, 40) }, + label: { Text("Increase Reader Margin") + } + ) + + Button( + action: { storedMaxWidthPercentage = min(storedMaxWidthPercentage + 10, 100) }, + label: { Text("Decrease Reader Margin") + } + ) + } + } + + public var lineSpacingButtons: some View { + Group { + Button( + action: { storedLineSpacing = min(storedLineSpacing + 25, 300) }, + label: { Text("Increase Reader Line Spacing") } + ) + + Button( + action: { storedLineSpacing = max(storedLineSpacing - 25, 100) }, + label: { Text("Decrease Reader Line Spacing") } + ) +// .keyboardShortcut("l") + } + } + + public init() {} + + public var body: some Commands { + CommandMenu("Reader Settings") { + fontSizeButtons + + Divider() + + marginSizeButtons + + Divider() + + lineSpacingButtons + + Divider() + + Picker(selection: $preferredFont, label: Text("Font Family")) { + ForEach(WebFont.allCases, id: \.self) { font in + Text(font.displayValue).tag(font.rawValue) + } + } + + Toggle( + isOn: $prefersHighContrastText, + label: { Text("High Contrast Text") } + ) + } + } + } +#endif diff --git a/apple/OmnivoreKit/Sources/App/Views/WelcomeView.swift b/apple/OmnivoreKit/Sources/App/Views/WelcomeView.swift index 7ba4f8307..6905cd969 100644 --- a/apple/OmnivoreKit/Sources/App/Views/WelcomeView.swift +++ b/apple/OmnivoreKit/Sources/App/Views/WelcomeView.swift @@ -52,6 +52,9 @@ struct WelcomeView: View { } ) .foregroundColor(.appGrayTextContrast) + #if os(macOS) + .buttonStyle(PlainButtonStyle()) + #endif } } diff --git a/apple/OmnivoreKit/Sources/Views/FontSizeAdjustmentPopoverView.swift b/apple/OmnivoreKit/Sources/Views/FontSizeAdjustmentPopoverView.swift index 164c3fcfe..bca934802 100644 --- a/apple/OmnivoreKit/Sources/Views/FontSizeAdjustmentPopoverView.swift +++ b/apple/OmnivoreKit/Sources/Views/FontSizeAdjustmentPopoverView.swift @@ -12,7 +12,7 @@ public enum WebFont: String, CaseIterable { case sourceserifpro = "Source Serif Pro" case openDyslexic = "OpenDyslexic" - var displayValue: String { + public var displayValue: String { switch self { case .inter, .merriweather, .lora, .opensans, .roboto, .crimsontext, .sourceserifpro: return rawValue diff --git a/apple/Sources/MainApp.swift b/apple/Sources/MainApp.swift index 909a6be02..5635335b8 100644 --- a/apple/Sources/MainApp.swift +++ b/apple/Sources/MainApp.swift @@ -33,6 +33,9 @@ struct MainApp: App { WindowGroup { RootView(intercomProvider: nil) } + .commands { + MacMenuCommands() + } #endif } }