Skip to content

Commit

Permalink
Add connection error to reader attack
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyfreeman committed Nov 5, 2022
1 parent 5f429ed commit 19115bc
Show file tree
Hide file tree
Showing 24 changed files with 80 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import SwiftUI
import Peripheral

struct AttackConnectionError: View {
let fliperColor: FlipperColor

var instructions: [AttributedString] = {
[
"Check Bluetooth connection with Flipper",
"Make sure Flipper is Turned On",
"If Flipper doesn’t respond, reboot it and connect to " +
"the app via Bluetooth",
"Restart **Mfkey32 (Detect Reader)**"
]
.compactMap {
try? .init(
markdown: $0,
options: .init(
allowsExtendedAttributes: true,
interpretedSyntax: .full))
}
}()

var body: some View {
VStack(spacing: 18) {
Text("Flipper is not Connected")
.font(.system(size: 18, weight: .bold))

VStack(spacing: 26) {
Image(
fliperColor == .white
? "FlipperDeadWhite"
: "FlipperDeadBlack"
)
.resizable()
.aspectRatio(contentMode: .fit)
.padding(.leading, 10)
.padding(.trailing, 24)

VStack(alignment: .leading, spacing: 8) {
ForEach(instructions.indices, id: \.self) { index in
HStack(alignment: .top, spacing: 0) {
Text("\(index + 1). ")
Text(instructions[index])
.multilineTextAlignment(.leading)
}
}
.font(.system(size: 16))
.opacity(0.5)
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ struct ReaderAttackView: View {
switch viewModel.state {
case .noLog:
ReaderDataNotFound(fliperColor: viewModel.flipperColor)
case .noDevice:
AttackConnectionError(fliperColor: viewModel.flipperColor)
case .downloadingLog:
VStack(spacing: 18) {
Text("Calculation Started...")
Expand Down Expand Up @@ -133,7 +135,7 @@ struct ReaderAttackView: View {
}
}

if viewModel.state != .noLog {
if !viewModel.isError {
VStack(alignment: .leading, spacing: 32) {
CalculatedKeys(results: viewModel.results)
if viewModel.hasNewKeys {
Expand All @@ -159,15 +161,15 @@ struct ReaderAttackView: View {
Spacer()
}

if viewModel.attackInProgress || viewModel.state == .noLog {
if viewModel.state != .finished {
HStack {
Spacer()
Button {
viewModel.attackInProgress
viewModel.isAttackInProgress
? viewModel.showCancelAttack = true
: dismiss()
} label: {
Text(viewModel.state == .noLog ? "Close" : "Cancel")
Text(viewModel.isError ? "Close" : "Cancel")
.font(.system(size: 16, weight: .medium))
.padding(.horizontal, 8)
.tappableFrame()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,23 @@ class ReaderAttackViewModel: ObservableObject {
private let appState: AppState = .shared
private var disposeBag: DisposeBag = .init()

@Published var flipper: Flipper?
@Published var flipper: Flipper? {
didSet {
if flipper?.state != .connected {
state = .noDevice
}
}
}
var flipperColor: FlipperColor {
flipper?.color ?? .white
}

var attackInProgress: Bool {
!(state == .finished || state == .noLog)
var isAttackInProgress: Bool {
!isError && state != .finished
}

var isError: Bool {
state == .noLog || state == .noDevice
}

@Published var state: State = .downloadingLog
Expand Down Expand Up @@ -56,6 +66,7 @@ class ReaderAttackViewModel: ObservableObject {

enum State {
case noLog
case noDevice
case downloadingLog
case calculating
case checkingKeys
Expand Down
6 changes: 6 additions & 0 deletions Flipper/Shared/Assets.xcassets/Flipper/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}

0 comments on commit 19115bc

Please sign in to comment.