summaryrefslogtreecommitdiffstats
path: root/browser/components/newtab/lib
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-15 03:35:49 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-15 03:35:49 +0000
commitd8bbc7858622b6d9c278469aab701ca0b609cddf (patch)
treeeff41dc61d9f714852212739e6b3738b82a2af87 /browser/components/newtab/lib
parentReleasing progress-linux version 125.0.3-1~progress7.99u1. (diff)
downloadfirefox-d8bbc7858622b6d9c278469aab701ca0b609cddf.tar.xz
firefox-d8bbc7858622b6d9c278469aab701ca0b609cddf.zip
Merging upstream version 126.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'browser/components/newtab/lib')
-rw-r--r--browser/components/newtab/lib/AboutPreferences.sys.mjs2
-rw-r--r--browser/components/newtab/lib/ActivityStream.sys.mjs30
-rw-r--r--browser/components/newtab/lib/ActivityStreamMessageChannel.sys.mjs2
-rw-r--r--browser/components/newtab/lib/DiscoveryStreamFeed.sys.mjs39
-rw-r--r--browser/components/newtab/lib/DownloadsManager.sys.mjs2
-rw-r--r--browser/components/newtab/lib/FaviconFeed.sys.mjs2
-rw-r--r--browser/components/newtab/lib/HighlightsFeed.sys.mjs2
-rw-r--r--browser/components/newtab/lib/NewTabInit.sys.mjs2
-rw-r--r--browser/components/newtab/lib/PlacesFeed.sys.mjs2
-rw-r--r--browser/components/newtab/lib/PrefsFeed.sys.mjs2
-rw-r--r--browser/components/newtab/lib/RecommendationProvider.sys.mjs2
-rw-r--r--browser/components/newtab/lib/SectionsManager.sys.mjs4
-rw-r--r--browser/components/newtab/lib/SystemTickFeed.sys.mjs2
-rw-r--r--browser/components/newtab/lib/TelemetryFeed.sys.mjs49
-rw-r--r--browser/components/newtab/lib/TopSitesFeed.sys.mjs2
-rw-r--r--browser/components/newtab/lib/TopStoriesFeed.sys.mjs2
-rw-r--r--browser/components/newtab/lib/WallpaperFeed.sys.mjs117
17 files changed, 232 insertions, 31 deletions
diff --git a/browser/components/newtab/lib/AboutPreferences.sys.mjs b/browser/components/newtab/lib/AboutPreferences.sys.mjs
index 33f7ecdaeb..08e0ca422a 100644
--- a/browser/components/newtab/lib/AboutPreferences.sys.mjs
+++ b/browser/components/newtab/lib/AboutPreferences.sys.mjs
@@ -5,7 +5,7 @@
import {
actionTypes as at,
actionCreators as ac,
-} from "resource://activity-stream/common/Actions.sys.mjs";
+} from "resource://activity-stream/common/Actions.mjs";
const HTML_NS = "http://www.w3.org/1999/xhtml";
export const PREFERENCES_LOADED_EVENT = "home-pane-loaded";
diff --git a/browser/components/newtab/lib/ActivityStream.sys.mjs b/browser/components/newtab/lib/ActivityStream.sys.mjs
index f46e8aadf0..fa2d011f11 100644
--- a/browser/components/newtab/lib/ActivityStream.sys.mjs
+++ b/browser/components/newtab/lib/ActivityStream.sys.mjs
@@ -36,6 +36,7 @@ ChromeUtils.defineESModuleGetters(lazy, {
TelemetryFeed: "resource://activity-stream/lib/TelemetryFeed.sys.mjs",
TopSitesFeed: "resource://activity-stream/lib/TopSitesFeed.sys.mjs",
TopStoriesFeed: "resource://activity-stream/lib/TopStoriesFeed.sys.mjs",
+ WallpaperFeed: "resource://activity-stream/lib/WallpaperFeed.sys.mjs",
});
// NB: Eagerly load modules that will be loaded/constructed/initialized in the
@@ -43,7 +44,7 @@ ChromeUtils.defineESModuleGetters(lazy, {
import {
actionCreators as ac,
actionTypes as at,
-} from "resource://activity-stream/common/Actions.sys.mjs";
+} from "resource://activity-stream/common/Actions.mjs";
const REGION_BASIC_CONFIG =
"browser.newtabpage.activity-stream.discoverystream.region-basic-config";
@@ -233,6 +234,27 @@ export const PREFS_CONFIG = new Map([
},
],
[
+ "newtabWallpapers.enabled",
+ {
+ title: "Boolean flag to turn wallpaper functionality on and off",
+ value: true,
+ },
+ ],
+ [
+ "newtabWallpapers.wallpaper-light",
+ {
+ title: "Currently set light wallpaper",
+ value: "",
+ },
+ ],
+ [
+ "newtabWallpapers.wallpaper-dark",
+ {
+ title: "Currently set dark wallpaper",
+ value: "",
+ },
+ ],
+ [
"improvesearch.noDefaultSearchTile",
{
title: "Remove tiles that are the same as the default search",
@@ -524,6 +546,12 @@ const FEEDS_DATA = [
title: "Handles new pocket ui for the new tab page",
value: true,
},
+ {
+ name: "wallpaperfeed",
+ factory: () => new lazy.WallpaperFeed(),
+ title: "Handles fetching and managing wallpaper data from RemoteSettings",
+ value: true,
+ },
];
const FEEDS_CONFIG = new Map();
diff --git a/browser/components/newtab/lib/ActivityStreamMessageChannel.sys.mjs b/browser/components/newtab/lib/ActivityStreamMessageChannel.sys.mjs
index 5392a421ca..3cb81b4793 100644
--- a/browser/components/newtab/lib/ActivityStreamMessageChannel.sys.mjs
+++ b/browser/components/newtab/lib/ActivityStreamMessageChannel.sys.mjs
@@ -13,7 +13,7 @@ import {
actionCreators as ac,
actionTypes as at,
actionUtils as au,
-} from "resource://activity-stream/common/Actions.sys.mjs";
+} from "resource://activity-stream/common/Actions.mjs";
const ABOUT_NEW_TAB_URL = "about:newtab";
diff --git a/browser/components/newtab/lib/DiscoveryStreamFeed.sys.mjs b/browser/components/newtab/lib/DiscoveryStreamFeed.sys.mjs
index ee08462503..bff9f1e04e 100644
--- a/browser/components/newtab/lib/DiscoveryStreamFeed.sys.mjs
+++ b/browser/components/newtab/lib/DiscoveryStreamFeed.sys.mjs
@@ -26,7 +26,7 @@ const { setTimeout, clearTimeout } = ChromeUtils.importESModule(
import {
actionTypes as at,
actionCreators as ac,
-} from "resource://activity-stream/common/Actions.sys.mjs";
+} from "resource://activity-stream/common/Actions.mjs";
const CACHE_KEY = "discovery_stream";
const STARTUP_CACHE_EXPIRE_TIME = 7 * 24 * 60 * 60 * 1000; // 1 week
@@ -565,8 +565,8 @@ export class DiscoveryStreamFeed {
generateFeedUrl(isBff) {
if (isBff) {
- return `https://${lazy.NimbusFeatures.saveToPocket.getVariable(
- "bffApi"
+ return `https://${Services.prefs.getStringPref(
+ "extensions.pocket.bffApi"
)}/desktop/v1/recommendations?locale=$locale&region=$region&count=30`;
}
return FEED_URL;
@@ -986,8 +986,9 @@ export class DiscoveryStreamFeed {
});
if (spocsResponse) {
+ const fetchTimestamp = Date.now();
spocsState = {
- lastUpdated: Date.now(),
+ lastUpdated: fetchTimestamp,
spocs: {
...spocsResponse,
},
@@ -1050,8 +1051,13 @@ export class DiscoveryStreamFeed {
const { data: blockedResults } = this.filterBlocked(capResult);
+ const { data: spocsWithFetchTimestamp } = this.addFetchTimestamp(
+ blockedResults,
+ fetchTimestamp
+ );
+
const { data: scoredResults, personalized } =
- await this.scoreItems(blockedResults, "spocs");
+ await this.scoreItems(spocsWithFetchTimestamp, "spocs");
spocsState.spocs = {
...spocsState.spocs,
@@ -1209,6 +1215,22 @@ export class DiscoveryStreamFeed {
return { data };
}
+ // Add the fetch timestamp property to each spoc returned to communicate how
+ // old the spoc is in telemetry when it is used by the client
+ addFetchTimestamp(spocs, fetchTimestamp) {
+ if (spocs && spocs.length) {
+ return {
+ data: spocs.map(s => {
+ return {
+ ...s,
+ fetchTimestamp,
+ };
+ }),
+ };
+ }
+ return { data: spocs };
+ }
+
// For backwards compatibility, older spoc endpoint don't have flight_id,
// but instead had campaign_id we can use
//
@@ -1334,8 +1356,8 @@ export class DiscoveryStreamFeed {
let options = {};
if (this.isBff) {
const headers = new Headers();
- const oAuthConsumerKey = lazy.NimbusFeatures.saveToPocket.getVariable(
- "oAuthConsumerKeyBff"
+ const oAuthConsumerKey = Services.prefs.getStringPref(
+ "extensions.pocket.oAuthConsumerKeyBff"
);
headers.append("consumer_key", oAuthConsumerKey);
options = {
@@ -1768,7 +1790,7 @@ export class DiscoveryStreamFeed {
break;
// Check if spocs was disabled. Remove them if they were.
case PREF_SHOW_SPONSORED:
- case PREF_SHOW_SPONSORED_TOPSITES:
+ case PREF_SHOW_SPONSORED_TOPSITES: {
const dispatch = update =>
this.store.dispatch(ac.BroadcastToContent(update));
// We refresh placements data because one of the spocs were turned off.
@@ -1794,6 +1816,7 @@ export class DiscoveryStreamFeed {
await this.cache.set("spocs", {});
await this.loadSpocs(dispatch);
break;
+ }
}
}
diff --git a/browser/components/newtab/lib/DownloadsManager.sys.mjs b/browser/components/newtab/lib/DownloadsManager.sys.mjs
index a9a57222ee..f6e99e462a 100644
--- a/browser/components/newtab/lib/DownloadsManager.sys.mjs
+++ b/browser/components/newtab/lib/DownloadsManager.sys.mjs
@@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
-import { actionTypes as at } from "resource://activity-stream/common/Actions.sys.mjs";
+import { actionTypes as at } from "resource://activity-stream/common/Actions.mjs";
const lazy = {};
diff --git a/browser/components/newtab/lib/FaviconFeed.sys.mjs b/browser/components/newtab/lib/FaviconFeed.sys.mjs
index a76566d3e8..18c2231f58 100644
--- a/browser/components/newtab/lib/FaviconFeed.sys.mjs
+++ b/browser/components/newtab/lib/FaviconFeed.sys.mjs
@@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-import { actionTypes as at } from "resource://activity-stream/common/Actions.sys.mjs";
+import { actionTypes as at } from "resource://activity-stream/common/Actions.mjs";
import { getDomain } from "resource://activity-stream/lib/TippyTopProvider.sys.mjs";
// We use importESModule here instead of static import so that
diff --git a/browser/components/newtab/lib/HighlightsFeed.sys.mjs b/browser/components/newtab/lib/HighlightsFeed.sys.mjs
index c603b886da..00eb109896 100644
--- a/browser/components/newtab/lib/HighlightsFeed.sys.mjs
+++ b/browser/components/newtab/lib/HighlightsFeed.sys.mjs
@@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-import { actionTypes as at } from "resource://activity-stream/common/Actions.sys.mjs";
+import { actionTypes as at } from "resource://activity-stream/common/Actions.mjs";
import { shortURL } from "resource://activity-stream/lib/ShortURL.sys.mjs";
import {
diff --git a/browser/components/newtab/lib/NewTabInit.sys.mjs b/browser/components/newtab/lib/NewTabInit.sys.mjs
index db30e009ec..768cc29ea4 100644
--- a/browser/components/newtab/lib/NewTabInit.sys.mjs
+++ b/browser/components/newtab/lib/NewTabInit.sys.mjs
@@ -5,7 +5,7 @@
import {
actionCreators as ac,
actionTypes as at,
-} from "resource://activity-stream/common/Actions.sys.mjs";
+} from "resource://activity-stream/common/Actions.mjs";
/**
* NewTabInit - A placeholder for now. This will send a copy of the state to all
diff --git a/browser/components/newtab/lib/PlacesFeed.sys.mjs b/browser/components/newtab/lib/PlacesFeed.sys.mjs
index 70011412f8..85679153bd 100644
--- a/browser/components/newtab/lib/PlacesFeed.sys.mjs
+++ b/browser/components/newtab/lib/PlacesFeed.sys.mjs
@@ -6,7 +6,7 @@ import {
actionCreators as ac,
actionTypes as at,
actionUtils as au,
-} from "resource://activity-stream/common/Actions.sys.mjs";
+} from "resource://activity-stream/common/Actions.mjs";
import { shortURL } from "resource://activity-stream/lib/ShortURL.sys.mjs";
diff --git a/browser/components/newtab/lib/PrefsFeed.sys.mjs b/browser/components/newtab/lib/PrefsFeed.sys.mjs
index bb2502ac55..4cb41c0421 100644
--- a/browser/components/newtab/lib/PrefsFeed.sys.mjs
+++ b/browser/components/newtab/lib/PrefsFeed.sys.mjs
@@ -5,7 +5,7 @@
import {
actionCreators as ac,
actionTypes as at,
-} from "resource://activity-stream/common/Actions.sys.mjs";
+} from "resource://activity-stream/common/Actions.mjs";
import { Prefs } from "resource://activity-stream/lib/ActivityStreamPrefs.sys.mjs";
// We use importESModule here instead of static import so that
diff --git a/browser/components/newtab/lib/RecommendationProvider.sys.mjs b/browser/components/newtab/lib/RecommendationProvider.sys.mjs
index 875c90492b..9fd6b71656 100644
--- a/browser/components/newtab/lib/RecommendationProvider.sys.mjs
+++ b/browser/components/newtab/lib/RecommendationProvider.sys.mjs
@@ -12,7 +12,7 @@ ChromeUtils.defineESModuleGetters(lazy, {
import {
actionTypes as at,
actionCreators as ac,
-} from "resource://activity-stream/common/Actions.sys.mjs";
+} from "resource://activity-stream/common/Actions.mjs";
const CACHE_KEY = "personalization";
const PREF_PERSONALIZATION_MODEL_KEYS =
diff --git a/browser/components/newtab/lib/SectionsManager.sys.mjs b/browser/components/newtab/lib/SectionsManager.sys.mjs
index 069ddbb224..a1634e0d47 100644
--- a/browser/components/newtab/lib/SectionsManager.sys.mjs
+++ b/browser/components/newtab/lib/SectionsManager.sys.mjs
@@ -15,7 +15,7 @@ const { EventEmitter } = ChromeUtils.importESModule(
import {
actionCreators as ac,
actionTypes as at,
-} from "resource://activity-stream/common/Actions.sys.mjs";
+} from "resource://activity-stream/common/Actions.mjs";
import { getDefaultOptions } from "resource://activity-stream/lib/ActivityStreamStorage.sys.mjs";
const lazy = {};
@@ -389,7 +389,7 @@ export const SectionsManager = {
/**
* Sets each card in highlights' context menu options based on the card's type.
- * (See types.js for a list of types)
+ * (See types.mjs for a list of types)
*
* @param rows section rows containing a type for each card
*/
diff --git a/browser/components/newtab/lib/SystemTickFeed.sys.mjs b/browser/components/newtab/lib/SystemTickFeed.sys.mjs
index d87860fab2..fdbbda3ddd 100644
--- a/browser/components/newtab/lib/SystemTickFeed.sys.mjs
+++ b/browser/components/newtab/lib/SystemTickFeed.sys.mjs
@@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-import { actionTypes as at } from "resource://activity-stream/common/Actions.sys.mjs";
+import { actionTypes as at } from "resource://activity-stream/common/Actions.mjs";
const lazy = {};
diff --git a/browser/components/newtab/lib/TelemetryFeed.sys.mjs b/browser/components/newtab/lib/TelemetryFeed.sys.mjs
index 1a9e9e3d34..6cf4dba4ab 100644
--- a/browser/components/newtab/lib/TelemetryFeed.sys.mjs
+++ b/browser/components/newtab/lib/TelemetryFeed.sys.mjs
@@ -18,13 +18,13 @@ const { XPCOMUtils } = ChromeUtils.importESModule(
// eslint-disable-next-line mozilla/use-static-import
const { MESSAGE_TYPE_HASH: msg } = ChromeUtils.importESModule(
- "resource:///modules/asrouter/ActorConstants.sys.mjs"
+ "resource:///modules/asrouter/ActorConstants.mjs"
);
import {
actionTypes as at,
actionUtils as au,
-} from "resource://activity-stream/common/Actions.sys.mjs";
+} from "resource://activity-stream/common/Actions.mjs";
import { Prefs } from "resource://activity-stream/lib/ActivityStreamPrefs.sys.mjs";
import { classifySite } from "resource://activity-stream/lib/SiteClassifier.sys.mjs";
@@ -454,8 +454,7 @@ export class TelemetryFeed {
event = await this.applyCFRPolicy(event);
break;
case "badge_user_event":
- case "whats-new-panel_user_event":
- event = await this.applyWhatsNewPolicy(event);
+ event = await this.applyToolbarBadgePolicy(event);
break;
case "infobar_user_event":
event = await this.applyInfoBarPolicy(event);
@@ -509,12 +508,12 @@ export class TelemetryFeed {
* Per Bug 1482134, all the metrics for What's New panel use client_id in
* all the release channels
*/
- async applyWhatsNewPolicy(ping) {
+ async applyToolbarBadgePolicy(ping) {
ping.client_id = await this.telemetryClientId;
ping.browser_session_id = lazy.browserSessionId;
// Attach page info to `event_context` if there is a session associated with this ping
delete ping.action;
- return { ping, pingType: "whats-new-panel" };
+ return { ping, pingType: "toolbar-badge" };
}
async applyInfoBarPolicy(ping) {
@@ -715,8 +714,16 @@ export class TelemetryFeed {
const session = this.sessions.get(au.getPortIdOfSender(action));
switch (action.data?.event) {
case "CLICK": {
- const { card_type, topic, recommendation_id, tile_id, shim, feature } =
- action.data.value ?? {};
+ const {
+ card_type,
+ topic,
+ recommendation_id,
+ tile_id,
+ shim,
+ fetchTimestamp,
+ firstVisibleTimestamp,
+ feature,
+ } = action.data.value ?? {};
if (
action.data.source === "POPULAR_TOPICS" ||
card_type === "topics_widget"
@@ -740,6 +747,14 @@ export class TelemetryFeed {
});
if (shim) {
Glean.pocket.shim.set(shim);
+ if (fetchTimestamp) {
+ Glean.pocket.fetchTimestamp.set(fetchTimestamp * 1000);
+ }
+ if (firstVisibleTimestamp) {
+ Glean.pocket.newtabCreationTimestamp.set(
+ firstVisibleTimestamp * 1000
+ );
+ }
GleanPings.spoc.submit("click");
}
}
@@ -755,6 +770,16 @@ export class TelemetryFeed {
});
if (action.data.value?.shim) {
Glean.pocket.shim.set(action.data.value.shim);
+ if (action.data.value.fetchTimestamp) {
+ Glean.pocket.fetchTimestamp.set(
+ action.data.value.fetchTimestamp * 1000
+ );
+ }
+ if (action.data.value.newtabCreationTimestamp) {
+ Glean.pocket.newtabCreationTimestamp.set(
+ action.data.value.newtabCreationTimestamp * 1000
+ );
+ }
GleanPings.spoc.submit("save");
}
break;
@@ -976,6 +1001,14 @@ export class TelemetryFeed {
});
if (tile.shim) {
Glean.pocket.shim.set(tile.shim);
+ if (tile.fetchTimestamp) {
+ Glean.pocket.fetchTimestamp.set(tile.fetchTimestamp * 1000);
+ }
+ if (data.firstVisibleTimestamp) {
+ Glean.pocket.newtabCreationTimestamp.set(
+ data.firstVisibleTimestamp * 1000
+ );
+ }
GleanPings.spoc.submit("impression");
}
});
diff --git a/browser/components/newtab/lib/TopSitesFeed.sys.mjs b/browser/components/newtab/lib/TopSitesFeed.sys.mjs
index 796211085b..e259253402 100644
--- a/browser/components/newtab/lib/TopSitesFeed.sys.mjs
+++ b/browser/components/newtab/lib/TopSitesFeed.sys.mjs
@@ -5,7 +5,7 @@
import {
actionCreators as ac,
actionTypes as at,
-} from "resource://activity-stream/common/Actions.sys.mjs";
+} from "resource://activity-stream/common/Actions.mjs";
import { TippyTopProvider } from "resource://activity-stream/lib/TippyTopProvider.sys.mjs";
import {
insertPinned,
diff --git a/browser/components/newtab/lib/TopStoriesFeed.sys.mjs b/browser/components/newtab/lib/TopStoriesFeed.sys.mjs
index be030649dd..5986209a1c 100644
--- a/browser/components/newtab/lib/TopStoriesFeed.sys.mjs
+++ b/browser/components/newtab/lib/TopStoriesFeed.sys.mjs
@@ -5,7 +5,7 @@
import {
actionTypes as at,
actionCreators as ac,
-} from "resource://activity-stream/common/Actions.sys.mjs";
+} from "resource://activity-stream/common/Actions.mjs";
import { Prefs } from "resource://activity-stream/lib/ActivityStreamPrefs.sys.mjs";
import { shortURL } from "resource://activity-stream/lib/ShortURL.sys.mjs";
import { SectionsManager } from "resource://activity-stream/lib/SectionsManager.sys.mjs";
diff --git a/browser/components/newtab/lib/WallpaperFeed.sys.mjs b/browser/components/newtab/lib/WallpaperFeed.sys.mjs
new file mode 100644
index 0000000000..cb21311ddc
--- /dev/null
+++ b/browser/components/newtab/lib/WallpaperFeed.sys.mjs
@@ -0,0 +1,117 @@
+/* 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/. */
+
+const lazy = {};
+ChromeUtils.defineESModuleGetters(lazy, {
+ RemoteSettings: "resource://services-settings/remote-settings.sys.mjs",
+ Utils: "resource://services-settings/Utils.sys.mjs",
+});
+
+import {
+ actionTypes as at,
+ actionCreators as ac,
+} from "resource://activity-stream/common/Actions.mjs";
+
+const PREF_WALLPAPERS_ENABLED =
+ "browser.newtabpage.activity-stream.newtabWallpapers.enabled";
+
+export class WallpaperFeed {
+ constructor() {
+ this.loaded = false;
+ this.wallpaperClient = "";
+ this.wallpaperDB = "";
+ this.baseAttachmentURL = "";
+ }
+
+ /**
+ * This thin wrapper around global.fetch makes it easier for us to write
+ * automated tests that simulate responses from this fetch.
+ */
+ fetch(...args) {
+ return fetch(...args);
+ }
+
+ /**
+ * This thin wrapper around lazy.RemoteSettings makes it easier for us to write
+ * automated tests that simulate responses from this fetch.
+ */
+ RemoteSettings(...args) {
+ return lazy.RemoteSettings(...args);
+ }
+
+ async wallpaperSetup(isStartup = false) {
+ const wallpapersEnabled = Services.prefs.getBoolPref(
+ PREF_WALLPAPERS_ENABLED
+ );
+
+ if (wallpapersEnabled) {
+ if (!this.wallpaperClient) {
+ this.wallpaperClient = this.RemoteSettings("newtab-wallpapers");
+ }
+
+ await this.getBaseAttachment();
+ this.wallpaperClient.on("sync", () => this.updateWallpapers());
+ this.updateWallpapers(isStartup);
+ }
+ }
+
+ async getBaseAttachment() {
+ if (!this.baseAttachmentURL) {
+ const SERVER = lazy.Utils.SERVER_URL;
+ const serverInfo = await (
+ await this.fetch(`${SERVER}/`, {
+ credentials: "omit",
+ })
+ ).json();
+ const { base_url } = serverInfo.capabilities.attachments;
+ this.baseAttachmentURL = base_url;
+ }
+ }
+
+ async updateWallpapers(isStartup = false) {
+ const records = await this.wallpaperClient.get();
+ if (!records?.length) {
+ return;
+ }
+
+ if (!this.baseAttachmentURL) {
+ await this.getBaseAttachment();
+ }
+ const wallpapers = records.map(record => {
+ return {
+ ...record,
+ wallpaperUrl: `${this.baseAttachmentURL}${record.attachment.location}`,
+ };
+ });
+
+ this.store.dispatch(
+ ac.BroadcastToContent({
+ type: at.WALLPAPERS_SET,
+ data: wallpapers,
+ meta: {
+ isStartup,
+ },
+ })
+ );
+ }
+
+ async onAction(action) {
+ switch (action.type) {
+ case at.INIT:
+ await this.wallpaperSetup(true /* isStartup */);
+ break;
+ case at.UNINIT:
+ break;
+ case at.SYSTEM_TICK:
+ break;
+ case at.PREF_CHANGED:
+ if (action.data.name === "newtabWallpapers.enabled") {
+ await this.wallpaperSetup(false /* isStartup */);
+ }
+ break;
+ case at.WALLPAPERS_SET:
+ break;
+ }
+ }
+}