Compare commits

..

2 Commits

Author SHA1 Message Date
Christoph Hagen
e4f93d94a9 Attempt to fix history item bug on WatchOS 2023-12-29 22:52:04 +01:00
Christoph Hagen
973f0cb1c1 Attempt to quit app when launched from complication 2023-12-29 22:18:41 +01:00
5 changed files with 29 additions and 73 deletions

View File

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

View File

@ -8,7 +8,7 @@
/* Begin PBXBuildFile section */
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 */; };
884A45C5279F4BBE00D6E650 /* KeyManagement.swift in Sources */ = {isa = PBXBuildFile; fileRef = 884A45C4279F4BBE00D6E650 /* KeyManagement.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 */; };
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 */; };
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 */; };
88E197C429EDCC8900BF1D19 /* 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 */
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>"; };
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>"; };
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>"; };
@ -159,7 +159,7 @@
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; };
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>"; };
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>"; };
@ -257,7 +257,7 @@
E2C5C1D92806FE4A00769EF6 /* API */,
8860D7442B2328B800849FAC /* API Extensions */,
884A45B6279F48C100D6E650 /* SesameApp.swift */,
884A45B8279F48C100D6E650 /* ContentView.swift */,
884A45B8279F48C100D6E650 /* MainView.swift */,
E28DED2C281E840B00259690 /* SettingsView.swift */,
E28DED2E281E8A0500259690 /* SingleKeyView.swift */,
E25317542A8A1A07005A537D /* History */,
@ -308,7 +308,7 @@
88E197B529EDC9BD00BF1D19 /* Assets.xcassets */,
E24065562A819AAD009C1AD8 /* Settings */,
88E197B129EDC9BC00BF1D19 /* Sesame_WatchApp.swift */,
88E197B329EDC9BC00BF1D19 /* ContentView.swift */,
88E197B329EDC9BC00BF1D19 /* UnlockView.swift */,
888362332A80F3F90032BBB2 /* SettingsView.swift */,
888362352A80F4420032BBB2 /* HistoryView.swift */,
E240655D2A822E97009C1AD8 /* HistoryListRow.swift */,
@ -548,7 +548,7 @@
buildActionMask = 2147483647;
files = (
884A45CF27A5402D00D6E650 /* MessageResult.swift in Sources */,
884A45B9279F48C100D6E650 /* ContentView.swift in Sources */,
884A45B9279F48C100D6E650 /* MainView.swift in Sources */,
88AEE3882B226FED0034EDA9 /* MessageResult+UI.swift in Sources */,
E28DED2F281E8A0500259690 /* SingleKeyView.swift in Sources */,
888A11332B32DBBB0099A12B /* UInt8+Extensions.swift in Sources */,
@ -594,7 +594,7 @@
8860D7662B23B5B200849FAC /* RequestCoordinator.swift in Sources */,
8860D75D2B237FC000849FAC /* Data+Coding.swift in Sources */,
888362342A80F3F90032BBB2 /* SettingsView.swift in Sources */,
88E197B429EDC9BC00BF1D19 /* ContentView.swift in Sources */,
88E197B429EDC9BC00BF1D19 /* UnlockView.swift in Sources */,
E2F5DCCB2A88E976002858B9 /* Array+Extensions.swift in Sources */,
E24065532A819614009C1AD8 /* SettingsNumberItemLink.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 {
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

@ -6,7 +6,11 @@ final class HistoryItem {
let startDate: Date
let message: HistoryMessage
let messageData: Data
var message: Message {
try! .init(decodeFrom: messageData)
}
let route: TransmissionType
@ -14,11 +18,7 @@ final class HistoryItem {
init(message: Message, startDate: Date, route: TransmissionType, finishDate: Date) {
self.startDate = startDate
self.message = .init(
messageType: message.messageType,
clientChallenge: Int(message.clientChallenge),
serverChallenge: Int(message.serverChallenge),
result: message.result)
self.messageData = message.encoded
self.finishDate = finishDate
self.route = route
}
@ -32,59 +32,6 @@ final class HistoryItem {
}
}
struct HistoryMessage {
/// The type of message being sent.
let messageType: MessageType
/**
* The random nonce created by the remote
*
* This nonce is a random number created by the remote, different for each unlock request.
* It is set for all message types.
*/
let clientChallenge: Int
/**
* A random number to sign by the remote
*
* This nonce is set by the server after receiving an initial message.
* It is set for the message types `challenge`, `request`, and `response`.
*/
let serverChallenge: Int
/**
* The response status for the previous message.
*
* It is set only for messages from the server, e.g. the `challenge` and `response` message types.
* Must be set to `MessageAccepted` for other messages.
*/
let result: MessageResult
}
extension HistoryMessage: Encodable {
func encode(to encoder: Encoder) throws {
var container = encoder.unkeyedContainer()
try container.encode(messageType)
try container.encode(clientChallenge)
try container.encode(serverChallenge)
try container.encode(result)
}
}
extension HistoryMessage: Decodable {
init(from decoder: Decoder) throws {
var container = try decoder.unkeyedContainer()
self.messageType = try container.decode(MessageType.self)
self.clientChallenge = try container.decode(Int.self)
self.serverChallenge = try container.decode(Int.self)
self.result = try container.decode(MessageResult.self)
}
}
extension HistoryItem: Identifiable {
var id: Double {

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()
}
}