Skip to content

Commit 11bd149

Browse files
committed
Misc polish
1 parent b78aded commit 11bd149

File tree

1 file changed

+33
-31
lines changed

1 file changed

+33
-31
lines changed

YubiKit/YubiKit/NFCConnection.swift

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -170,40 +170,42 @@ private final actor NFCConnectionManager: NSObject {
170170
private var _currentState = State.inactive
171171
private var currentState: State {
172172
get { _currentState }
173-
set { set(state: newValue) }
173+
set {
174+
trace(message: "State: \(currentState)\(newValue)")
175+
176+
defer { _currentState = newValue }
177+
178+
switch (currentState, newValue) {
179+
180+
// Jump to 'connected'
181+
case (.inactive, let .connected(_, newTag)):
182+
connection = connection ?? .init()
183+
didCloseConnection = nil
184+
fallthrough
185+
case (.scanning, let .connected(_, newTag)):
186+
didCloseConnection = .init()
187+
Task { await connection!.fulfill(.init(tag: ISO7816Identifier(newTag.identifier))) }
188+
189+
// Jump to 'scanning'
190+
case (_, .scanning):
191+
connection = connection ?? .init()
192+
didCloseConnection = nil
193+
194+
// Jump to 'inactive'
195+
case (.connected, .inactive):
196+
fallthrough
197+
case (.scanning, .inactive):
198+
connection = nil
199+
didCloseConnection = nil
200+
201+
default:
202+
return
203+
}
204+
}
174205
}
175206

176207
private func set(state newValue: State) {
177-
trace(message: "State: \(currentState)\(newValue)")
178-
179-
defer { _currentState = newValue }
180-
181-
switch (currentState, newValue) {
182-
183-
// Jump to 'connected'
184-
case (.inactive, let .connected(_, newTag)):
185-
connection = connection ?? .init()
186-
didCloseConnection = nil
187-
fallthrough
188-
case (.scanning, let .connected(_, newTag)):
189-
didCloseConnection = .init()
190-
Task { await connection!.fulfill(.init(tag: ISO7816Identifier(newTag.identifier))) }
191-
192-
// Jump to 'scanning'
193-
case (_, .scanning):
194-
connection = connection ?? .init()
195-
didCloseConnection = nil
196-
197-
// Jump to 'inactive'
198-
case (.connected, .inactive):
199-
fallthrough
200-
case (.scanning, .inactive):
201-
connection = nil
202-
didCloseConnection = nil
203-
204-
default:
205-
return
206-
}
208+
currentState = newValue
207209
}
208210

209211
// @TraceScope

0 commit comments

Comments
 (0)