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

Commit

Permalink
Authenticate when disabling browser lock
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandon-T committed Jan 3, 2024
1 parent 1c6d636 commit 748bcb9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
23 changes: 18 additions & 5 deletions Sources/Brave/Frontend/Settings/SettingsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ class SettingsViewController: TableViewController {
let privateTabsRow = Row(
text: Strings.TabsSettings.privateTabsSettingsTitle,
selection: { [unowned self] in
let vc = UIHostingController(rootView: PrivateTabsView(tabManager: tabManager))
let vc = UIHostingController(rootView: PrivateTabsView(tabManager: tabManager, askForAuthentication: self.askForLocalAuthentication))
self.navigationController?.pushViewController(vc, animated: true)
},
image: UIImage(braveSystemNamed: "leo.product.private-window"),
Expand Down Expand Up @@ -656,11 +656,24 @@ class SettingsViewController: TableViewController {
return Section(
header: .title(Strings.security),
rows: [
.boolRow(
title: Strings.Privacy.browserLock,
Row(
text: Strings.Privacy.browserLock,
detailText: Strings.Privacy.browserLockDescription,
option: Preferences.Privacy.lockWithPasscode,
image: UIImage(braveSystemNamed: "leo.biometric.login")),
image: UIImage(braveSystemNamed: "leo.biometric.login"),
accessory: .view(SwitchAccessoryView(initialValue: Preferences.Privacy.lockWithPasscode.value, valueChange: { isOn in
if isOn {
Preferences.Privacy.lockWithPasscode.value = isOn
} else {
self.askForLocalAuthentication { [weak self] success, error in
if success {
Preferences.Privacy.lockWithPasscode.value = isOn
}
}
}
})),
cellClass: MultilineSubtitleCell.self,
uuid: Preferences.Privacy.lockWithPasscode.key
),
Row(
text: Strings.Login.loginListNavigationTitle,
selection: { [unowned self] in
Expand Down
15 changes: 13 additions & 2 deletions Sources/Brave/Frontend/Settings/Tabs/PrivateTabsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ struct PrivateTabsView: View {
}

@ObservedObject var privateBrowsingOnly = Preferences.Privacy.privateBrowsingOnly
@ObservedObject var privateBrowsingLock = Preferences.Privacy.privateBrowsingLock

var tabManager: TabManager?
var askForAuthentication: (AuthViewType, ((Bool, LAError.Code?) -> Void)?) -> Void

private var localAuthenticationType: AuthenticationType {
let context = LAContext()
Expand Down Expand Up @@ -86,7 +89,15 @@ struct PrivateTabsView: View {
case .faceID, .touchID, .pinCode:
OptionToggleView(title: browsingLockTitle,
subtitle: nil,
option: Preferences.Privacy.privateBrowsingLock)
option: privateBrowsingLock) { newValue in
if !newValue {
askForAuthentication(.general) { success, _ in
if success {
privateBrowsingLock.value = newValue
}
}
}
}
case .noAuthentication:
Toggle(isOn: .constant(false)) {
VStack(alignment: .leading, spacing: 4) {
Expand All @@ -111,7 +122,7 @@ struct PrivateTabsView: View {
#if DEBUG
struct PrivateTabsView_Previews: PreviewProvider {
static var previews: some View {
PrivateTabsView()
PrivateTabsView(askForAuthentication: { _, _ in })
}
}
#endif

0 comments on commit 748bcb9

Please sign in to comment.