-
Notifications
You must be signed in to change notification settings - Fork 114
Prototype of using privacy screen and LocalAuthentication #219
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
4eda5c7
40ba192
3970da4
5c9d8a9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ | |
// | ||
|
||
import UIKit | ||
import LocalAuthentication | ||
|
||
class OpaqueNavigationController: UINavigationController { | ||
override func viewDidLoad() { | ||
|
@@ -52,6 +53,7 @@ class RootViewController: OpaqueNavigationController { | |
|
||
fileprivate var tokenListViewController: TokenListViewController | ||
fileprivate var modalNavController: UINavigationController? | ||
fileprivate var authController: UIViewController? | ||
|
||
fileprivate let dispatchAction: (Root.Action) -> Void | ||
|
||
|
@@ -173,6 +175,8 @@ extension RootViewController { | |
actionTransform: Root.Action.infoListEffect) | ||
} | ||
} | ||
updateWithAuthViewModel(viewModel.privacy) | ||
|
||
currentViewModel = viewModel | ||
} | ||
|
||
|
@@ -201,6 +205,49 @@ extension RootViewController { | |
) | ||
presentViewControllers([viewControllerA, viewControllerB]) | ||
} | ||
|
||
private func updateWithAuthViewModel(_ viewModel: AuthViewModel) { | ||
if viewModel.enabled == currentViewModel.privacy.enabled { | ||
return | ||
} | ||
if viewModel.enabled { | ||
if authController == nil { | ||
authController = UIViewController() | ||
authController?.view.backgroundColor = UIColor.otpBackgroundColor | ||
let button = UIButton(type: .roundedRect) | ||
button.setTitleColor(UIColor.otpForegroundColor, for: .normal) | ||
button.setTitle("Unlock", for: .normal) | ||
button.addTarget(self, action: #selector(authChallenge), for: .touchUpInside) | ||
button.sizeToFit() | ||
authController?.view.addSubview(button) | ||
button.center = authController!.view.center | ||
authController?.modalPresentationStyle = .overFullScreen | ||
} | ||
|
||
guard let controller = authController else { | ||
return | ||
} | ||
if let presented = presentedViewController { | ||
presented.present(controller, animated: false) | ||
return | ||
} else { | ||
present(controller, animated: false) | ||
} | ||
} | ||
if !viewModel.enabled { | ||
authController?.presentingViewController?.dismiss(animated: true) | ||
authController = nil | ||
} | ||
} | ||
|
||
@objc private func authChallenge() { | ||
let context = LAContext() | ||
context.evaluatePolicy(.deviceOwnerAuthentication, localizedReason: "LOLZ") { (reply, error) in | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This currently only triggers the passcode-screen, although Face ID is available. Per docs it should try Face ID / Touch ID first. Did you notice this as well? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Strange! On my phone, it triggers FaceID. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It does not prompt for this permission and is not visible in the settings but I can check again! Having this pull request merged brings this project to a new level of privacy, so thanks everyone contributing to this! 🙂 |
||
DispatchQueue.main.async { | ||
self.dispatchAction(.authAction(.authResult(reply: reply, error: error))) | ||
} | ||
} | ||
} | ||
} | ||
|
||
private func compose<A, B, C>(_ transform: @escaping (A) -> B, _ handler: @escaping (B) -> C) -> (A) -> C { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This
localizedReason
seems completely correct to me.