From 75b846b90fb0eba782cfecddc8263939f96e9e92 Mon Sep 17 00:00:00 2001 From: Alex Kontos Date: Wed, 6 Aug 2025 12:28:03 +0100 Subject: [PATCH] feat: enable custom wallpapers on about:newtab --- .../newtab/lib/WallpaperFeed.sys.mjs | 51 +++++++++++++++---- 1 file changed, 40 insertions(+), 11 deletions(-) diff --git a/browser/extensions/newtab/lib/WallpaperFeed.sys.mjs b/browser/extensions/newtab/lib/WallpaperFeed.sys.mjs index 3de340cf9c25..1875ea10e842 100644 --- a/browser/extensions/newtab/lib/WallpaperFeed.sys.mjs +++ b/browser/extensions/newtab/lib/WallpaperFeed.sys.mjs @@ -129,19 +129,22 @@ export class WallpaperFeed { } // retrieving all records in collection - const records = await this.wallpaperClient.get(); - if (!records?.length) { - return; - } + let records = []; + let baseAttachmentURL = ""; const customWallpaperEnabled = Services.prefs.getBoolPref( PREF_WALLPAPERS_CUSTOM_WALLPAPER_ENABLED ); - const baseAttachmentURL = await lazy.Utils.baseAttachmentsURL(); + const customColorEnabled = Services.prefs.getBoolPref( + "browser.newtabpage.activity-stream.newtabWallpapers.customColor.enabled" + ); - const wallpapers = [ - ...records.map(record => { + let wallpapers = []; + + // Process records if we have any + if (records && records.length > 0 && baseAttachmentURL) { + wallpapers = records.map(record => { return { ...record, ...(record.attachment @@ -151,16 +154,42 @@ export class WallpaperFeed { : {}), category: record.category || "", }; - }), - ]; + }); + } - const categories = [ + // Build categories + let categories = [ ...new Set( wallpapers.map(wallpaper => wallpaper.category).filter(Boolean) ), - ...(customWallpaperEnabled ? ["custom-wallpaper"] : []), // Conditionally add custom wallpaper input ]; + // Always add solid-colors if custom color is enabled and not already present + if (customColorEnabled && !categories.includes("solid-colors")) { + categories.push("solid-colors"); + + // Add default solid colors if we have no wallpapers + if (wallpapers.length === 0) { + wallpapers = [ + { title: "red-30", solid_color: "#ff7e8e", category: "solid-colors" }, + { title: "orange-30", solid_color: "#ff8f31", category: "solid-colors" }, + { title: "yellow-30", solid_color: "#f1af00", category: "solid-colors" }, + { title: "green-30", solid_color: "#61cc69", category: "solid-colors" }, + { title: "cyan-30", solid_color: "#00cadb", category: "solid-colors" }, + { title: "blue-30", solid_color: "#60adff", category: "solid-colors" }, + { title: "violet-30", solid_color: "#b295ff", category: "solid-colors"}, + { title: "purple-30", solid_color: "#d98dfa", category: "solid-colors"}, + { title: "pink-30", solid_color: "#ff7ead", category: "solid-colors"} + ]; + } + } + + // Always add custom-wallpaper if enabled + if (customWallpaperEnabled) { + categories.push("custom-wallpaper"); + } + + // Dispatch even with empty wallpapers as long as we have categories this.store.dispatch( ac.BroadcastToContent({ type: at.WALLPAPERS_SET,