From eb888f985b33ed7de6877fc6113765ae5d2d1751 Mon Sep 17 00:00:00 2001 From: Brandon-T Date: Tue, 12 Nov 2024 11:35:42 -0500 Subject: [PATCH] [iOS] - Obey Leo Feature Flag (#26484) * Fix crash when disabling Leo via feature-flags on iOS. * Disable Leo settings when feature flag is disabled. --- .../Sources/AIChat/AIChatStrings.swift | 18 ++++++++++++++++++ .../BrowserViewController/BVC+Menu.swift | 6 ++++-- .../BrowserViewController.swift | 12 ++++++++++++ .../Search/SearchSuggestionDataSource.swift | 5 ++++- .../Settings/SettingsViewController.swift | 2 +- 5 files changed, 39 insertions(+), 4 deletions(-) diff --git a/ios/brave-ios/Sources/AIChat/AIChatStrings.swift b/ios/brave-ios/Sources/AIChat/AIChatStrings.swift index 64e79fe7e793..773c71958ba4 100644 --- a/ios/brave-ios/Sources/AIChat/AIChatStrings.swift +++ b/ios/brave-ios/Sources/AIChat/AIChatStrings.swift @@ -979,5 +979,23 @@ extension Strings { comment: "The default title displayed above a code block when the language of the code is not known." ) + public static let leoDisabledMessageTitle = NSLocalizedString( + "aichat.leoDisabledMessageTitle", + tableName: "BraveLeo", + bundle: .module, + value: + "Leo Disabled", + comment: + "The title that shows in an alert when the Leo/AI-Chat feature is disabled." + ) + public static let leoDisabledMessageDescription = NSLocalizedString( + "aichat.leoDisabledMessageDescription", + tableName: "BraveLeo", + bundle: .module, + value: + "Leo is currently disabled via feature flags. To re-enable Leo, please visit brave://flags and enable it.", + comment: + "The message that shows in an alert, to let the user know the 'Leo' feature is disabled, and explains how to re-enable the feature." + ) } } diff --git a/ios/brave-ios/Sources/Brave/Frontend/Browser/BrowserViewController/BVC+Menu.swift b/ios/brave-ios/Sources/Brave/Frontend/Browser/BrowserViewController/BVC+Menu.swift index ca34d21abfc4..770fbfe97cb6 100644 --- a/ios/brave-ios/Sources/Brave/Frontend/Browser/BrowserViewController/BVC+Menu.swift +++ b/ios/brave-ios/Sources/Brave/Frontend/Browser/BrowserViewController/BVC+Menu.swift @@ -155,7 +155,7 @@ extension BrowserViewController { } // Add Brave-Leo options only in normal browsing - if !privateBrowsingManager.isPrivateBrowsing { + if !privateBrowsingManager.isPrivateBrowsing && FeatureList.kAIChat.enabled { MenuItemFactory.button(for: .leo) { [unowned self] in self.popToBVC() self.openBraveLeo() @@ -357,7 +357,9 @@ extension BrowserViewController { } // Add Brave-Leo options only in normal browsing - if !browserViewController.tabManager.privateBrowsingManager.isPrivateBrowsing { + if !browserViewController.tabManager.privateBrowsingManager.isPrivateBrowsing + && FeatureList.kAIChat.enabled + { MenuItemButton( icon: Image(braveSystemName: "leo.product.brave-leo"), title: Strings.leoMenuItem diff --git a/ios/brave-ios/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController.swift b/ios/brave-ios/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController.swift index 8b4960c7459f..b3d63eb01cbc 100644 --- a/ios/brave-ios/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController.swift +++ b/ios/brave-ios/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController.swift @@ -3666,6 +3666,18 @@ extension BrowserViewController { } func openBraveLeo(with query: String? = nil) { + if !FeatureList.kAIChat.enabled { + let alert = UIAlertController( + title: Strings.AIChat.leoDisabledMessageTitle, + message: Strings.AIChat.leoDisabledMessageDescription, + preferredStyle: .alert + ) + let action = UIAlertAction(title: Strings.OKString, style: .default) + alert.addAction(action) + present(alert, animated: true) + return + } + let webView = (query == nil) ? tabManager.selectedTab?.webView : nil let model = AIChatViewModel( diff --git a/ios/brave-ios/Sources/Brave/Frontend/Browser/Search/SearchSuggestionDataSource.swift b/ios/brave-ios/Sources/Brave/Frontend/Browser/Search/SearchSuggestionDataSource.swift index 998154b09357..82e1f44d8183 100644 --- a/ios/brave-ios/Sources/Brave/Frontend/Browser/Search/SearchSuggestionDataSource.swift +++ b/ios/brave-ios/Sources/Brave/Frontend/Browser/Search/SearchSuggestionDataSource.swift @@ -4,6 +4,7 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. import AIChat +import BraveCore import BraveUI import Foundation import Preferences @@ -84,7 +85,9 @@ class SearchSuggestionDataSource { sections.append(.openTabsAndHistoryAndBookmarks) } - if !tabType.isPrivate && Preferences.AIChat.autocompleteSuggestionsEnabled.value { + if !tabType.isPrivate && Preferences.AIChat.autocompleteSuggestionsEnabled.value + && FeatureList.kAIChat.enabled + { sections.append(.aiChat) } diff --git a/ios/brave-ios/Sources/Brave/Frontend/Settings/SettingsViewController.swift b/ios/brave-ios/Sources/Brave/Frontend/Settings/SettingsViewController.swift index 18efb3e6bad1..0b488b8e9341 100644 --- a/ios/brave-ios/Sources/Brave/Frontend/Settings/SettingsViewController.swift +++ b/ios/brave-ios/Sources/Brave/Frontend/Settings/SettingsViewController.swift @@ -368,7 +368,7 @@ class SettingsViewController: TableViewController { ) ) - if !tabManager.privateBrowsingManager.isPrivateBrowsing { + if !tabManager.privateBrowsingManager.isPrivateBrowsing && FeatureList.kAIChat.enabled { section.rows.append(leoSettingsRow) }