Attempt to quit app when launched from complication

This commit is contained in:
Christoph Hagen
2023-12-29 22:18:41 +01:00
parent e9d870bd12
commit 973f0cb1c1
4 changed files with 23 additions and 14 deletions

View File

@ -58,13 +58,16 @@ final class RequestCoordinator: ObservableObject {
}
}
func startUnlock() {
func startUnlock(quitAfterSuccess: Bool = false) {
guard !isPerformingRequest else {
return
}
isPerformingRequest = true
Task {
let finalResult = await performFullChallengeResponse()
if finalResult == .unlocked, quitAfterSuccess {
exit(EXIT_SUCCESS)
}
DispatchQueue.main.async {
self.state = finalResult
self.isPerformingRequest = false

View File

@ -40,9 +40,8 @@ struct ContentView: View {
.background(.white.opacity(0.2))
.cornerRadius(smallButtonSize / 2)
.font(.title2)
}
Button("Unlock", action: coordinator.startUnlock)
Button("Unlock", action: unlock)
.frame(width: unlockButtonSize, height: unlockButtonSize)
.background(buttonBackground)
.cornerRadius(unlockButtonSize / 2)
@ -82,7 +81,9 @@ struct ContentView: View {
.preferredColorScheme(.dark)
}
private func unlock() {
coordinator.startUnlock()
}
}