Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removes Gemini toggle option from settings when unsupported [1.13] #6612

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ cr.define('settings', function() {
* @return {!Promise<Boolean>}
*/
getIsBraveTogetherSupported() {}

/**
* @return {!Promise<Boolean>}
*/
getIsGeminiSupported() {}
}

/**
Expand All @@ -43,6 +48,11 @@ cr.define('settings', function() {
getIsBraveTogetherSupported() {
return cr.sendWithPromise('getIsBraveTogetherSupported')
}

/** @override */
getIsGeminiSupported() {
return cr.sendWithPromise('getIsGeminiSupported')
}
}

cr.addSingletonGetter(BraveNewTabBrowserProxyImpl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,13 @@
label="$i18n{braveNewTabBinance}">
</settings-toggle-button>
</template>
<settings-toggle-button
class="cr-row"
pref="{{prefs.brave.new_tab_page.show_gemini}}"
label="$i18n{braveNewTabGemini}">
</settings-toggle-button>
<template is="dom-if" if="[[isGeminiSupported_]]">
<settings-toggle-button
class="cr-row"
pref="{{prefs.brave.new_tab_page.show_gemini}}"
label="$i18n{braveNewTabGemini}">
</settings-toggle-button>
</template>
<settings-toggle-button
class="cr-row"
pref="{{prefs.brave.new_tab_page.show_top_sites}}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
isSuperReferralActive_: Boolean,
isBinanceSupported_: Boolean,
isBraveTogetherSupported_: Boolean,
isGeminiSupported_: Boolean,
},

/** @override */
Expand All @@ -32,6 +33,7 @@
this.isSuperReferralActive_ = false;
this.isBinanceSupported_ = false;
this.isBraveTogetherSupported_ = false;
this.isGeminiSupported_ = false;
},

/** @override */
Expand All @@ -45,6 +47,9 @@
this.browserProxy_.getIsBraveTogetherSupported().then(isBraveTogetherSupported => {
this.isBraveTogetherSupported_ = isBraveTogetherSupported;
})
this.browserProxy_.getIsGeminiSupported().then(isGeminiSupported => {
this.isGeminiSupported_ = isGeminiSupported;
})

this.addWebUIListener('super-referral-active-state-changed', (isSuperReferralActive) => {
this.isSuperReferralActive_ = isSuperReferralActive;
Expand Down
24 changes: 24 additions & 0 deletions browser/ui/webui/settings/brave_appearance_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "brave/browser/themes/brave_dark_mode_utils.h"
#include "brave/components/binance/browser/buildflags/buildflags.h"
#include "brave/components/brave_together/buildflags/buildflags.h"
#include "brave/components/gemini/browser/buildflags/buildflags.h"
#include "brave/common/pref_names.h"
#include "brave/components/ntp_background_images/browser/ntp_background_images_data.h"
#include "brave/components/ntp_background_images/browser/view_counter_service.h"
Expand All @@ -27,6 +28,10 @@
#include "brave/browser/brave_together/brave_together_util.h"
#endif

#if BUILDFLAG(GEMINI_ENABLED)
#include "brave/browser/gemini/gemini_util.h"
#endif

using ntp_background_images::ViewCounterServiceFactory;
using ntp_background_images::prefs::kNewTabPageSuperReferralThemesOption;

Expand Down Expand Up @@ -85,6 +90,10 @@ void BraveAppearanceHandler::RegisterMessages() {
"getIsBraveTogetherSupported",
base::BindRepeating(&BraveAppearanceHandler::GetIsBraveTogetherSupported,
base::Unretained(this)));
web_ui()->RegisterMessageCallback(
"getIsGeminiSupported",
base::BindRepeating(&BraveAppearanceHandler::GetIsGeminiSupported,
base::Unretained(this)));
}

void BraveAppearanceHandler::SetBraveThemeType(const base::ListValue* args) {
Expand Down Expand Up @@ -147,6 +156,21 @@ void BraveAppearanceHandler::GetIsBraveTogetherSupported(
ResolveJavascriptCallback(args->GetList()[0], base::Value(is_supported));
}

void BraveAppearanceHandler::GetIsGeminiSupported(
const base::ListValue* args) {
CHECK_EQ(args->GetSize(), 1U);

AllowJavascript();

#if !BUILDFLAG(GEMINI_ENABLED)
bool is_supported = false;
#else
bool is_supported = gemini::IsGeminiSupported(profile);
#endif

ResolveJavascriptCallback(args->GetList()[0], base::Value(is_supported));
}

void BraveAppearanceHandler::OnBraveDarkModeChanged() {
// GetBraveThemeType() should be used because settings option displays all
// available options including default.
Expand Down
1 change: 1 addition & 0 deletions browser/ui/webui/settings/brave_appearance_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class BraveAppearanceHandler : public settings::SettingsPageUIHandler {
void GetIsSuperReferralActive(const base::ListValue* args);
void GetIsBinanceSupported(const base::ListValue* args);
void GetIsBraveTogetherSupported(const base::ListValue* args);
void GetIsGeminiSupported(const base::ListValue* args);

Profile* profile_ = nullptr;
PrefChangeRegistrar local_state_change_registrar_;
Expand Down