From 748bcb9d5881c6fd77d05ff8a207ab40c6eaa890 Mon Sep 17 00:00:00 2001 From: Brandon T Date: Wed, 3 Jan 2024 10:29:48 -0500 Subject: [PATCH] Authenticate when disabling browser lock --- .../Settings/SettingsViewController.swift | 23 +++++++++++++++---- .../Settings/Tabs/PrivateTabsView.swift | 15 ++++++++++-- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/Sources/Brave/Frontend/Settings/SettingsViewController.swift b/Sources/Brave/Frontend/Settings/SettingsViewController.swift index 3b8145f85c7..b0c8a8f2711 100644 --- a/Sources/Brave/Frontend/Settings/SettingsViewController.swift +++ b/Sources/Brave/Frontend/Settings/SettingsViewController.swift @@ -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"), @@ -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 diff --git a/Sources/Brave/Frontend/Settings/Tabs/PrivateTabsView.swift b/Sources/Brave/Frontend/Settings/Tabs/PrivateTabsView.swift index 44d0c0d5ff7..849f78dd2f3 100644 --- a/Sources/Brave/Frontend/Settings/Tabs/PrivateTabsView.swift +++ b/Sources/Brave/Frontend/Settings/Tabs/PrivateTabsView.swift @@ -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() @@ -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) { @@ -111,7 +122,7 @@ struct PrivateTabsView: View { #if DEBUG struct PrivateTabsView_Previews: PreviewProvider { static var previews: some View { - PrivateTabsView() + PrivateTabsView(askForAuthentication: { _, _ in }) } } #endif