Skip to content

Commit 2339be8

Browse files
committed
More work
1 parent 3f9fe95 commit 2339be8

1 file changed

Lines changed: 96 additions & 1 deletion

File tree

beta/emuos/assets/js/emuos.js

Lines changed: 96 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@
349349

350350
self.$desktop = $('.desktop').first();
351351
self.$taskbar = $('.taskbar').first();
352+
self._applyStoredCustomWallpaper();
352353

353354
var desktopIcons = self._getDesktopIcons(self.options.icons, self.useFolders);
354355

@@ -1078,6 +1079,12 @@
10781079
uiIcon: 'ui-icon-refresh'
10791080
} , {
10801081
title: '----'
1082+
} , {
1083+
title: 'Custom Wallpaper...',
1084+
cmd: 'custom-wallpaper',
1085+
uiIcon: 'ui-icon-image'
1086+
} , {
1087+
title: '----'
10811088
} , {
10821089
title: 'Themes',
10831090
children: [{
@@ -1109,6 +1116,9 @@
11091116
// noinspection JSUnresolvedFunction
11101117
window.location.reload();
11111118
break;
1119+
case 'custom-wallpaper':
1120+
self._promptCustomWallpaper();
1121+
break;
11121122
case 'toggle-folders':
11131123
self.useFolders = !self.useFolders;
11141124

@@ -1262,6 +1272,91 @@
12621272
}
12631273
};
12641274

1275+
EmuOS.prototype._getCustomWallpaper = function() {
1276+
if (typeof simplestorage === 'undefined' || typeof simplestorage.get !== 'function') {
1277+
return '';
1278+
}
1279+
1280+
var value = simplestorage.get('customWallpaper');
1281+
1282+
return typeof value === 'string' ? value : '';
1283+
};
1284+
1285+
EmuOS.prototype._setCustomWallpaper = function(dataUrl) {
1286+
if (typeof simplestorage === 'undefined' || typeof simplestorage.set !== 'function') {
1287+
return;
1288+
}
1289+
1290+
simplestorage.set('customWallpaper', dataUrl);
1291+
};
1292+
1293+
EmuOS.prototype._applyCustomWallpaper = function(dataUrl) {
1294+
if (!dataUrl || typeof dataUrl !== 'string') {
1295+
return;
1296+
}
1297+
1298+
this.$desktop.css({
1299+
'background-image': 'url(' + dataUrl + ')',
1300+
'background-size': 'cover',
1301+
'background-position': 'center center',
1302+
'background-repeat': 'no-repeat'
1303+
});
1304+
};
1305+
1306+
EmuOS.prototype._applyStoredCustomWallpaper = function() {
1307+
var wallpaper = this._getCustomWallpaper();
1308+
1309+
if (wallpaper) {
1310+
this._applyCustomWallpaper(wallpaper);
1311+
}
1312+
};
1313+
1314+
EmuOS.prototype._promptCustomWallpaper = function() {
1315+
var self = this;
1316+
var $picker = $('<input type="file" accept="image/*" style="display:none;" />');
1317+
1318+
self.$body.append($picker);
1319+
1320+
$picker.off('change').on('change', function() {
1321+
var file = this.files && this.files[0] ? this.files[0] : null;
1322+
1323+
if (!file) {
1324+
$picker.remove();
1325+
return;
1326+
}
1327+
1328+
if (typeof FileReader === 'undefined') {
1329+
toastr.error('This browser does not support custom wallpaper upload.');
1330+
$picker.remove();
1331+
return;
1332+
}
1333+
1334+
var reader = new FileReader();
1335+
1336+
reader.onload = function(evt) {
1337+
var result = evt && evt.target ? evt.target.result : '';
1338+
1339+
if (typeof result === 'string' && result.indexOf('data:image') === 0) {
1340+
self._setCustomWallpaper(result);
1341+
self._applyCustomWallpaper(result);
1342+
} else {
1343+
toastr.error('Invalid image file.');
1344+
}
1345+
1346+
$picker.remove();
1347+
};
1348+
1349+
reader.onerror = function() {
1350+
toastr.error('Could not read image file.');
1351+
$picker.remove();
1352+
};
1353+
1354+
reader.readAsDataURL(file);
1355+
});
1356+
1357+
$picker.trigger('click');
1358+
};
1359+
12651360
EmuOS.prototype._getUseFoldersSetting = function() {
12661361
if (typeof simplestorage === 'undefined' || typeof simplestorage.get !== 'function') {
12671362
return true;
@@ -2060,4 +2155,4 @@
20602155
};
20612156

20622157
return EmuOS;
2063-
}));
2158+
}));

0 commit comments

Comments
 (0)