Skip to content

Commit d1b57b6

Browse files
committed
Use Task.yield()
1 parent f2de0c1 commit d1b57b6

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed
Binary file not shown.

Sentinel/Utilities/Gatekeeper.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,19 +68,20 @@ func CmdRunSudo(cmd: String, type: gkType, appState: AppState) {
6868

6969
func updateGatekeeperUI(appState: AppState) {
7070
Task {
71-
// Get status without side effects
71+
// Get current Gatekeeper status
7272
let isEnabled = await getGatekeeperStatus()
7373

74+
// Phase 1: disable handler and sync toggle
7475
await MainActor.run {
7576
appState.hasInitializedGatekeeperState = false
76-
// Sync both the actual state and the UI toggle
7777
appState.isGatekeeperEnabledState = isEnabled
7878
appState.isGatekeeperEnabled = isEnabled
7979
}
8080

81-
// Give SwiftUI a chance to process the toggle change before re-enabling
82-
try? await Task.sleep(nanoseconds: 1_000_000)
81+
// Yield to let SwiftUI process the toggle change while handler is off
82+
await Task.yield()
8383

84+
// Phase 2: re-enable handler and update status
8485
await MainActor.run {
8586
appState.hasInitializedGatekeeperState = true
8687
appState.status = isEnabled ? "Gatekeeper is enabled" : "Gatekeeper is disabled"

0 commit comments

Comments
 (0)