Skip to content

Commit

Permalink
Add background functions
Browse files Browse the repository at this point in the history
  • Loading branch information
rda0 committed Apr 5, 2022
1 parent c6453f1 commit 41834db
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 51 deletions.
32 changes: 7 additions & 25 deletions generate-images.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
FORMATS = [ '.jpg', '.jpeg', '.png' ]
PATH_WALL = [ 'img/wallpapers', '/usr/share/backgrounds' ]
PATH_THUMB = 'img/thumbs'
SIZE = '100x56'

scriptpath = os.path.realpath(__file__)
dirpath = os.path.dirname(scriptpath)
Expand All @@ -23,28 +24,9 @@
filepath = os.path.join(root, filename)
name, ext = os.path.splitext(filename)
if ext in FORMATS:
image = dict()
image['name'] = name
image['filename'] = filename
image['filepath'] = filepath
images.append(image)
subprocess.call(['mogrify',
'-resize', '100x56',
'-gravity', 'center',
'-format', 'jpg',
'-quality', '100',
'-path', PATH_THUMB, filepath])

config = dict()
config['backgrounds'] = list()

for image in images:
thumb = PATH_THUMB + '/' + image['name'] + '.jpg'
background = dict()
background['name'] = image['name']
background['thumb'] = thumb
background['image'] = image['filepath']
config['backgrounds'].append(background)

with open('background.json.local', 'w') as outfile:
json.dump(config, outfile, indent=2)
subprocess.call(['gm', 'convert',
'-size', SIZE,
filepath,
'-resize', SIZE,
'+profile', '*',
'/'.join([PATH_THUMB, filename])])
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
<link rel="stylesheet" type="text/css" href="css/style.css" />
<script src="js/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/backgrounds.js"></script>
<script src="js/greeter.js"></script>
</head>
<body>
Expand Down
74 changes: 74 additions & 0 deletions js/backgrounds.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
class Backgrounds {
constructor() {
this._localStorage = window.localStorage;
this._defaultBackgroundArr = [
"img/wallpapers/milky-way-robiei.jpg",
"img/wallpapers/star-cloud-blue-red.jpg",
"img/wallpapers/nathan-anderson-268995.jpg",
"img/wallpapers/hugo-kemmel-289805.jpg",
"img/wallpapers/jamison-mcandie-112376.jpg",
];
this._backgroundImages = null;
this._backgroundImagesDir = null;
this._backgroundPath = "";
}

async _createBackgroundArray() {
let images = await this._getImages();
this._backgroundImages = this._defaultBackgroundArr.concat(images);
return new Promise((resolve) => resolve());
}

_updateOnStartup() {
this._backgroundPath =
this._localStorage.getItem("defaultBackgroundImage") ||
this._backgroundImages[0];
this._updateBackgroundImages();
this._addBackgroundButtonsHandler();
}

_updateBackgroundImages() {
this._backgroundImages.forEach(function (file) {
let background = {};
background.image = file;
background.thumb = 'img/thumbs/' + file.split(/(\\|\/)/g).pop();
$('.bgs').append(`
<a href="#" data-img="${background.image}" class="background">
<img src="${background.thumb}" />
</a>
`);
});
}

_addBackgroundButtonsHandler() {
let backgroundButtons = $(".bg-switch .background");
backgroundButtons.click(function (e) {
e.preventDefault();
backgroundButtons.removeClass("active");
$(".bgs .background .default").first().removeClass('active');
$(this).addClass("active");
switchBackground($(this).data("img"));
});
}

_getImages(path) {
this._backgroundImagesDir =
greeter_config.branding.background_images_dir || "/usr/share/backgrounds";
return new Promise((resolve) => {
theme_utils.dirlist(
path ? path : this._backgroundImagesDir,
true,
(result) => {
resolve(result);
}
);
});
}

async _init() {
await this._createBackgroundArray();
this._updateOnStartup();

return new Promise((resolve) => resolve());
}
}
35 changes: 9 additions & 26 deletions js/greeter.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,27 +352,6 @@ function addActionButton(id) {
* functions for UI initialisation
*/

function addBackgroundButtons() {
theme_config.backgrounds.forEach(function (background) {
$('.bgs').append(`
<a href="#" data-img="${background.image}" class="background">
<img src="${background.thumb}" />
</a>
`);
});
}

function addBackgroundButtonsHandler() {
let backgroundButtons = $(".bg-switch .background");
backgroundButtons.click(function (e) {
e.preventDefault();
backgroundButtons.removeClass("active");
$(".bgs .background .default").first().removeClass('active');
$(this).addClass("active");
switchBackground($(this).data("img"));
});
}

function addActionButtons() {
addActionButton("shutdown");
addActionButton("hibernate");
Expand Down Expand Up @@ -554,8 +533,8 @@ function applyConfig() {
$('#banner img').attr('src', `img/banners/${theme_config.banner}.png`);
$('#logo img').attr('src', `img/banners/${theme_config.logo}.png`);

addBackgroundButtons();
addBackgroundButtonsHandler();
//addBackgroundButtons();
//addBackgroundButtonsHandler();
addActionButtons();
activeSessions = setLockedSessions();
setHeader(activeSessions);
Expand Down Expand Up @@ -666,17 +645,21 @@ function submitUsername() {
}

/*
* greeter ready
* greeter init
*/

function initBackgrounds() {
let backgrounds = new Backgrounds();
backgrounds._init()
}

function initGreeter() {
theme_config = THEME_CONFIG_DEFAULTS;
theme_config.backgrounds = [];
lightdm.authentication_complete.connect(authentication_complete);
lightdm.autologin_timer_expired.connect(autologin_timer_expired);
loadThemeConfig();
initBackgrounds();
applyConfig();
}

window.addEventListener("GreeterReady", initGreeter);

0 comments on commit 41834db

Please sign in to comment.