Skip to content

Commit

Permalink
Add SettingsAlertView
Browse files Browse the repository at this point in the history
  • Loading branch information
tekezo committed Sep 28, 2024
1 parent bfd4d96 commit 27e7501
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/apps/SettingsWindow/src/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
1 change: 1 addition & 0 deletions src/apps/SettingsWindow/src/ContentViewStates.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 30 additions & 0 deletions src/apps/SettingsWindow/src/SettingsChecker.swift
Original file line number Diff line number Diff line change
@@ -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<AnyCancellable> = []

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
}
}
}
4 changes: 4 additions & 0 deletions src/apps/SettingsWindow/src/View/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ struct ContentView: View {
OverlayAlertView {
DriverNotActivatedAlertView()
}
} else if contentViewStates.showSettingsAlert {
OverlayAlertView {
SettingsAlertView()
}
}
}
.frame(
Expand Down
24 changes: 24 additions & 0 deletions src/apps/SettingsWindow/src/View/KeyboardTypeSelector.swift
Original file line number Diff line number Diff line change
@@ -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()
}
}
42 changes: 42 additions & 0 deletions src/apps/SettingsWindow/src/View/SettingsAlertView.swift
Original file line number Diff line number Diff line change
@@ -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)
}
}
}
11 changes: 1 addition & 10 deletions src/apps/SettingsWindow/src/View/VirtualKeyboardView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 27e7501

Please sign in to comment.