Skip to content

Commit

Permalink
[iOS] - Obey Leo Feature Flag (#26484)
Browse files Browse the repository at this point in the history
* Fix crash when disabling Leo via feature-flags on iOS.
* Disable Leo settings when feature flag is disabled.
  • Loading branch information
Brandon-T authored Nov 12, 2024
1 parent 71c03ef commit eb888f9
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 4 deletions.
18 changes: 18 additions & 0 deletions ios/brave-ios/Sources/AIChat/AIChatStrings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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."
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ class SettingsViewController: TableViewController {
)
)

if !tabManager.privateBrowsingManager.isPrivateBrowsing {
if !tabManager.privateBrowsingManager.isPrivateBrowsing && FeatureList.kAIChat.enabled {
section.rows.append(leoSettingsRow)
}

Expand Down

0 comments on commit eb888f9

Please sign in to comment.