Skip to content

Commit

Permalink
Add in random image selection
Browse files Browse the repository at this point in the history
  • Loading branch information
efyang committed May 11, 2016
1 parent e377c4e commit 65ae713
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
32 changes: 27 additions & 5 deletions assets/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ angular.module('webkitMaterial', ['ngMaterial', 'angularLoad'])
}

factory.loadEngine(function () {
var imagePath = 'assets/ui/no-mans-sky.jpg';
if (settings.backgroundEngine === 'trianglify') {
var backgroundHeight = Math.max($(document).height(), $(window).height()) * 0.89;
var backgroundWidth = Math.max($(document).width(), $(window).width()) * 0.89;
Expand Down Expand Up @@ -205,11 +206,32 @@ angular.module('webkitMaterial', ['ngMaterial', 'angularLoad'])
density: settings.particlegroundDensity,
proximity: settings.particlegroundDensity / 70
});
} else if (settings.backgroundEngine === 'random-image') {
var imageDir = config.get_str('branding', 'background_images');
var imagesLoaded = false;
if (imageDir == null) {imageDir = config.get_str('greeter', 'background_images');}
if (imageDir != null) {
var imagePaths = greeterutil.dirlist(imageDir);
if (imagePaths != null) {
if (imagePaths.length > 0) {
imagesLoaded = true;
var imageIndex = Math.floor(Math.random() * imagePaths.length);
imagePath = imagePaths[imageIndex];
}
}
if (!imagesLoaded) {
console.error('Non-existant or missing background images in', imageDir);
}
} else {
console.error('background_images variable unset');
}
} else if (settings.backgroundEngine === 'image') {
var imagePath = '/var/lib/AccountsService/wallpapers/lightdm-webkit.jpg';
$rootScope.$applyAsync(function () {
$rootScope.backgroundStyle = {"background-image": 'url('+imagePath+')', "background-color": 'none'};
});
imagePath = '/var/lib/AccountsService/wallpapers/lightdm-webkit.jpg';
}
if (settings.backgroundEngine === 'random-image' || settings.backgroundEngine === 'image') {
$rootScope.$applyAsync(function () {
$rootScope.backgroundStyle = {"background-image": 'url('+imagePath+')', "background-color": 'none'};
});
$http({
method: 'GET',
url: imagePath
Expand Down Expand Up @@ -367,4 +389,4 @@ angular.module('webkitMaterial', ['ngMaterial', 'angularLoad'])

$rootScope.animation = settings.animation;
$rootScope.animationDuration = {'animationDuration': settings.animationDuration + 'ms'};
});
});
4 changes: 3 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,10 @@
<md-select id="settings-background" name="backgroundEngine" ng-model="settings.backgroundEngine">
<md-option value="trianglify">Trianglify</md-option>
<md-option value="particleground">Particleground</md-option>
<md-option value="random-image">Random Image</md-option>
<md-option value="image">Image</md-option>
</md-select>
<div class="hint" ng-if="settings.backgroundEngine == 'random-image'">Background images should be located in "/var/lib/AccountsService/wallpapers" in png or jpeg format.</div>
<div class="hint" ng-if="settings.backgroundEngine == 'image'">Background image should be located at "/var/lib/AccountsService/wallpapers/lightdm-webkit.jpg" in jpeg format.</div>
</md-input-container>
<md-input-container ng-show="settings.backgroundEngine == 'particleground'">
Expand All @@ -79,7 +81,7 @@
</div>
</div>
</md-input-container>
<md-input-container ng-if="settings.backgroundEngine != 'image'">
<md-input-container ng-if="settings.backgroundEngine != 'image' || settings.backgroundEngine != 'random-image'">
<label for="settings-background"><i class="fa fa-desktop"></i> Background Color Scheme</label>
<md-select id="settings-background" ng-model="settings.background">
<md-option value="random">Random (default)</md-option>
Expand Down

0 comments on commit 65ae713

Please sign in to comment.