Skip to content

Commit

Permalink
Add a delay to SettingsChecker
Browse files Browse the repository at this point in the history
  • Loading branch information
tekezo committed Sep 28, 2024
1 parent 9cd4be1 commit 70a9b45
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/apps/SettingsWindow/src/SettingsChecker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,22 @@ final class SettingsChecker: ObservableObject {
private var subscribers: Set<AnyCancellable> = []

public func start() {
settings.$virtualHIDKeyboardKeyboardTypeV2.sink { [weak self] newValue in
self?.checkVirtualHIDKeyboardKeyboardTypeV2(newValue)
settings.$virtualHIDKeyboardKeyboardTypeV2.sink { [weak self] _ in
Task { @MainActor in
// Add a delay to prevent the alert from briefly appearing at startup.
do {
try await Task.sleep(nanoseconds: 100 * NSEC_PER_MSEC)
} catch {
print(error.localizedDescription)
}

self?.check()
}
}.store(in: &subscribers)
}

private func checkVirtualHIDKeyboardKeyboardTypeV2(_ virtualHIDKeyboardKeyboardTypeV2: String) {
keyboardTypeEmpty = (virtualHIDKeyboardKeyboardTypeV2 == "")
private func check() {
keyboardTypeEmpty = (settings.virtualHIDKeyboardKeyboardTypeV2 == "")
updateShowSettingsAlert()
}

Expand Down

0 comments on commit 70a9b45

Please sign in to comment.