'use strict';
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/*
*
* Copyright © 2015-2016 Antergos
*
* greeter.js
*
* This file is part of lightdm-webkit-theme-antergos
*
* lightdm-webkit-theme-antergos is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License,
* or any later version.
*
* lightdm-webkit-theme-antergos is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* The following additional terms are in effect as per Section 7 of this license:
*
* The preservation of all legal notices and author attributions in
* the material or in the Appropriate Legal Notices displayed
* by works containing it is required.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see
');
}
/**
* Get a key's value from localStorage. Keys can have two or more parts.
* For example: "ant:user:john:session".
*
* @param {...string} key_parts - Strings that are combined to form the key.
*/
}, {
key: 'cache_get',
value: function cache_get() {
var key = 'ant';
for (var _len = arguments.length, key_parts = Array(_len), _key = 0; _key < _len; _key++) {
key_parts[_key] = arguments[_key];
}
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = key_parts[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var part = _step.value;
key += ':' + part;
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
return localStorage.getItem(key);
}
/**
* Set a key's value in localStorage. Keys can have two or more parts.
* For example: "ant:user:john:session".
*
* @param {string} value - The value to set.
* @param {...string} key_parts - Strings that are combined to form the key.
*/
}, {
key: 'cache_set',
value: function cache_set(value) {
var key = 'ant';
for (var _len2 = arguments.length, key_parts = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
key_parts[_key2 - 1] = arguments[_key2];
}
var _iteratorNormalCompletion2 = true;
var _didIteratorError2 = false;
var _iteratorError2 = undefined;
try {
for (var _iterator2 = key_parts[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
var part = _step2.value;
key += ':' + part;
}
} catch (err) {
_didIteratorError2 = true;
_iteratorError2 = err;
} finally {
try {
if (!_iteratorNormalCompletion2 && _iterator2.return) {
_iterator2.return();
}
} finally {
if (_didIteratorError2) {
throw _iteratorError2;
}
}
}
return localStorage.setItem(key, value);
}
/**
* Get some values from `lightdm-webkit2-greeter.conf` and save them for later.
*/
}, {
key: 'init_config_values',
value: function init_config_values() {
var logo = '',
background_images = '',
background_images_dir = '';
if ('undefined' !== typeof config) {
if (this instanceof AntergosTheme) {
logo = config.get_str('branding', 'logo_image') || '';
} else if (this instanceof AntergosBackgroundManager) {
background_images = config.get_str('branding', 'background_images_array') || '';
background_images = background_images.length ? background_images.split(',') : [];
background_images_dir = config.get_str('branding', 'background_images') || '';
}
}
this.logo = logo;
this.background_images = background_images;
this.background_images_dir = background_images_dir;
}
}]);
return GreeterThemeComponent;
})();
/**
* This class handles the theme's background switcher.
*/
var AntergosBackgroundManager = (function (_GreeterThemeComponen) {
_inherits(AntergosBackgroundManager, _GreeterThemeComponen);
function AntergosBackgroundManager() {
var _ret;
_classCallCheck(this, AntergosBackgroundManager);
var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(AntergosBackgroundManager).call(this));
if (null === _bg_self) {
_bg_self = _this;
}
_this.current_background = _this.cache_get('background_config', 'current_background');
if (!_this.background_images_dir.length || !_this.background_images.length) {
_this.log('AntergosBackgroundManager: [ERROR] No background images detected.');
}
_this.initialize();
return _ret = _bg_self, _possibleConstructorReturn(_this, _ret);
}
_createClass(AntergosBackgroundManager, [{
key: 'initialize',
value: function initialize() {
if (!this.current_background) {
// For backwards compatibility
if (null !== localStorage.getItem('bgsaved') && '0' === localStorage.getItem('bgrandom')) {
this.current_background = localStorage.getItem('bgsaved');
this.cache_set(this.current_background, 'background_manager', 'current_background');
localStorage.removeItem('bgrandom');
localStorage.removeItem('bgsaved');
} else if ('0' === localStorage.getItem('bgrandom')) {
this.current_background = this.get_random_image();
this.cache_set('true', 'background_manager', 'random_background');
localStorage.removeItem('bgrandom');
}
}
if (!this.current_background) {
// For current and future versions
var current_background = this.cache_get('background_manager', 'current_background'),
random_background = this.cache_get('background_manager', 'random_background');
if ('true' === random_background) {}
}
$('.header').fadeTo(300, 0.5, function () {
$('.header').css("background", this.current_background);
}).fadeTo(300, 1);
}
}, {
key: 'get_random_image',
value: function get_random_image() {
var background = undefined,
random_bg = undefined;
if (this.background_images.length) {
random_bg = Math.floor(Math.random() * this.background_images.length);
background = this.background_images[random_bg];
}
}
}, {
key: 'get_old_backgrounds',
value: function get_old_backgrounds() {
var old_backgrounds = [];
$('.bgs .clearfix').each(function (i) {
if (i > 0) {
old_backgrounds.push($(this).attr('data-img'));
}
});
}
}]);
return AntergosBackgroundManager;
})(GreeterThemeComponent);
/**
* This is the theme's main class object. It contains almost all the theme's logic.
*/
var AntergosTheme = (function (_GreeterThemeComponen2) {
_inherits(AntergosTheme, _GreeterThemeComponen2);
function AntergosTheme() {
var _ret2;
_classCallCheck(this, AntergosTheme);
var _this2 = _possibleConstructorReturn(this, Object.getPrototypeOf(AntergosTheme).call(this));
if (null === _self) {
_self = _this2;
}
_this2.user_list_visible = false;
_this2.auth_pending = false;
_this2.selected_user = null;
_this2.$user_list = $('#user-list2');
_this2.$session_list = $('#sessions');
_this2.$clock_container = $('#collapseOne');
_this2.$clock = $("#current_time");
_this2.$actions_container = $("#actionsArea");
_this2.$msg_area_container = $('#statusArea');
_this2.$msg_area = $('#showMsg');
_this2.background_manager = new AntergosBackgroundManager();
_this2.initialize();
return _ret2 = _self, _possibleConstructorReturn(_this2, _ret2);
}
_createClass(AntergosTheme, [{
key: 'initialize',
value: function initialize() {
this.prepare_translations();
this.do_static_translations();
this.initialize_clock();
this.prepare_login_panel_header();
this.prepare_user_list();
this.prepare_session_list();
this.prepare_system_action_buttons();
this.register_callbacks();
}
/**
* Register callbacks for the LDM Greeter as well as any others that haven't been registered
* elsewhere.
*/
}, {
key: 'register_callbacks',
value: function register_callbacks() {
var events = 'shown.bs.collapse, hidden.bs.collapse';
this.$user_list.parents('.collapse').on(events, this.user_list_collapse_handler);
$(document).keydown(this.key_press_handler);
$('.cancel_auth').click(this.cancel_authentication);
$('.submit_passwd').click(this.submit_password);
window.show_prompt = this.show_prompt;
window.show_message = this.show_message;
window.start_authentication = this.start_authentication;
window.cancel_authentication = this.cancel_authentication;
window.authentication_complete = this.authentication_complete;
window.autologin_timer_expired = this.cancel_authentication;
}
/**
* Initialize the user list.
*/
}, {
key: 'prepare_user_list',
value: function prepare_user_list() {
var tux = 'img/antergos-logo-user.png',
template;
// Loop through the array of LightDMUser objects to create our user list.
var _iteratorNormalCompletion3 = true;
var _didIteratorError3 = false;
var _iteratorError3 = undefined;
try {
for (var _iterator3 = lightdm.users[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
var user = _step3.value;
var last_session = this.cache_get('user', user.name, 'session'),
image_src = user.image.length ? user.image : tux;
if (null === last_session) {
// For backwards compatibility
last_session = localStorage.getItem(user.name);
if (null === last_session) {
// This user has never logged in before let's enable the system's default
// session.
last_session = lightdm.default_session;
}
this.cache_set(last_session, 'user', user.name, 'session');
}
this.log('Last session for ' + user.name + ' was: ' + last_session);
template = '\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t' + user.display_name + '\n\t\t\t\t\t\n\t\t\t\t';
// Register event handler here so we don't have to iterate over the users again later.
$(template).appendTo(this.$user_list).click(this.start_authentication);
} // END for ( var user of lightdm.users )
} catch (err) {
_didIteratorError3 = true;
_iteratorError3 = err;
} finally {
try {
if (!_iteratorNormalCompletion3 && _iterator3.return) {
_iterator3.return();
}
} finally {
if (_didIteratorError3) {
throw _iteratorError3;
}
}
}
if ($(this.$user_list).children().length > 3) {
// Make the user list two columns instead of one.
$(this.$user_list).css('column-count', '2').parent().css('max-width', '85%');
}
}
/**
* Initialize the session selection dropdown.
*/
}, {
key: 'prepare_session_list',
value: function prepare_session_list() {
// Loop through the array of LightDMSession objects to create our session list.
var _iteratorNormalCompletion4 = true;
var _didIteratorError4 = false;
var _iteratorError4 = undefined;
try {
for (var _iterator4 = lightdm.sessions[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
var session = _step4.value;
var css_class = session.name.replace(/ /g, ''),
template;
this.log('Adding ' + session.name + ' to the session list...');
template = '\n\t\t\t\t