tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit f5f1764e76f59751227a8bfcd9f4f138a4784682
parent fd81a764be34cd0a4b9720f33104e9c24eafda97
Author: scottdowne <sdowne@mozilla.com>
Date:   Wed, 22 Oct 2025 04:22:35 +0000

Bug 1995426 - Newtab migrate weather system pred from NImbus to TrainhopConfig r=reemhamz

Differential Revision: https://phabricator.services.mozilla.com/D269438

Diffstat:
Mbrowser/extensions/newtab/content-src/components/Base/Base.jsx | 3++-
Mbrowser/extensions/newtab/content-src/components/Weather/Weather.jsx | 12+++++++++---
Mbrowser/extensions/newtab/data/content/activity-stream.bundle.js | 14+++++++++++---
Mbrowser/extensions/newtab/lib/WeatherFeed.sys.mjs | 20+++++++++++++-------
4 files changed, 35 insertions(+), 14 deletions(-)

diff --git a/browser/extensions/newtab/content-src/components/Base/Base.jsx b/browser/extensions/newtab/content-src/components/Base/Base.jsx @@ -656,7 +656,8 @@ export class BaseContent extends React.PureComponent { const pocketRegion = prefs["feeds.system.topstories"]; const mayHaveInferredPersonalization = prefs[PREF_INFERRED_PERSONALIZATION_SYSTEM]; - const mayHaveWeather = prefs["system.showWeather"]; + const mayHaveWeather = + prefs["system.showWeather"] || prefs.trainhopConfig?.weather?.enabled; const supportUrl = prefs["support.url"]; // Weather can be enabled and not rendered in the top right corner diff --git a/browser/extensions/newtab/content-src/components/Weather/Weather.jsx b/browser/extensions/newtab/content-src/components/Weather/Weather.jsx @@ -11,6 +11,7 @@ import React, { useState } from "react"; const VISIBLE = "visible"; const VISIBILITY_CHANGE_EVENT = "visibilitychange"; +const PREF_SYSTEM_SHOW_WEATHER = "system.showWeather"; function WeatherPlaceholder() { const [isSeen, setIsSeen] = useState(false); @@ -242,11 +243,16 @@ export class _Weather extends React.PureComponent { }); }; + isEnabled() { + const { values } = this.props.Prefs; + const systemValue = values[PREF_SYSTEM_SHOW_WEATHER]; + const experimentValue = values.trainhopConfig?.weather?.enabled; + return systemValue || experimentValue; + } + render() { // Check if weather should be rendered - const isWeatherEnabled = this.props.Prefs.values["system.showWeather"]; - - if (!isWeatherEnabled) { + if (!this.isEnabled()) { return false; } diff --git a/browser/extensions/newtab/data/content/activity-stream.bundle.js b/browser/extensions/newtab/data/content/activity-stream.bundle.js @@ -11521,6 +11521,7 @@ function LocationSearch({ const Weather_VISIBLE = "visible"; const Weather_VISIBILITY_CHANGE_EVENT = "visibilitychange"; +const PREF_SYSTEM_SHOW_WEATHER = "system.showWeather"; function WeatherPlaceholder() { const [isSeen, setIsSeen] = (0,external_React_namespaceObject.useState)(false); @@ -11706,10 +11707,17 @@ class _Weather extends (external_React_default()).PureComponent { })); }); }; + isEnabled() { + const { + values + } = this.props.Prefs; + const systemValue = values[PREF_SYSTEM_SHOW_WEATHER]; + const experimentValue = values.trainhopConfig?.weather?.enabled; + return systemValue || experimentValue; + } render() { // Check if weather should be rendered - const isWeatherEnabled = this.props.Prefs.values["system.showWeather"]; - if (!isWeatherEnabled) { + if (!this.isEnabled()) { return false; } if (this.props.App.isForStartupCache.Weather || !this.props.Weather.initialized) { @@ -16806,7 +16814,7 @@ class BaseContent extends (external_React_default()).PureComponent { }; const pocketRegion = prefs["feeds.system.topstories"]; const mayHaveInferredPersonalization = prefs[PREF_INFERRED_PERSONALIZATION_SYSTEM]; - const mayHaveWeather = prefs["system.showWeather"]; + const mayHaveWeather = prefs["system.showWeather"] || prefs.trainhopConfig?.weather?.enabled; const supportUrl = prefs["support.url"]; // Weather can be enabled and not rendered in the top right corner diff --git a/browser/extensions/newtab/lib/WeatherFeed.sys.mjs b/browser/extensions/newtab/lib/WeatherFeed.sys.mjs @@ -67,13 +67,15 @@ export class WeatherFeed { await this.resetCache(); this.suggestions = []; this.lastUpdated = null; + this.loaded = false; } isEnabled() { - return ( - this.store.getState().Prefs.values[PREF_SHOW_WEATHER] && - this.store.getState().Prefs.values[PREF_SYSTEM_SHOW_WEATHER] - ); + const { values } = this.store.getState().Prefs; + const userValue = values[PREF_SHOW_WEATHER]; + const systemValue = values[PREF_SYSTEM_SHOW_WEATHER]; + const experimentValue = values.trainhopConfig?.weather?.enabled || false; + return userValue && (systemValue || experimentValue); } async init() { @@ -176,6 +178,7 @@ export class WeatherFeed { this.lastUpdated = weather.lastUpdated; this.update(); } + this.loaded = true; } update() { @@ -266,12 +269,15 @@ export class WeatherFeed { break; case PREF_SHOW_WEATHER: case PREF_SYSTEM_SHOW_WEATHER: - if (this.isEnabled() && action.data.value) { + case "trainhopConfig": { + const enabled = this.isEnabled(); + if (enabled && !this.loaded) { await this.loadWeather(); - } else { + } else if (!enabled && this.loaded) { await this.resetWeather(); } break; + } } } @@ -287,7 +293,7 @@ export class WeatherFeed { switch (action.type) { case at.INIT: await this.checkOptInRegion(); - if (this.isEnabled()) { + if (this.isEnabled() && !this.loaded) { await this.init(); } break;