feat: enable custom wallpapers on about:newtab
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user