fixing wallpaper
All checks were successful
Build and Release to Staging / Build Vision Start (push) Successful in 31s
Build and Release to Staging / Build Vision Start Image (push) Successful in 2m54s
Build and Release to Staging / Deploy Vision Start (staging) (push) Successful in 1m10s

This commit is contained in:
2026-07-02 19:22:19 -03:00
parent c397e77c01
commit ddf2f2a416
4 changed files with 115 additions and 37 deletions

View File

@@ -13,6 +13,7 @@ interface ConfigurationModalProps {
onSave: (config: Config) => void;
currentConfig: Config;
onWallpaperChange: (newConfig: Partial<Config>) => void;
onNextWallpaper: () => void;
}
const ConfigurationModal: React.FC<ConfigurationModalProps> = ({
@@ -20,6 +21,7 @@ const ConfigurationModal: React.FC<ConfigurationModalProps> = ({
onSave,
currentConfig,
onWallpaperChange,
onNextWallpaper,
}) => {
const [config, setConfig] = useState<Config>(currentConfig);
const [activeTab, setActiveTab] = useState('general');
@@ -175,6 +177,7 @@ const ConfigurationModal: React.FC<ConfigurationModalProps> = ({
onAddWallpaper={handleAddWallpaper}
onAddWallpaperFile={handleAddWallpaperFile}
onDeleteWallpaper={handleDeleteWallpaper}
onNextWallpaper={onNextWallpaper}
/>
)}
{activeTab === 'clock' && (

View File

@@ -10,35 +10,41 @@ interface WallpaperProps {
brightness: number;
opacity: number;
wallpaperFrequency: string;
wallpaperVersion: number;
}
const getWallpaperUrlByName = async (name: string): Promise<string | undefined> => {
if (!name) return undefined;
const foundInBase = baseWallpapers.find((w: WallpaperType) => w.name === name);
if (foundInBase) {
return foundInBase.url || foundInBase.base64;
}
const userWallpapers: WallpaperType[] = JSON.parse(localStorage.getItem('userWallpapers') || '[]');
const foundInUser = userWallpapers.find((w: WallpaperType) => w.name === name);
if (foundInUser) {
try {
const wallpaperData = await getWallpaperFromChromeStorageLocal(name);
if (wallpaperData && wallpaperData.startsWith('http')) {
return wallpaperData;
try {
const storedUserWallpapers: WallpaperType[] =
JSON.parse(localStorage.getItem('userWallpapers') || '[]');
const foundInUser = storedUserWallpapers.find((w: WallpaperType) => w.name === name);
if (foundInUser) {
try {
const wallpaperData = await getWallpaperFromChromeStorageLocal(name);
if (wallpaperData && wallpaperData.startsWith('http')) {
return wallpaperData;
}
return wallpaperData || undefined;
} catch (error) {
console.error('Error getting wallpaper from chrome storage', error);
return undefined;
}
return wallpaperData || undefined;
} catch (error) {
console.error('Error getting wallpaper from chrome storage', error);
return undefined;
}
} catch (error) {
console.error('Error reading userWallpapers from localStorage', error);
}
return undefined;
};
const Wallpaper: React.FC<WallpaperProps> = ({ wallpaperNames, blur, brightness, opacity, wallpaperFrequency }) => {
const Wallpaper: React.FC<WallpaperProps> = ({ wallpaperNames, blur, brightness, opacity, wallpaperFrequency, wallpaperVersion }) => {
const [imageUrl, setImageUrl] = useState<string | undefined>(undefined);
const [currentWallpaperIndex, setCurrentWallpaperIndex] = useState<number>(0);
// Helper to parse wallpaperFrequency string to ms
const parseFrequencyToMs = (freq: string): number => {
@@ -54,36 +60,61 @@ const Wallpaper: React.FC<WallpaperProps> = ({ wallpaperNames, blur, brightness,
useEffect(() => {
const updateWallpaper = async () => {
if (wallpaperNames.length === 0) return;
// Read wallpaperState from localStorage
if (wallpaperNames.length === 0) {
setImageUrl(undefined);
localStorage.setItem(
'wallpaperState',
JSON.stringify({ lastWallpaperChange: new Date().toISOString(), currentIndex: 0 }),
);
return;
}
const wallpaperState = JSON.parse(localStorage.getItem('wallpaperState') || '{}');
const lastChange = wallpaperState.lastWallpaperChange ? new Date(wallpaperState.lastWallpaperChange).getTime() : 0;
const lastChange = wallpaperState.lastWallpaperChange
? new Date(wallpaperState.lastWallpaperChange).getTime()
: 0;
const now = Date.now();
const freqMs = parseFrequencyToMs(wallpaperFrequency);
let currentIndex = typeof wallpaperState.currentIndex === 'number' ? wallpaperState.currentIndex : 0;
// If enough time has passed, pick a new wallpaper
if (now - lastChange >= freqMs) {
currentIndex = (currentIndex + 1) % wallpaperNames.length;
localStorage.setItem('wallpaperState', JSON.stringify({
lastWallpaperChange: new Date().toISOString(),
currentIndex
}));
} else {
// Keep currentIndex in sync with localStorage if not updating
localStorage.setItem('wallpaperState', JSON.stringify({
lastWallpaperChange: wallpaperState.lastWallpaperChange || new Date().toISOString(),
currentIndex
}));
let storedIndex =
typeof wallpaperState.currentIndex === 'number' ? wallpaperState.currentIndex : 0;
if (storedIndex < 0 || storedIndex >= wallpaperNames.length) storedIndex = 0;
const shouldRotate = now - lastChange >= freqMs;
let resolvedIndex = shouldRotate
? (storedIndex + 1) % wallpaperNames.length
: storedIndex;
const tried = new Set<number>();
let resolvedUrl: string | undefined;
for (let i = 0; i < wallpaperNames.length; i++) {
if (tried.has(resolvedIndex)) break;
tried.add(resolvedIndex);
const url = await getWallpaperUrlByName(wallpaperNames[resolvedIndex]);
if (url) {
resolvedUrl = url;
break;
}
resolvedIndex = (resolvedIndex + 1) % wallpaperNames.length;
}
setCurrentWallpaperIndex(currentIndex);
const wallpaperName = wallpaperNames[currentIndex];
const url = await getWallpaperUrlByName(wallpaperName);
setImageUrl(url);
const nextLastChange = shouldRotate
? new Date().toISOString()
: wallpaperState.lastWallpaperChange || new Date().toISOString();
localStorage.setItem(
'wallpaperState',
JSON.stringify({
lastWallpaperChange: nextLastChange,
currentIndex: resolvedIndex,
}),
);
setImageUrl(resolvedUrl);
};
updateWallpaper();
// No timer, just run on render/dependency change
}, [wallpaperNames, wallpaperFrequency]);
}, [wallpaperNames, wallpaperFrequency, wallpaperVersion]);
if (!imageUrl) return null;

View File

@@ -11,6 +11,7 @@ interface ThemeTabProps {
onAddWallpaper: (name: string, url: string) => Promise<void>;
onAddWallpaperFile: (file: File) => Promise<void>;
onDeleteWallpaper: (wallpaper: Wallpaper) => Promise<void>;
onNextWallpaper: () => void;
}
const ThemeTab: React.FC<ThemeTabProps> = ({
@@ -22,6 +23,7 @@ const ThemeTab: React.FC<ThemeTabProps> = ({
onAddWallpaper,
onAddWallpaperFile,
onDeleteWallpaper,
onNextWallpaper,
}) => {
const [newWallpaperName, setNewWallpaperName] = useState('');
const [newWallpaperUrl, setNewWallpaperUrl] = useState('');
@@ -177,7 +179,7 @@ const ThemeTab: React.FC<ThemeTabProps> = ({
/>
<button
onClick={handleAddWallpaper}
className="bg-cyan-500 hover:bg-cyan-400 text-white font-bold py-2 px-4 rounded-lg"
className="bg-cyan-500 hover:bg-cyan-400 active:scale-95 text-white font-bold py-2 px-4 rounded-lg transition-all duration-150 ease-ios"
>
Add
</button>
@@ -221,6 +223,24 @@ const ThemeTab: React.FC<ThemeTabProps> = ({
</div>
</>
)}
<div className="flex justify-center pt-2">
<button
onClick={onNextWallpaper}
disabled={config.currentWallpapers.length === 0}
className="flex items-center gap-2 bg-black/25 backdrop-blur-md border border-white/10 hover:bg-white/25 active:scale-95 disabled:opacity-40 disabled:cursor-not-allowed text-white text-sm font-semibold py-2 px-4 rounded-xl transition-all duration-150 ease-ios"
>
<svg
xmlns="http://www.w3.org/2000/svg"
width="16"
height="16"
fill="currentColor"
viewBox="0 0 16 16"
>
<path d="M8 0a8 8 0 1 0 0 16A8 8 0 0 0 8 0zM4.5 7.5a.5.5 0 0 1 .5-.5h5.379L8.646 5.354a.5.5 0 1 1 .708-.708l2.5 2.5a.5.5 0 0 1 0 .708l-2.5 2.5a.5.5 0 0 1-.708-.708L10.379 8H5a.5.5 0 0 1-.5-.5z" />
</svg>
Next Wallpaper
</button>
</div>
</div>
);
};