This repository has been archived by the owner on May 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 440
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
8afb991
commit ff67224
Showing
9 changed files
with
200 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
Sources/Brave/Frontend/Widgets/LoadingViewController.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
// Copyright 2023 The Brave Authors. All rights reserved. | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
import UIKit | ||
import BraveShared | ||
import Shared | ||
import LocalAuthentication | ||
|
||
public class LoadingViewController: UIViewController { | ||
|
||
let spinner = UIActivityIndicatorView().then { | ||
$0.snp.makeConstraints { make in | ||
make.size.equalTo(24) | ||
} | ||
$0.hidesWhenStopped = true | ||
$0.isHidden = true | ||
} | ||
|
||
var isLoading: Bool = false { | ||
didSet { | ||
if isLoading { | ||
view.addSubview(spinner) | ||
spinner.snp.makeConstraints { | ||
$0.center.equalTo(view.snp.center) | ||
} | ||
spinner.startAnimating() | ||
} else { | ||
spinner.stopAnimating() | ||
spinner.removeFromSuperview() | ||
} | ||
} | ||
} | ||
} | ||
|
||
public class AuthenticationController: LoadingViewController { | ||
enum AuthViewType { | ||
case sync, tabTray | ||
} | ||
|
||
let windowProtection: WindowProtection? | ||
let requiresAuthentication: Bool | ||
|
||
// MARK: Lifecycle | ||
|
||
init(windowProtection: WindowProtection? = nil, | ||
requiresAuthentication: Bool = false, | ||
isCancellable: Bool = false, | ||
unlockScreentitle: String = "") { | ||
self.windowProtection = windowProtection | ||
self.requiresAuthentication = requiresAuthentication | ||
|
||
super.init(nibName: nil, bundle: nil) | ||
|
||
self.windowProtection?.isCancellable = isCancellable | ||
self.windowProtection?.unlockScreentitle = unlockScreentitle | ||
} | ||
|
||
required init?(coder: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
|
||
/// 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) { | ||
guard let windowProtection = windowProtection else { | ||
completion?(false, nil) | ||
return | ||
} | ||
|
||
if !windowProtection.isPassCodeAvailable { | ||
showSetPasscodeError(viewType: viewType) { | ||
completion?(false, LAError.passcodeNotSet) | ||
} | ||
} else { | ||
windowProtection.presentAuthenticationForViewController( | ||
determineLockWithPasscode: false) { status, error in | ||
completion?(status, error) | ||
} | ||
} | ||
} | ||
|
||
/// An alert presenter for passcode error to warn user to setup passcode to use feature | ||
/// - Parameter completion: block after Ok button is pressed | ||
func showSetPasscodeError(viewType: AuthViewType, completion: @escaping (() -> Void)) { | ||
let alert = UIAlertController( | ||
title: Strings.Sync.syncSetPasscodeAlertTitle, | ||
message: viewType == .sync ? Strings.Sync.syncSetPasscodeAlertDescription : Strings.Privacy.tabTraySetPasscodeAlertDescription, | ||
preferredStyle: .alert) | ||
|
||
alert.addAction( | ||
UIAlertAction(title: Strings.OKString, style: .default, handler: { _ in | ||
completion() | ||
}) | ||
) | ||
|
||
present(alert, animated: true, completion: nil) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.