diff --git a/src/apps/SettingsWindow/src/AppDelegate.swift b/src/apps/SettingsWindow/src/AppDelegate.swift index 29b7562fe..e078c0b5f 100644 --- a/src/apps/SettingsWindow/src/AppDelegate.swift +++ b/src/apps/SettingsWindow/src/AppDelegate.swift @@ -59,6 +59,7 @@ public class AppDelegate: NSObject, NSApplicationDelegate { LibKrbn.GrabberClient.shared.start("") LibKrbn.Settings.shared.watch() ServicesMonitor.shared.start() + SettingsChecker.shared.start() StateJsonMonitor.shared.start() SystemPreferences.shared.start() diff --git a/src/apps/SettingsWindow/src/ContentViewStates.swift b/src/apps/SettingsWindow/src/ContentViewStates.swift index a32c34752..e6888d854 100644 --- a/src/apps/SettingsWindow/src/ContentViewStates.swift +++ b/src/apps/SettingsWindow/src/ContentViewStates.swift @@ -12,6 +12,7 @@ final class ContentViewStates: ObservableObject { @Published public var showDriverVersionMismatchedAlert = false @Published public var showInputMonitoringPermissionsAlert = false @Published public var showDoctorAlert = false + @Published public var showSettingsAlert = false // // ContentMainView diff --git a/src/apps/SettingsWindow/src/SettingsChecker.swift b/src/apps/SettingsWindow/src/SettingsChecker.swift new file mode 100644 index 000000000..428005f58 --- /dev/null +++ b/src/apps/SettingsWindow/src/SettingsChecker.swift @@ -0,0 +1,30 @@ +import Combine +import Foundation +import SwiftUI + +final class SettingsChecker: ObservableObject { + static let shared = SettingsChecker() + + @ObservedObject private var settings = LibKrbn.Settings.shared + @Published var keyboardTypeEmpty = false + private var subscribers: Set = [] + + public func start() { + settings.$virtualHIDKeyboardKeyboardTypeV2.sink { [weak self] newValue in + self?.checkVirtualHIDKeyboardKeyboardTypeV2(newValue) + }.store(in: &subscribers) + } + + private func checkVirtualHIDKeyboardKeyboardTypeV2(_ virtualHIDKeyboardKeyboardTypeV2: String) { + keyboardTypeEmpty = (virtualHIDKeyboardKeyboardTypeV2 == "") + updateShowSettingsAlert() + } + + private func updateShowSettingsAlert() { + if keyboardTypeEmpty { + ContentViewStates.shared.showSettingsAlert = true + } else { + ContentViewStates.shared.showSettingsAlert = false + } + } +} diff --git a/src/apps/SettingsWindow/src/View/ContentView.swift b/src/apps/SettingsWindow/src/View/ContentView.swift index 6eeef906b..3f0b18bf7 100644 --- a/src/apps/SettingsWindow/src/View/ContentView.swift +++ b/src/apps/SettingsWindow/src/View/ContentView.swift @@ -29,6 +29,10 @@ struct ContentView: View { OverlayAlertView { DriverNotActivatedAlertView() } + } else if contentViewStates.showSettingsAlert { + OverlayAlertView { + SettingsAlertView() + } } } .frame( diff --git a/src/apps/SettingsWindow/src/View/KeyboardTypeSelector.swift b/src/apps/SettingsWindow/src/View/KeyboardTypeSelector.swift new file mode 100644 index 000000000..f385bc120 --- /dev/null +++ b/src/apps/SettingsWindow/src/View/KeyboardTypeSelector.swift @@ -0,0 +1,24 @@ +import SwiftUI + +struct KeyboardTypeSelectorView: View { + @ObservedObject private var settings = LibKrbn.Settings.shared + @ObservedObject private var grabberClient = LibKrbn.GrabberClient.shared + + var body: some View { + Picker( + selection: $settings.virtualHIDKeyboardKeyboardTypeV2, label: Text("Keyboard type:") + ) { + Text("ANSI (North America, most of Asia and others)").tag("ansi") + Text("ISO (Europe, Latin America, Middle-East and others)").tag("iso") + Text("JIS (Japanese)").tag("jis") + } + .pickerStyle(RadioGroupPickerStyle()) + .disabled(!grabberClient.connected) + } +} + +struct KeyboardTypeSelectorView_Previews: PreviewProvider { + static var previews: some View { + KeyboardTypeSelectorView() + } +} diff --git a/src/apps/SettingsWindow/src/View/SettingsAlertView.swift b/src/apps/SettingsWindow/src/View/SettingsAlertView.swift new file mode 100644 index 000000000..03d860298 --- /dev/null +++ b/src/apps/SettingsWindow/src/View/SettingsAlertView.swift @@ -0,0 +1,42 @@ +import SwiftUI + +struct SettingsAlertView: View { + @ObservedObject private var settingsChecker = SettingsChecker.shared + @FocusState var focus: Bool + + var body: some View { + ZStack(alignment: .topLeading) { + VStack(alignment: .leading, spacing: 6.0) { + if settingsChecker.keyboardTypeEmpty { + VStack(alignment: .leading, spacing: 20.0) { + Label( + "Please select the keyboard type", + systemImage: "gearshape" + ) + .font(.system(size: 24)) + + KeyboardTypeSelectorView() + } + } + } + .padding() + .frame(width: 850) + + SheetCloseButton { + ContentViewStates.shared.showSettingsAlert = false + } + } + .onAppear { + focus = true + } + } +} + +struct SettingsAlertView_Previews: PreviewProvider { + static var previews: some View { + Group { + SettingsAlertView() + .previewLayout(.sizeThatFits) + } + } +} diff --git a/src/apps/SettingsWindow/src/View/VirtualKeyboardView.swift b/src/apps/SettingsWindow/src/View/VirtualKeyboardView.swift index 42e1e1369..c87d808af 100644 --- a/src/apps/SettingsWindow/src/View/VirtualKeyboardView.swift +++ b/src/apps/SettingsWindow/src/View/VirtualKeyboardView.swift @@ -2,22 +2,13 @@ import SwiftUI struct VirtualKeyboardView: View { @ObservedObject private var settings = LibKrbn.Settings.shared - @ObservedObject private var systemPreferences = SystemPreferences.shared @ObservedObject private var grabberClient = LibKrbn.GrabberClient.shared var body: some View { VStack(alignment: .leading, spacing: 24.0) { GroupBox(label: Text("Keyboard")) { VStack(alignment: .leading, spacing: 6.0) { - Picker( - selection: $settings.virtualHIDKeyboardKeyboardTypeV2, label: Text("Keyboard type:") - ) { - Text("ANSI (North America, most of Asia and others)").tag("ansi") - Text("ISO (Europe, Latin America, Middle-East and others)").tag("iso") - Text("JIS (Japanese)").tag("jis") - } - .pickerStyle(RadioGroupPickerStyle()) - .disabled(!grabberClient.connected) + KeyboardTypeSelectorView() } .padding(6.0) }