feat: multiple custom backgrounds (WIP)

This commit is contained in:
David Ralph
2021-09-08 20:58:07 +01:00
parent 6bb461b8a2
commit 102078744e
4 changed files with 79 additions and 14 deletions

View File

@@ -189,14 +189,24 @@ export default class Background extends PureComponent {
break;
case 'custom':
const customBackground = localStorage.getItem('customBackground');
let customBackground;
try {
customBackground = JSON.parse(localStorage.getItem('customBackground'));
} catch (e) {
// move to new format
customBackground = [localStorage.getItem('customBackground')];
localStorage.setItem('customBackground', JSON.stringify(customBackground));
}
// pick random
customBackground = customBackground[Math.floor(Math.random() * customBackground.length)];
// allow users to use offline images
if (offline && !customBackground.startsWith('data:')) {
return this.setState(offlineBackground());
}
if (customBackground !== '' && customBackground !== 'undefined') {
if (customBackground !== '' && customBackground !== 'undefined' && customBackground !== ['']) {
this.setState({
url: customBackground,
type: 'custom',