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

Brave VPN card widget in NTP #26189

Merged
merged 47 commits into from
Nov 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
bf27c75
BraveVPN widget in NTP
simonhong Sep 21, 2024
171d94d
WIP: add vpn widget ui
AlanBreck Sep 23, 2024
1a6d7cf
fixup! WIP: add vpn widget ui
AlanBreck Sep 23, 2024
1ce41e8
fixup! WIP: add vpn widget ui
AlanBreck Sep 23, 2024
2e392cb
Reuse rewards widget for vpn widget
simonhong Sep 24, 2024
250c2f2
Launch vpn panel when clicks change link in ntp widget
simonhong Sep 24, 2024
c9e5b34
Fix deps issue temporarily
simonhong Sep 24, 2024
a4a23a4
Added api for open url
simonhong Sep 24, 2024
c18f9b2
add vpn widget promo screen
AlanBreck Sep 24, 2024
44b4b76
Changed condition check for choosing promo or main
simonhong Sep 24, 2024
1a3b35b
Updated widget menu/customize entry
simonhong Sep 25, 2024
0eda278
fix theme for VPN widget
AlanBreck Sep 25, 2024
6d19ce2
Rebased
simonhong Oct 24, 2024
004e0ac
Revert "Updated widget menu/customize entry"
simonhong Oct 25, 2024
39bce71
Revert "Reuse rewards widget for vpn widget"
simonhong Oct 25, 2024
96c6377
WIP: Show vpn widget card
simonhong Oct 28, 2024
368d3d8
Control vpn card visibility in NTP settings
simonhong Oct 29, 2024
476f239
Revert "Fix deps issue temporarily"
simonhong Oct 29, 2024
0362ac8
Deleted launchVpnPanel/openVpnUI from brave_vpn::mojom::ServiceHandler
simonhong Oct 29, 2024
a76ce6f
fixup! WIP: Show vpn widget card
simonhong Oct 31, 2024
df06afc
fixed build failure on android
simonhong Nov 1, 2024
897ba9c
Updated vpn card settings graphic
simonhong Nov 1, 2024
7f101bc
WIP: Polish widget UI
simonhong Nov 1, 2024
0cb2bef
Fixed presubmit error - line length
simonhong Nov 1, 2024
6013238
Wireup vpn card actions with BraveVPNController
simonhong Nov 1, 2024
4007779
fixup! WIP: Polish widget UI
simonhong Nov 2, 2024
8855e11
Use lottie player for animated shields icon for connecting
simonhong Nov 2, 2024
697a2a3
Launch vpn panel with selection page from NTP vpn card
simonhong Nov 4, 2024
7842134
Moved vpn refresh api from vpn.mojom to ntp.mojom
simonhong Nov 4, 2024
0ec4056
Use ENABLE_BRAVE_VPN instead of ENABLE_BRAVE_VPN_PANEL
simonhong Nov 4, 2024
157a997
fixup! Moved vpn refresh api from vpn.mojom to ntp.mojom
simonhong Nov 4, 2024
18077fc
Done card widget localization
simonhong Nov 4, 2024
77d409d
Deleted NTPWidgetHandlerFactory
simonhong Nov 5, 2024
514c7dd
Removed braveVPNSupported from initialData
simonhong Nov 5, 2024
8ae99bf
Deleted vpn props from settings
simonhong Nov 5, 2024
d57cc1c
Merged vpn card styles file
simonhong Nov 5, 2024
0172e33
Cleanup
simonhong Nov 5, 2024
5104d52
Deleted saveShowBraveVPN
simonhong Nov 5, 2024
45ff385
Fixed sell panel is shown after reloading in purchased
simonhong Nov 5, 2024
977008a
Deleted unnecessary export from styles
simonhong Nov 5, 2024
ebaab87
Use our lottie-player instead of third party npm module
simonhong Nov 6, 2024
3be8ba5
Moved lottie-player to common place for sharing
simonhong Nov 6, 2024
c2989d9
Fixed typo and deleted unnecessary state
simonhong Nov 7, 2024
ee5415f
Fixed flickering whenever reload due to vpn card page change
simonhong Nov 7, 2024
7deda1d
Deleted redundant checking for showing card
simonhong Nov 7, 2024
e3a07a7
fixup! Fixed flickering whenever reload due to vpn card page change
simonhong Nov 7, 2024
0936793
Guarded vpn prefs
simonhong Nov 9, 2024
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
6 changes: 6 additions & 0 deletions browser/brave_content_browser_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,12 @@ void BraveContentBrowserClient::RegisterWebUIInterfaceBrokers(
.Add<brave_new_tab_page::mojom::PageHandlerFactory>()
.Add<brave_news::mojom::BraveNewsController>();

#if BUILDFLAG(ENABLE_BRAVE_VPN)
if (brave_vpn::IsBraveVPNFeatureEnabled()) {
ntp_registration.Add<brave_vpn::mojom::ServiceHandler>();
}
#endif

if (base::FeatureList::IsEnabled(features::kBraveNtpSearchWidget)) {
ntp_registration.Add<searchbox::mojom::PageHandler>();
}
Expand Down
5 changes: 5 additions & 0 deletions browser/brave_profile_prefs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "brave/components/brave_shields/content/browser/brave_shields_p3a.h"
#include "brave/components/brave_shields/core/common/pref_names.h"
#include "brave/components/brave_sync/brave_sync_prefs.h"
#include "brave/components/brave_vpn/common/buildflags/buildflags.h"
#include "brave/components/brave_wallet/browser/brave_wallet_prefs.h"
#include "brave/components/brave_wayback_machine/buildflags/buildflags.h"
#include "brave/components/brave_webtorrent/browser/buildflags/buildflags.h"
Expand Down Expand Up @@ -367,6 +368,10 @@ void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {
registry->RegisterBooleanPref(kNewTabPageShowBraveTalk, true);
registry->RegisterBooleanPref(kNewTabPageHideAllWidgets, false);

#if BUILDFLAG(ENABLE_BRAVE_VPN)
registry->RegisterBooleanPref(kNewTabPageShowBraveVPN, true);
#endif

// Private New Tab Page
#if !BUILDFLAG(IS_ANDROID)
brave_private_new_tab::prefs::RegisterProfilePrefs(registry);
Expand Down
2 changes: 2 additions & 0 deletions browser/extensions/api/settings_private/brave_prefs_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ const PrefsUtil::TypedPrefMap& BravePrefsUtil::GetAllowlistedKeys() {
settings_api::PrefType::kBoolean;
(*s_brave_allowlist)[kNewTabPageShowBraveTalk] =
settings_api::PrefType::kBoolean;
(*s_brave_allowlist)[kNewTabPageShowBraveVPN] =
settings_api::PrefType::kBoolean;
(*s_brave_allowlist)[kNewTabPageShowsOptions] =
settings_api::PrefType::kNumber;
#if BUILDFLAG(ENABLE_EXTENSIONS)
Expand Down
14 changes: 14 additions & 0 deletions browser/ui/webui/new_tab_page/brave_new_tab_message_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "brave/components/brave_news/common/pref_names.h"
#include "brave/components/brave_perf_predictor/common/pref_names.h"
#include "brave/components/brave_search_conversion/pref_names.h"
#include "brave/components/brave_vpn/common/buildflags/buildflags.h"
#include "brave/components/constants/pref_names.h"
#include "brave/components/ntp_background_images/browser/url_constants.h"
#include "brave/components/ntp_background_images/browser/view_counter_service.h"
Expand Down Expand Up @@ -86,6 +87,9 @@ base::Value::Dict GetPreferencesDictionary(PrefService* prefs) {
prefs->GetBoolean(brave_news::prefs::kBraveNewsOptedIn));
pref_data.Set("hideAllWidgets", prefs->GetBoolean(kNewTabPageHideAllWidgets));
pref_data.Set("showBraveTalk", prefs->GetBoolean(kNewTabPageShowBraveTalk));
#if BUILDFLAG(ENABLE_BRAVE_VPN)
pref_data.Set("showBraveVPN", prefs->GetBoolean(kNewTabPageShowBraveVPN));
#endif
pref_data.Set(
"showSearchBox",
prefs->GetBoolean(brave_search_conversion::prefs::kShowNTPSearchBox));
Expand Down Expand Up @@ -329,6 +333,12 @@ void BraveNewTabMessageHandler::OnJavascriptAllowed() {
kNewTabPageShowBraveTalk,
base::BindRepeating(&BraveNewTabMessageHandler::OnPreferencesChanged,
base::Unretained(this)));
#if BUILDFLAG(ENABLE_BRAVE_VPN)
pref_change_registrar_.Add(
kNewTabPageShowBraveVPN,
base::BindRepeating(&BraveNewTabMessageHandler::OnPreferencesChanged,
base::Unretained(this)));
#endif
pref_change_registrar_.Add(
kNewTabPageHideAllWidgets,
base::BindRepeating(&BraveNewTabMessageHandler::OnPreferencesChanged,
Expand Down Expand Up @@ -452,6 +462,10 @@ void BraveNewTabMessageHandler::HandleSaveNewTabPagePref(
settings_key = kNewTabPageHideAllWidgets;
} else if (settings_key_input == "showBraveTalk") {
settings_key = kNewTabPageShowBraveTalk;
#if BUILDFLAG(ENABLE_BRAVE_VPN)
} else if (settings_key_input == "showBraveVPN") {
settings_key = kNewTabPageShowBraveVPN;
#endif
} else if (settings_key_input == "showSearchBox") {
settings_key = brave_search_conversion::prefs::kShowNTPSearchBox;
} else if (settings_key_input == "promptEnableSearchSuggestions") {
Expand Down
40 changes: 40 additions & 0 deletions browser/ui/webui/new_tab_page/brave_new_tab_page_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "brave/components/brave_search_conversion/pref_names.h"
#include "brave/components/brave_search_conversion/types.h"
#include "brave/components/brave_search_conversion/utils.h"
#include "brave/components/brave_vpn/common/buildflags/buildflags.h"
#include "brave/components/constants/pref_names.h"
#include "brave/components/l10n/common/localization_util.h"
#include "brave/components/ntp_background_images/browser/ntp_background_images_data.h"
Expand All @@ -34,7 +35,10 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/search_engines/template_url_service_factory.h"
#include "chrome/browser/themes/theme_syncable_service.h"
#include "chrome/browser/ui/browser_window/public/browser_window_features.h"
#include "chrome/browser/ui/browser_window/public/browser_window_interface.h"
#include "chrome/browser/ui/chrome_select_file_policy.h"
#include "chrome/browser/ui/tabs/public/tab_interface.h"
#include "chrome/common/pref_names.h"
#include "chrome/grit/generated_resources.h"
#include "components/omnibox/browser/omnibox_view.h"
Expand All @@ -55,6 +59,12 @@
#include "url/gurl.h"
#include "url/origin.h"

#if BUILDFLAG(ENABLE_BRAVE_VPN)
#include "brave/browser/brave_vpn/brave_vpn_service_factory.h"
#include "brave/browser/ui/brave_vpn/brave_vpn_controller.h"
#include "brave/components/brave_vpn/browser/brave_vpn_service.h"
#endif

namespace {

bool IsNTPPromotionEnabled(Profile* profile) {
Expand Down Expand Up @@ -313,6 +323,36 @@ void BraveNewTabPageHandler::SearchWhatYouTyped(const std::string& host,
web_contents_->OpenURL(params, /*navigation_handle_callback=*/{});
}

void BraveNewTabPageHandler::RefreshVPNState() {
#if BUILDFLAG(ENABLE_BRAVE_VPN)
auto* vpn_service =
brave_vpn::BraveVpnServiceFactory::GetForProfile(profile_);
vpn_service->ReloadPurchasedState();
#endif
}

void BraveNewTabPageHandler::LaunchVPNPanel() {
#if BUILDFLAG(ENABLE_BRAVE_VPN)
auto* tab = tabs::TabInterface::GetFromContents(web_contents_);
CHECK(tab);
tab->GetBrowserWindowInterface()
->GetFeatures()
.GetBraveVPNController()
->ShowBraveVPNBubble(/* show_select */ true);
#endif
}

void BraveNewTabPageHandler::OpenVPNAccountPage() {
#if BUILDFLAG(ENABLE_BRAVE_VPN)
auto* tab = tabs::TabInterface::GetFromContents(web_contents_);
CHECK(tab);
tab->GetBrowserWindowInterface()
->GetFeatures()
.GetBraveVPNController()
->OpenVPNAccountPage();
#endif
}

bool BraveNewTabPageHandler::IsCustomBackgroundImageEnabled() const {
if (profile_->GetPrefs()->IsManagedPreference(GetThemePrefNameInMigration(
ThemePrefInMigration::kNtpCustomBackgroundDict))) {
Expand Down
3 changes: 3 additions & 0 deletions browser/ui/webui/new_tab_page/brave_new_tab_page_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ class BraveNewTabPageHandler : public brave_new_tab_page::mojom::PageHandler,
bool ctrl_key,
bool meta_key,
bool shift_key) override;
void RefreshVPNState() override;
void LaunchVPNPanel() override;
void OpenVPNAccountPage() override;

// Observe BraveNTPCustomBackgroundService.
void OnBackgroundUpdated();
Expand Down
38 changes: 38 additions & 0 deletions browser/ui/webui/new_tab_page/brave_new_tab_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "ui/webui/resources/cr_components/searchbox/searchbox.mojom.h"

#if BUILDFLAG(ENABLE_BRAVE_VPN)
#include "brave/browser/brave_vpn/brave_vpn_service_factory.h"
#include "brave/components/brave_vpn/browser/brave_vpn_service.h"
#include "brave/components/brave_vpn/common/brave_vpn_utils.h"
#endif

using ntp_background_images::NTPCustomImagesSource;

BraveNewTabUI::BraveNewTabUI(content::WebUI* web_ui, const std::string& name)
Expand Down Expand Up @@ -73,6 +79,17 @@ BraveNewTabUI::BraveNewTabUI(content::WebUI* web_ui, const std::string& name)

AddBackgroundColorToSource(source, web_contents);

// Lottie animations tick on a worker thread and requires the document CSP to
// be set to "worker-src blob: 'self';".
source->OverrideContentSecurityPolicy(
network::mojom::CSPDirectiveName::WorkerSrc,
"worker-src blob: chrome://resources 'self';");

source->OverrideContentSecurityPolicy(
network::mojom::CSPDirectiveName::TrustedTypes,
"trusted-types static-types lottie-worker-script-loader lit-html-desktop "
diracdeltas marked this conversation as resolved.
Show resolved Hide resolved
"default; ");

source->AddBoolean(
"featureCustomBackgroundEnabled",
!profile->GetPrefs()->IsManagedPreference(GetThemePrefNameInMigration(
Expand All @@ -91,6 +108,14 @@ BraveNewTabUI::BraveNewTabUI(content::WebUI* web_ui, const std::string& name)
"featureFlagSearchWidget",
base::FeatureList::IsEnabled(features::kBraveNtpSearchWidget));

source->AddBoolean("vpnWidgetSupported",
#if BUILDFLAG(ENABLE_BRAVE_VPN)
brave_vpn::IsBraveVPNFeatureEnabled()
#else
false
#endif
);

web_ui->AddMessageHandler(base::WrapUnique(
BraveNewTabMessageHandler::Create(source, profile, was_restored)));
web_ui->AddMessageHandler(
Expand Down Expand Up @@ -140,6 +165,19 @@ void BraveNewTabUI::BindInterface(
/*omnibox_controller=*/nullptr);
}

#if BUILDFLAG(ENABLE_BRAVE_VPN)
void BraveNewTabUI::BindInterface(
mojo::PendingReceiver<brave_vpn::mojom::ServiceHandler>
pending_vpn_service_handler) {
auto* profile = Profile::FromWebUI(web_ui());
CHECK(profile);
auto* vpn_service = brave_vpn::BraveVpnServiceFactory::GetForProfile(profile);
if (vpn_service) {
vpn_service->BindInterface(std::move(pending_vpn_service_handler));
}
}
#endif

void BraveNewTabUI::CreatePageHandler(
mojo::PendingRemote<brave_new_tab_page::mojom::Page> pending_page,
mojo::PendingReceiver<brave_new_tab_page::mojom::PageHandler>
Expand Down
10 changes: 10 additions & 0 deletions browser/ui/webui/new_tab_page/brave_new_tab_ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include "brave/components/brave_new_tab_ui/brave_new_tab_page.mojom.h"
#include "brave/components/brave_news/common/brave_news.mojom.h"
#include "brave/components/brave_vpn/common/buildflags/buildflags.h"
#include "chrome/browser/ui/webui/searchbox/realbox_handler.h"
#include "content/public/browser/web_ui_controller.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
Expand All @@ -19,6 +20,10 @@
#include "ui/webui/mojo_web_ui_controller.h"
#include "ui/webui/resources/cr_components/searchbox/searchbox.mojom.h"

#if BUILDFLAG(ENABLE_BRAVE_VPN)
#include "brave/components/brave_vpn/common/mojom/brave_vpn.mojom.h" // nogncheck
#endif

namespace brave_news {
class BraveNewsController;
} // namespace brave_news
Expand All @@ -45,6 +50,11 @@ class BraveNewTabUI : public ui::MojoWebUIController,
void BindInterface(mojo::PendingReceiver<searchbox::mojom::PageHandler>
pending_page_handler);

#if BUILDFLAG(ENABLE_BRAVE_VPN)
void BindInterface(mojo::PendingReceiver<brave_vpn::mojom::ServiceHandler>
pending_vpn_service_handler);
#endif

private:
// new_tab_page::mojom::PageHandlerFactory:
void CreatePageHandler(
Expand Down
1 change: 1 addition & 0 deletions components/brave_new_tab_ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ transpile_web_ui("brave_new_tab_ui") {
public_deps = [
":mojom_js",
"//brave/components/brave_news/common:mojom_js",
"//brave/components/brave_vpn/common/mojom:mojom_js",
]
if (!is_android && !is_ios) {
public_deps += [
Expand Down
21 changes: 21 additions & 0 deletions components/brave_new_tab_ui/actions/brave_vpn_actions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) 2024 The Brave Authors. All rights reserved.
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at https://mozilla.org/MPL/2.0/.

import { createAction } from 'redux-act'
import * as BraveVPN from '../api/braveVpn'

export const initialize = createAction<BraveVPN.PurchasedState>('initialize')
export const toggleConnection = createAction('toggleConnection')
export const launchVPNPanel = createAction('launchVPNPanel')
export const openVPNAccountPage = createAction('openVPNAccountPage')
export const purchasedStateChanged = createAction<BraveVPN.PurchasedState>(
'purchasedStateChanged'
)
export const connectionStateChanged = createAction<BraveVPN.ConnectionState>(
'connectionStateChanged'
)
export const selectedRegionChanged = createAction<BraveVPN.Region>(
'connectionStateChanged'
)
12 changes: 12 additions & 0 deletions components/brave_new_tab_ui/api/braveVpn.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (c) 2024 The Brave Authors. All rights reserved.
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at https://mozilla.org/MPL/2.0/.

import * as BraveVPN from 'gen/brave/components/brave_vpn/common/mojom/brave_vpn.mojom.m.js'
// Provide access to all the generated types
export * from 'gen/brave/components/brave_vpn/common/mojom/brave_vpn.mojom.m.js'

export default function getVPNServiceHandler () {
return BraveVPN.ServiceHandler.getRemote()
}
4 changes: 3 additions & 1 deletion components/brave_new_tab_ui/api/getActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import * as gridSitesActions from '../actions/grid_sites_actions'
import * as rewardsActions from '../actions/rewards_actions'
import * as stackWidgetActions from '../actions/stack_widget_actions'
import * as todayActions from '../actions/today_actions'
import * as braveVPNActions from '../actions/brave_vpn_actions'
import { NewTabActions } from '../constants/new_tab_types'
import store from '../store'

Expand All @@ -29,6 +30,7 @@ export function getActionsForDispatch (dispatch: Dispatch) {
const allActions = Object.assign({}, newTabActions, stackWidgetActions, gridSitesActions, rewardsActions)
return {
...bindActionCreators(allActions, dispatch),
today: bindActionCreators(todayActions, dispatch)
today: bindActionCreators(todayActions, dispatch),
braveVPN: bindActionCreators(braveVPNActions, dispatch)
}
}
18 changes: 16 additions & 2 deletions components/brave_new_tab_ui/api/initialData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import * as privateTabDataAPI from './privateTabData'
import * as wallpaper from './wallpaper'
import * as newTabAdsDataAPI from './newTabAdsData'
import getNTPBrowserAPI from './background'
import getVPNServiceHandler, * as BraveVPN from '../api/braveVpn'
import { loadTimeData } from '$web-common/loadTimeData'

export type InitialData = {
preferences: NewTab.Preferences
Expand All @@ -20,6 +22,7 @@ export type InitialData = {
braveRewardsSupported: boolean
braveTalkSupported: boolean
searchPromotionEnabled: boolean
purchasedState: BraveVPN.PurchasedState
}

export type PreInitialRewardsData = {
Expand Down Expand Up @@ -56,7 +59,8 @@ export async function getInitialData (): Promise<InitialData> {
braveTalkSupported,
searchPromotionEnabled,
braveBackgrounds,
customImageBackgrounds
customImageBackgrounds,
purchasedState
] = await Promise.all([
preferencesAPI.getPreferences(),
statsAPI.getStats(),
Expand All @@ -83,6 +87,15 @@ export async function getInitialData (): Promise<InitialData> {
}),
getNTPBrowserAPI().pageHandler.getCustomImageBackgrounds().then(({ backgrounds }) => {
return backgrounds.map(background => ({ type: 'image', wallpaperImageUrl: background.url.url }))
}),
new Promise((resolve) => {
if (loadTimeData.getBoolean('vpnWidgetSupported')) {
getVPNServiceHandler().getPurchasedState().then(({state}) => {
resolve(state.state)
})
} else {
resolve(BraveVPN.PurchasedState.NOT_PURCHASED)
}
})
])
console.timeStamp('Got all initial data.')
Expand All @@ -95,7 +108,8 @@ export async function getInitialData (): Promise<InitialData> {
customImageBackgrounds,
braveRewardsSupported,
braveTalkSupported,
searchPromotionEnabled
searchPromotionEnabled,
purchasedState
} as InitialData
} catch (e) {
console.error(e)
Expand Down
4 changes: 4 additions & 0 deletions components/brave_new_tab_ui/apiEventsToStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import * as newTabAdsDataAPI from './api/newTabAdsData'
import getNTPBrowserAPI, { Background, CustomBackground } from './api/background'
import { getInitialData, getRewardsInitialData, getRewardsPreInitialData } from './api/initialData'
import * as backgroundData from './data/backgrounds'
import { loadTimeData } from '$web-common/loadTimeData'

async function updatePreferences (prefData: NewTab.Preferences) {
getActions().preferencesUpdated(prefData)
Expand Down Expand Up @@ -71,6 +72,9 @@ export function wireApiEventsToStore () {
getNTPBrowserAPI().addBackgroundUpdatedListener(onBackgroundUpdated)
getNTPBrowserAPI().addCustomImageBackgroundsUpdatedListener(onCustomImageBackgroundsUpdated)
getNTPBrowserAPI().addSearchPromotionDisabledListener(() => getActions().searchPromotionDisabled())
if (loadTimeData.getBoolean('vpnWidgetSupported')) {
getActions().braveVPN.initialize(initialData.purchasedState)
}
})
.catch(e => {
console.error('New Tab Page fatal error:', e)
Expand Down
Loading
Loading