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

@ -2,6 +2,7 @@ import SwiftUI
import SwiftData import SwiftData
import SFSafeSymbols import SFSafeSymbols
import CryptoKit import CryptoKit
import UIKit
struct ContentView: View { struct ContentView: View {
@ -40,7 +41,7 @@ struct ContentView: View {
.aspectRatio(contentMode: .fit) .aspectRatio(contentMode: .fit)
.fontWeight(.ultraLight) .fontWeight(.ultraLight)
.padding() .padding()
.onTapGesture(perform: coordinator.startUnlock) .onTapGesture { unlock(quit: true) }
if coordinator.isPerformingRequest { if coordinator.isPerformingRequest {
ProgressView() ProgressView()
.progressViewStyle(CircularProgressViewStyle()) .progressViewStyle(CircularProgressViewStyle())
@ -58,10 +59,14 @@ struct ContentView: View {
guard launched else { guard launched else {
return return
} }
unlock(quit: true)
didLaunchFromComplication = false didLaunchFromComplication = false
coordinator.startUnlock()
} }
} }
private func unlock(quit: Bool) {
coordinator.startUnlock(quitAfterSuccess: quit)
}
} }
#Preview { #Preview {

View File

@ -8,7 +8,7 @@
/* Begin PBXBuildFile section */ /* Begin PBXBuildFile section */
884A45B7279F48C100D6E650 /* SesameApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 884A45B6279F48C100D6E650 /* SesameApp.swift */; }; 884A45B7279F48C100D6E650 /* SesameApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 884A45B6279F48C100D6E650 /* SesameApp.swift */; };
884A45B9279F48C100D6E650 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 884A45B8279F48C100D6E650 /* ContentView.swift */; }; 884A45B9279F48C100D6E650 /* MainView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 884A45B8279F48C100D6E650 /* MainView.swift */; };
884A45BB279F48C300D6E650 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 884A45BA279F48C300D6E650 /* Assets.xcassets */; }; 884A45BB279F48C300D6E650 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 884A45BA279F48C300D6E650 /* Assets.xcassets */; };
884A45C5279F4BBE00D6E650 /* KeyManagement.swift in Sources */ = {isa = PBXBuildFile; fileRef = 884A45C4279F4BBE00D6E650 /* KeyManagement.swift */; }; 884A45C5279F4BBE00D6E650 /* KeyManagement.swift in Sources */ = {isa = PBXBuildFile; fileRef = 884A45C4279F4BBE00D6E650 /* KeyManagement.swift */; };
884A45CB27A464C000D6E650 /* SymmetricKey+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 884A45CA27A464C000D6E650 /* SymmetricKey+Extensions.swift */; }; 884A45CB27A464C000D6E650 /* SymmetricKey+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 884A45CA27A464C000D6E650 /* SymmetricKey+Extensions.swift */; };
@ -54,7 +54,7 @@
88AEE3862B22376D0034EDA9 /* Message+Crypto.swift in Sources */ = {isa = PBXBuildFile; fileRef = 88AEE3852B22376D0034EDA9 /* Message+Crypto.swift */; }; 88AEE3862B22376D0034EDA9 /* Message+Crypto.swift in Sources */ = {isa = PBXBuildFile; fileRef = 88AEE3852B22376D0034EDA9 /* Message+Crypto.swift */; };
88AEE3882B226FED0034EDA9 /* MessageResult+UI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 88AEE3872B226FED0034EDA9 /* MessageResult+UI.swift */; }; 88AEE3882B226FED0034EDA9 /* MessageResult+UI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 88AEE3872B226FED0034EDA9 /* MessageResult+UI.swift */; };
88E197B229EDC9BC00BF1D19 /* Sesame_WatchApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 88E197B129EDC9BC00BF1D19 /* Sesame_WatchApp.swift */; }; 88E197B229EDC9BC00BF1D19 /* Sesame_WatchApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 88E197B129EDC9BC00BF1D19 /* Sesame_WatchApp.swift */; };
88E197B429EDC9BC00BF1D19 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 88E197B329EDC9BC00BF1D19 /* ContentView.swift */; }; 88E197B429EDC9BC00BF1D19 /* UnlockView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 88E197B329EDC9BC00BF1D19 /* UnlockView.swift */; };
88E197B629EDC9BD00BF1D19 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 88E197B529EDC9BD00BF1D19 /* Assets.xcassets */; }; 88E197B629EDC9BD00BF1D19 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 88E197B529EDC9BD00BF1D19 /* Assets.xcassets */; };
88E197C429EDCC8900BF1D19 /* Client.swift in Sources */ = {isa = PBXBuildFile; fileRef = 884A45CC27A465F500D6E650 /* Client.swift */; }; 88E197C429EDCC8900BF1D19 /* Client.swift in Sources */ = {isa = PBXBuildFile; fileRef = 884A45CC27A465F500D6E650 /* Client.swift */; };
88E197C729EDCCBD00BF1D19 /* Client.swift in Sources */ = {isa = PBXBuildFile; fileRef = 884A45CC27A465F500D6E650 /* Client.swift */; }; 88E197C729EDCCBD00BF1D19 /* Client.swift in Sources */ = {isa = PBXBuildFile; fileRef = 884A45CC27A465F500D6E650 /* Client.swift */; };
@ -131,7 +131,7 @@
/* Begin PBXFileReference section */ /* Begin PBXFileReference section */
884A45B3279F48C100D6E650 /* Sesame.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Sesame.app; sourceTree = BUILT_PRODUCTS_DIR; }; 884A45B3279F48C100D6E650 /* Sesame.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Sesame.app; sourceTree = BUILT_PRODUCTS_DIR; };
884A45B6279F48C100D6E650 /* SesameApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SesameApp.swift; sourceTree = "<group>"; }; 884A45B6279F48C100D6E650 /* SesameApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SesameApp.swift; sourceTree = "<group>"; };
884A45B8279F48C100D6E650 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; }; 884A45B8279F48C100D6E650 /* MainView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainView.swift; sourceTree = "<group>"; };
884A45BA279F48C300D6E650 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; }; 884A45BA279F48C300D6E650 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
884A45C4279F4BBE00D6E650 /* KeyManagement.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyManagement.swift; sourceTree = "<group>"; }; 884A45C4279F4BBE00D6E650 /* KeyManagement.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyManagement.swift; sourceTree = "<group>"; };
884A45CA27A464C000D6E650 /* SymmetricKey+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SymmetricKey+Extensions.swift"; sourceTree = "<group>"; }; 884A45CA27A464C000D6E650 /* SymmetricKey+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SymmetricKey+Extensions.swift"; sourceTree = "<group>"; };
@ -159,7 +159,7 @@
88AEE3872B226FED0034EDA9 /* MessageResult+UI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MessageResult+UI.swift"; sourceTree = "<group>"; }; 88AEE3872B226FED0034EDA9 /* MessageResult+UI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MessageResult+UI.swift"; sourceTree = "<group>"; };
88E197AC29EDC9BC00BF1D19 /* Sesame-Watch Watch App.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Sesame-Watch Watch App.app"; sourceTree = BUILT_PRODUCTS_DIR; }; 88E197AC29EDC9BC00BF1D19 /* Sesame-Watch Watch App.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Sesame-Watch Watch App.app"; sourceTree = BUILT_PRODUCTS_DIR; };
88E197B129EDC9BC00BF1D19 /* Sesame_WatchApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Sesame_WatchApp.swift; sourceTree = "<group>"; }; 88E197B129EDC9BC00BF1D19 /* Sesame_WatchApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Sesame_WatchApp.swift; sourceTree = "<group>"; };
88E197B329EDC9BC00BF1D19 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; }; 88E197B329EDC9BC00BF1D19 /* UnlockView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnlockView.swift; sourceTree = "<group>"; };
88E197B529EDC9BD00BF1D19 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; }; 88E197B529EDC9BD00BF1D19 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
88E197D629EDCFE800BF1D19 /* Date+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Date+Extensions.swift"; sourceTree = "<group>"; }; 88E197D629EDCFE800BF1D19 /* Date+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Date+Extensions.swift"; sourceTree = "<group>"; };
88E35EF42B3B0A9800485A66 /* App+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "App+Extensions.swift"; sourceTree = "<group>"; }; 88E35EF42B3B0A9800485A66 /* App+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "App+Extensions.swift"; sourceTree = "<group>"; };
@ -257,7 +257,7 @@
E2C5C1D92806FE4A00769EF6 /* API */, E2C5C1D92806FE4A00769EF6 /* API */,
8860D7442B2328B800849FAC /* API Extensions */, 8860D7442B2328B800849FAC /* API Extensions */,
884A45B6279F48C100D6E650 /* SesameApp.swift */, 884A45B6279F48C100D6E650 /* SesameApp.swift */,
884A45B8279F48C100D6E650 /* ContentView.swift */, 884A45B8279F48C100D6E650 /* MainView.swift */,
E28DED2C281E840B00259690 /* SettingsView.swift */, E28DED2C281E840B00259690 /* SettingsView.swift */,
E28DED2E281E8A0500259690 /* SingleKeyView.swift */, E28DED2E281E8A0500259690 /* SingleKeyView.swift */,
E25317542A8A1A07005A537D /* History */, E25317542A8A1A07005A537D /* History */,
@ -308,7 +308,7 @@
88E197B529EDC9BD00BF1D19 /* Assets.xcassets */, 88E197B529EDC9BD00BF1D19 /* Assets.xcassets */,
E24065562A819AAD009C1AD8 /* Settings */, E24065562A819AAD009C1AD8 /* Settings */,
88E197B129EDC9BC00BF1D19 /* Sesame_WatchApp.swift */, 88E197B129EDC9BC00BF1D19 /* Sesame_WatchApp.swift */,
88E197B329EDC9BC00BF1D19 /* ContentView.swift */, 88E197B329EDC9BC00BF1D19 /* UnlockView.swift */,
888362332A80F3F90032BBB2 /* SettingsView.swift */, 888362332A80F3F90032BBB2 /* SettingsView.swift */,
888362352A80F4420032BBB2 /* HistoryView.swift */, 888362352A80F4420032BBB2 /* HistoryView.swift */,
E240655D2A822E97009C1AD8 /* HistoryListRow.swift */, E240655D2A822E97009C1AD8 /* HistoryListRow.swift */,
@ -548,7 +548,7 @@
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
884A45CF27A5402D00D6E650 /* MessageResult.swift in Sources */, 884A45CF27A5402D00D6E650 /* MessageResult.swift in Sources */,
884A45B9279F48C100D6E650 /* ContentView.swift in Sources */, 884A45B9279F48C100D6E650 /* MainView.swift in Sources */,
88AEE3882B226FED0034EDA9 /* MessageResult+UI.swift in Sources */, 88AEE3882B226FED0034EDA9 /* MessageResult+UI.swift in Sources */,
E28DED2F281E8A0500259690 /* SingleKeyView.swift in Sources */, E28DED2F281E8A0500259690 /* SingleKeyView.swift in Sources */,
888A11332B32DBBB0099A12B /* UInt8+Extensions.swift in Sources */, 888A11332B32DBBB0099A12B /* UInt8+Extensions.swift in Sources */,
@ -594,7 +594,7 @@
8860D7662B23B5B200849FAC /* RequestCoordinator.swift in Sources */, 8860D7662B23B5B200849FAC /* RequestCoordinator.swift in Sources */,
8860D75D2B237FC000849FAC /* Data+Coding.swift in Sources */, 8860D75D2B237FC000849FAC /* Data+Coding.swift in Sources */,
888362342A80F3F90032BBB2 /* SettingsView.swift in Sources */, 888362342A80F3F90032BBB2 /* SettingsView.swift in Sources */,
88E197B429EDC9BC00BF1D19 /* ContentView.swift in Sources */, 88E197B429EDC9BC00BF1D19 /* UnlockView.swift in Sources */,
E2F5DCCB2A88E976002858B9 /* Array+Extensions.swift in Sources */, E2F5DCCB2A88E976002858B9 /* Array+Extensions.swift in Sources */,
E24065532A819614009C1AD8 /* SettingsNumberItemLink.swift in Sources */, E24065532A819614009C1AD8 /* SettingsNumberItemLink.swift in Sources */,
888362362A80F4420032BBB2 /* HistoryView.swift in Sources */, 888362362A80F4420032BBB2 /* HistoryView.swift in Sources */,

View File

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

View File

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