Skip to content

Commit

Permalink
fix(encrypt): improved error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
mhamann committed Aug 25, 2022
1 parent 1b93af4 commit c842143
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
6 changes: 5 additions & 1 deletion Sources/Rownd/Views/KeyTransfer/KeyScanner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import CodeScanner

struct KeyScannerView: View {
var receiveKeyTransfer: (_ url: String) -> Void
var parentViewController: UIViewController
@State private var isPresentingScanner = true
@State private var scannedCode: String?
@State private var isTransferringKey = false
Expand Down Expand Up @@ -60,7 +61,10 @@ struct KeyScannerView: View {
Spacer()
}

NavigationLink(destination: KeyTransferProgress(isShowingProgressView: $isTransferringKey), isActive: $isTransferringKey) { EmptyView() }
NavigationLink(destination: KeyTransferProgress(
parentViewController: parentViewController,
isShowingProgressView: $isTransferringKey
), isActive: $isTransferringKey) { EmptyView() }

}
.padding(.horizontal)
Expand Down
9 changes: 9 additions & 0 deletions Sources/Rownd/Views/KeyTransfer/KeyTransferProgress.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import SwiftUI
struct KeyTransferProgress: View {
@Environment(\.presentationMode) var presentationMode
@EnvironmentObject var keyState: KeyTransferViewState
var parentViewController: UIViewController

@Binding var isShowingProgressView: Bool

Expand Down Expand Up @@ -94,6 +95,14 @@ struct KeyTransferProgress: View {
.frame(minWidth: 0, maxWidth: .infinity)
Spacer()
}

Button(action: {
parentViewController.dismiss(animated: true)
}, label: {
Text("Finish")
.frame(minWidth: 0, maxWidth: .infinity)
})
.modifier(RowndButton())
}.frame(maxHeight: .infinity)
}
}
Expand Down
16 changes: 10 additions & 6 deletions Sources/Rownd/Views/KeyTransfer/KeyTransferView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct KeyTransferView : View {

@Environment(\.presentationMode) var presentationMode

var parentViewController: UIViewController?
var parentViewController: UIViewController
var setupKeyTransfer: () -> Void
var receiveKeyTransfer: (_ url: String) -> Void

Expand All @@ -38,7 +38,7 @@ struct KeyTransferView : View {
Button(action: {
self.setupKeyTransfer()
activeNavSelection = "key-code"
parentViewController?.bottomSheetController?.grow(toMaximumHeight: true)
parentViewController.bottomSheetController?.grow(toMaximumHeight: true)
}, label: {
Text("Show encrpytion key")
.frame(minWidth: 0, maxWidth: .infinity)
Expand All @@ -53,12 +53,12 @@ struct KeyTransferView : View {
switch AVCaptureDevice.authorizationStatus(for: .video) {
case .authorized:
activeNavSelection = "key-scanner"
parentViewController?.bottomSheetController?.grow(toMaximumHeight: true)
parentViewController.bottomSheetController?.grow(toMaximumHeight: true)
case .notDetermined:
AVCaptureDevice.requestAccess(for: .video) { granted in
if granted {
activeNavSelection = "key-scanner"
parentViewController?.bottomSheetController?.grow(toMaximumHeight: true)
parentViewController.bottomSheetController?.grow(toMaximumHeight: true)
}
}
case .denied:
Expand Down Expand Up @@ -88,7 +88,10 @@ struct KeyTransferView : View {
dismissButton: .default(Text("OK"))
)
}
NavigationLink(destination: KeyScannerView(receiveKeyTransfer: receiveKeyTransfer), tag: "key-scanner", selection: $activeNavSelection) { EmptyView() }
NavigationLink(destination: KeyScannerView(
receiveKeyTransfer: receiveKeyTransfer,
parentViewController: parentViewController
), tag: "key-scanner", selection: $activeNavSelection) { EmptyView() }
NavigationLink(destination: KeyCodeView(), tag: "key-code", selection: $activeNavSelection) { EmptyView() }

Spacer()
Expand Down Expand Up @@ -139,7 +142,8 @@ struct RowndButton: ViewModifier {

struct KeyTransferView_Previews: PreviewProvider {
static var previews: some View {
KeyTransferView(setupKeyTransfer: {
KeyTransferView(parentViewController: KeyTransferViewController(),
setupKeyTransfer: {
return
}, receiveKeyTransfer: { url in
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class KeyTransferViewController : UIViewController {

private func receiveKeyTransfer(_ url: String) {
keyState.isReceivingKey = true
keyState.operationError = nil

Task {
let url = URL(string: url)
Expand Down

0 comments on commit c842143

Please sign in to comment.