Skip to content

Commit

Permalink
Fix brave/brave-ios#8608: Authenticate when disabling browser lock (b…
Browse files Browse the repository at this point in the history
…rave/brave-ios#8609)

- Authenticate when disabling browser lock
  • Loading branch information
Brandon-T committed Jan 5, 2024
1 parent 443dbb8 commit 98206ba
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 10 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
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import Preferences
struct OptionToggleView: View {
let title: String
var subtitle: String?
var markdownSubtitle: LocalizedStringKey?
@ObservedObject var option: Preferences.Option<Bool>
let onChange: ShieldToggleView.OnChangeCallback?

Expand Down
22 changes: 18 additions & 4 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 @@ -84,9 +87,20 @@ struct PrivateTabsView: View {

switch localAuthenticationType {
case .faceID, .touchID, .pinCode:
OptionToggleView(title: browsingLockTitle,
subtitle: nil,
option: Preferences.Privacy.privateBrowsingLock)
ShieldToggleView(
title: browsingLockTitle,
subtitle: nil,
toggle: .init(get: {
privateBrowsingLock.value
}, set: { isOn in
if isOn {
privateBrowsingLock.value = true
} else {
askForAuthentication(.general) { success, _ in
privateBrowsingLock.value = !success
}
}
}))
case .noAuthentication:
Toggle(isOn: .constant(false)) {
VStack(alignment: .leading, spacing: 4) {
Expand All @@ -111,7 +125,7 @@ struct PrivateTabsView: View {
#if DEBUG
struct PrivateTabsView_Previews: PreviewProvider {
static var previews: some View {
PrivateTabsView()
PrivateTabsView(askForAuthentication: { _, _ in })
}
}
#endif

0 comments on commit 98206ba

Please sign in to comment.