Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Commit

Permalink
Cleaning up view type and handling cancel case for general
Browse files Browse the repository at this point in the history
  • Loading branch information
soner-yuksel committed Aug 28, 2023
1 parent 68dbdac commit 21610ec
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 9 deletions.
9 changes: 6 additions & 3 deletions Sources/Brave/Frontend/Passcode/WindowProtection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public class WindowProtection {
private var protectedWindow: UIWindow
private var passcodeWindow: UIWindow
private var context = LAContext()
private var viewType: AuthViewType = .general

private var isVisible: Bool = false {
didSet {
Expand Down Expand Up @@ -174,7 +175,7 @@ public class WindowProtection {
}

@objc private func tappedUnlock() {
presentLocalAuthentication()
presentLocalAuthentication(viewType: viewType)
}

@objc private func tappedCancel() {
Expand Down Expand Up @@ -208,7 +209,7 @@ public class WindowProtection {
}
}

private func presentLocalAuthentication(viewType: AuthViewType = .general, completion: ((Bool, LAError.Code?) -> Void)? = nil) {
private func presentLocalAuthentication(viewType: AuthViewType, completion: ((Bool, LAError.Code?) -> Void)? = nil) {
if !context.canEvaluatePolicy(.deviceOwnerAuthentication, error: nil) {
completion?(false, .passcodeNotSet)
return
Expand All @@ -229,7 +230,7 @@ public class WindowProtection {
completion?(true, nil)
})
} else {
lockedViewController.unlockButton.isHidden = false
lockedViewController.unlockButton.isHidden = viewType == .general

let errorPolicy = error as? LAError
completion?(false, errorPolicy?.code)
Expand All @@ -248,6 +249,8 @@ public class WindowProtection {
if isVisible {
return
}

self.viewType = viewType

context = LAContext()
updateVisibleStatusForForeground(determineLockWithPasscode, viewType: viewType) { status, error in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ class SyncSettingsTableViewController: SyncViewController, UITableViewDelegate,
if toggleExistingStatus {
performSyncDataTypeStatusChange(type: syncDataType)
} else {
askForAuthentication() { status, error in
askForAuthentication(viewType: .sync) { status, error in
guard status else {
toggle.setOn(toggleExistingStatus, animated: false)
return
Expand Down Expand Up @@ -336,7 +336,7 @@ class SyncSettingsTableViewController: SyncViewController, UITableViewDelegate,

@objc
private func onSyncInternalsTapped() {
askForAuthentication() { [weak self] status, error in
askForAuthentication(viewType: .sync) { [weak self] status, error in
guard let self = self, status else { return }

let syncInternalsController = self.syncAPI.createSyncInternalsController().then {
Expand Down Expand Up @@ -592,7 +592,7 @@ extension SyncSettingsTableViewController {
}

private func addAnotherDevice() {
askForAuthentication() { [weak self] status, error in
askForAuthentication(viewType: .sync) { [weak self] status, error in
guard let self = self, status else { return }

let view = SyncSelectDeviceTypeViewController()
Expand Down
2 changes: 1 addition & 1 deletion Sources/Brave/Frontend/Sync/SyncViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class SyncViewController: AuthenticationController {
super.viewWillAppear(animated)

if requiresAuthentication {
askForAuthentication() { [weak self] success, error in
askForAuthentication(viewType: .sync) { [weak self] success, error in
guard let self else { return }

if !success, error != .userCancel {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ class SyncWelcomeViewController: SyncViewController {

@objc
private func onSyncInternalsAction() {
askForAuthentication() { [weak self] status, error in
askForAuthentication(viewType: .sync) { [weak self] status, error in
guard let self = self, status else { return }

let syncInternalsController = syncAPI.createSyncInternalsController().then {
Expand Down
2 changes: 1 addition & 1 deletion Sources/Brave/Frontend/Widgets/LoadingViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public class AuthenticationController: LoadingViewController {

/// A method to ask biometric authentication to user
/// - Parameter completion: block returning authentication status
func askForAuthentication(viewType: AuthViewType = .sync, completion: ((Bool, LAError.Code?) -> Void)? = nil) {
func askForAuthentication(viewType: AuthViewType, completion: ((Bool, LAError.Code?) -> Void)? = nil) {
guard let windowProtection = windowProtection else {
completion?(false, nil)
return
Expand Down

0 comments on commit 21610ec

Please sign in to comment.