mirror of
https://github.com/mue/mue.git
synced 2026-06-08 14:10:42 +02:00
chore: remove migrations for background
This commit is contained in:
@@ -24,12 +24,13 @@ export async function fetchAPIImageData(excludedPun = null) {
|
|||||||
const baseURL = `${variables.constants.API_URL}/images`;
|
const baseURL = `${variables.constants.API_URL}/images`;
|
||||||
const collection = localStorage.getItem('unsplashCollections');
|
const collection = localStorage.getItem('unsplashCollections');
|
||||||
|
|
||||||
const url = (api === 'unsplash' || api === 'pexels')
|
const url =
|
||||||
|
api === 'unsplash' || api === 'pexels'
|
||||||
? `${baseURL}/unsplash?${collection ? `collections=${collection}` : `categories=${categories || ''}`}&quality=${quality}`
|
? `${baseURL}/unsplash?${collection ? `collections=${collection}` : `categories=${categories || ''}`}&quality=${quality}`
|
||||||
: `${baseURL}/random?categories=${categories || ''}&quality=${quality}&excludes=${excludes}`;
|
: `${baseURL}/random?categories=${categories || ''}&quality=${quality}&excludes=${excludes}`;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const accept = `application/json, ${await supportsAVIF() ? 'image/avif' : 'image/webp'}`;
|
const accept = `application/json, ${(await supportsAVIF()) ? 'image/avif' : 'image/webp'}`;
|
||||||
const data = await (await fetch(url, { headers: { accept } })).json();
|
const data = await (await fetch(url, { headers: { accept } })).json();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -66,7 +67,9 @@ export async function fetchAPIImageData(excludedPun = null) {
|
|||||||
* Gets background data based on current configuration
|
* Gets background data based on current configuration
|
||||||
*/
|
*/
|
||||||
export async function getBackgroundData() {
|
export async function getBackgroundData() {
|
||||||
const isOffline = localStorage.getItem('offlineMode') === 'true' || localStorage.getItem('showWelcome') === 'true';
|
const isOffline =
|
||||||
|
localStorage.getItem('offlineMode') === 'true' ||
|
||||||
|
localStorage.getItem('showWelcome') === 'true';
|
||||||
|
|
||||||
// Handle favourited background
|
// Handle favourited background
|
||||||
const fav = parseJSON('favourite');
|
const fav = parseJSON('favourite');
|
||||||
@@ -105,19 +108,10 @@ export async function getBackgroundData() {
|
|||||||
* Gets solid colour background
|
* Gets solid colour background
|
||||||
*/
|
*/
|
||||||
function getColourBackground() {
|
function getColourBackground() {
|
||||||
let colour = localStorage.getItem('customBackgroundColour');
|
return {
|
||||||
|
type: 'colour',
|
||||||
// Migrate legacy format
|
style: `background: ${localStorage.getItem('customBackgroundColour') || 'rgb(0,0,0)'}`,
|
||||||
if (colour?.startsWith('{')) {
|
};
|
||||||
try {
|
|
||||||
colour = JSON.parse(colour).gradient[0].colour;
|
|
||||||
localStorage.setItem('customBackgroundColour', colour);
|
|
||||||
} catch {
|
|
||||||
colour = 'rgb(0,0,0)';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return { type: 'colour', style: `background: ${colour || 'rgb(0,0,0)'}` };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -128,7 +122,7 @@ async function getAPIBackground(isOffline) {
|
|||||||
|
|
||||||
// Use cached next image if available
|
// Use cached next image if available
|
||||||
const cached = parseJSON('nextImage');
|
const cached = parseJSON('nextImage');
|
||||||
const data = cached || await fetchAPIImageData();
|
const data = cached || (await fetchAPIImageData());
|
||||||
|
|
||||||
if (!data) return getOfflineImage('api');
|
if (!data) return getOfflineImage('api');
|
||||||
|
|
||||||
@@ -149,13 +143,6 @@ async function getAPIBackground(isOffline) {
|
|||||||
function getCustomBackground(isOffline) {
|
function getCustomBackground(isOffline) {
|
||||||
let backgrounds = parseJSON('customBackground');
|
let backgrounds = parseJSON('customBackground');
|
||||||
|
|
||||||
// Migrate legacy format
|
|
||||||
if (!Array.isArray(backgrounds)) {
|
|
||||||
const saved = localStorage.getItem('customBackground');
|
|
||||||
backgrounds = saved ? [saved] : [];
|
|
||||||
localStorage.setItem('customBackground', JSON.stringify(backgrounds));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (backgrounds.length === 0) return null;
|
if (backgrounds.length === 0) return null;
|
||||||
|
|
||||||
const selected = backgrounds[Math.floor(Math.random() * backgrounds.length)];
|
const selected = backgrounds[Math.floor(Math.random() * backgrounds.length)];
|
||||||
@@ -180,14 +167,15 @@ function getPhotoPackBackground(isOffline) {
|
|||||||
if (isOffline) return getOfflineImage('photo_pack');
|
if (isOffline) return getOfflineImage('photo_pack');
|
||||||
|
|
||||||
const photos = parseJSON('installed', []).flatMap((item) =>
|
const photos = parseJSON('installed', []).flatMap((item) =>
|
||||||
item.type === 'photos' && item.photos ? item.photos : []
|
item.type === 'photos' && item.photos ? item.photos : [],
|
||||||
);
|
);
|
||||||
|
|
||||||
if (photos.length === 0) return null;
|
if (photos.length === 0) return null;
|
||||||
|
|
||||||
const interval = localStorage.getItem('backgroundchange');
|
const interval = localStorage.getItem('backgroundchange');
|
||||||
const startTime = Number(localStorage.getItem('backgroundStartTime'));
|
const startTime = Number(localStorage.getItem('backgroundStartTime'));
|
||||||
const shouldRefresh = !interval || interval === 'refresh' || startTime + Number(interval) < Date.now();
|
const shouldRefresh =
|
||||||
|
!interval || interval === 'refresh' || startTime + Number(interval) < Date.now();
|
||||||
|
|
||||||
let index;
|
let index;
|
||||||
if (shouldRefresh) {
|
if (shouldRefresh) {
|
||||||
@@ -199,13 +187,11 @@ function getPhotoPackBackground(isOffline) {
|
|||||||
|
|
||||||
const photo = photos[index];
|
const photo = photos[index];
|
||||||
|
|
||||||
return photo ? {
|
return photo
|
||||||
|
? {
|
||||||
url: photo.url.default,
|
url: photo.url.default,
|
||||||
type: 'photo_pack',
|
type: 'photo_pack',
|
||||||
photoInfo: {
|
photoInfo: { hidden: false, credit: photo.photographer, location: photo.location },
|
||||||
hidden: false,
|
}
|
||||||
credit: photo.photographer,
|
: null;
|
||||||
location: photo.location,
|
|
||||||
},
|
|
||||||
} : null;
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user