Skip to content

Commit 41834db

Browse files
committed
Add background functions
1 parent c6453f1 commit 41834db

File tree

4 files changed

+91
-51
lines changed

4 files changed

+91
-51
lines changed

generate-images.py

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
FORMATS = [ '.jpg', '.jpeg', '.png' ]
1010
PATH_WALL = [ 'img/wallpapers', '/usr/share/backgrounds' ]
1111
PATH_THUMB = 'img/thumbs'
12+
SIZE = '100x56'
1213

1314
scriptpath = os.path.realpath(__file__)
1415
dirpath = os.path.dirname(scriptpath)
@@ -23,28 +24,9 @@
2324
filepath = os.path.join(root, filename)
2425
name, ext = os.path.splitext(filename)
2526
if ext in FORMATS:
26-
image = dict()
27-
image['name'] = name
28-
image['filename'] = filename
29-
image['filepath'] = filepath
30-
images.append(image)
31-
subprocess.call(['mogrify',
32-
'-resize', '100x56',
33-
'-gravity', 'center',
34-
'-format', 'jpg',
35-
'-quality', '100',
36-
'-path', PATH_THUMB, filepath])
37-
38-
config = dict()
39-
config['backgrounds'] = list()
40-
41-
for image in images:
42-
thumb = PATH_THUMB + '/' + image['name'] + '.jpg'
43-
background = dict()
44-
background['name'] = image['name']
45-
background['thumb'] = thumb
46-
background['image'] = image['filepath']
47-
config['backgrounds'].append(background)
48-
49-
with open('background.json.local', 'w') as outfile:
50-
json.dump(config, outfile, indent=2)
27+
subprocess.call(['gm', 'convert',
28+
'-size', SIZE,
29+
filepath,
30+
'-resize', SIZE,
31+
'+profile', '*',
32+
'/'.join([PATH_THUMB, filename])])

index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
<link rel="stylesheet" type="text/css" href="css/style.css" />
4343
<script src="js/jquery.min.js"></script>
4444
<script src="js/bootstrap.min.js"></script>
45+
<script src="js/backgrounds.js"></script>
4546
<script src="js/greeter.js"></script>
4647
</head>
4748
<body>

js/backgrounds.js

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
class Backgrounds {
2+
constructor() {
3+
this._localStorage = window.localStorage;
4+
this._defaultBackgroundArr = [
5+
"img/wallpapers/milky-way-robiei.jpg",
6+
"img/wallpapers/star-cloud-blue-red.jpg",
7+
"img/wallpapers/nathan-anderson-268995.jpg",
8+
"img/wallpapers/hugo-kemmel-289805.jpg",
9+
"img/wallpapers/jamison-mcandie-112376.jpg",
10+
];
11+
this._backgroundImages = null;
12+
this._backgroundImagesDir = null;
13+
this._backgroundPath = "";
14+
}
15+
16+
async _createBackgroundArray() {
17+
let images = await this._getImages();
18+
this._backgroundImages = this._defaultBackgroundArr.concat(images);
19+
return new Promise((resolve) => resolve());
20+
}
21+
22+
_updateOnStartup() {
23+
this._backgroundPath =
24+
this._localStorage.getItem("defaultBackgroundImage") ||
25+
this._backgroundImages[0];
26+
this._updateBackgroundImages();
27+
this._addBackgroundButtonsHandler();
28+
}
29+
30+
_updateBackgroundImages() {
31+
this._backgroundImages.forEach(function (file) {
32+
let background = {};
33+
background.image = file;
34+
background.thumb = 'img/thumbs/' + file.split(/(\\|\/)/g).pop();
35+
$('.bgs').append(`
36+
<a href="#" data-img="${background.image}" class="background">
37+
<img src="${background.thumb}" />
38+
</a>
39+
`);
40+
});
41+
}
42+
43+
_addBackgroundButtonsHandler() {
44+
let backgroundButtons = $(".bg-switch .background");
45+
backgroundButtons.click(function (e) {
46+
e.preventDefault();
47+
backgroundButtons.removeClass("active");
48+
$(".bgs .background .default").first().removeClass('active');
49+
$(this).addClass("active");
50+
switchBackground($(this).data("img"));
51+
});
52+
}
53+
54+
_getImages(path) {
55+
this._backgroundImagesDir =
56+
greeter_config.branding.background_images_dir || "/usr/share/backgrounds";
57+
return new Promise((resolve) => {
58+
theme_utils.dirlist(
59+
path ? path : this._backgroundImagesDir,
60+
true,
61+
(result) => {
62+
resolve(result);
63+
}
64+
);
65+
});
66+
}
67+
68+
async _init() {
69+
await this._createBackgroundArray();
70+
this._updateOnStartup();
71+
72+
return new Promise((resolve) => resolve());
73+
}
74+
}

js/greeter.js

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -352,27 +352,6 @@ function addActionButton(id) {
352352
* functions for UI initialisation
353353
*/
354354

355-
function addBackgroundButtons() {
356-
theme_config.backgrounds.forEach(function (background) {
357-
$('.bgs').append(`
358-
<a href="#" data-img="${background.image}" class="background">
359-
<img src="${background.thumb}" />
360-
</a>
361-
`);
362-
});
363-
}
364-
365-
function addBackgroundButtonsHandler() {
366-
let backgroundButtons = $(".bg-switch .background");
367-
backgroundButtons.click(function (e) {
368-
e.preventDefault();
369-
backgroundButtons.removeClass("active");
370-
$(".bgs .background .default").first().removeClass('active');
371-
$(this).addClass("active");
372-
switchBackground($(this).data("img"));
373-
});
374-
}
375-
376355
function addActionButtons() {
377356
addActionButton("shutdown");
378357
addActionButton("hibernate");
@@ -554,8 +533,8 @@ function applyConfig() {
554533
$('#banner img').attr('src', `img/banners/${theme_config.banner}.png`);
555534
$('#logo img').attr('src', `img/banners/${theme_config.logo}.png`);
556535

557-
addBackgroundButtons();
558-
addBackgroundButtonsHandler();
536+
//addBackgroundButtons();
537+
//addBackgroundButtonsHandler();
559538
addActionButtons();
560539
activeSessions = setLockedSessions();
561540
setHeader(activeSessions);
@@ -666,17 +645,21 @@ function submitUsername() {
666645
}
667646

668647
/*
669-
* greeter ready
648+
* greeter init
670649
*/
671650

651+
function initBackgrounds() {
652+
let backgrounds = new Backgrounds();
653+
backgrounds._init()
654+
}
655+
672656
function initGreeter() {
673657
theme_config = THEME_CONFIG_DEFAULTS;
674-
theme_config.backgrounds = [];
675658
lightdm.authentication_complete.connect(authentication_complete);
676659
lightdm.autologin_timer_expired.connect(autologin_timer_expired);
677660
loadThemeConfig();
661+
initBackgrounds();
678662
applyConfig();
679663
}
680664

681665
window.addEventListener("GreeterReady", initGreeter);
682-

0 commit comments

Comments
 (0)