Browse Source

finish implementing utility function for getting the current localized time as well as allowing the format and language to be overridden in the config file.

sisyphus
Dustin Falgout 8 years ago
parent
commit
ff500a437d
  1. 6
      data/lightdm-webkit2-greeter.conf
  2. 52
      src/gresource/js/GreeterConfig.js
  3. 30
      src/gresource/js/ThemeUtils.js

6
data/lightdm-webkit2-greeter.conf

@ -3,13 +3,19 @@
# debug_mode = Greeter theme debug mode. # debug_mode = Greeter theme debug mode.
# secure_mode = Don't allow themes to make remote http requests. # secure_mode = Don't allow themes to make remote http requests.
# screensaver_timeout = Blank the screen after this many seconds of inactivity. # screensaver_timeout = Blank the screen after this many seconds of inactivity.
# time_format = A moment.js format string for use by theme's to display the time.
# time_language = Language to use when displaying the time or "auto" to use the system's language.
# webkit_theme = Webkit theme to use. # webkit_theme = Webkit theme to use.
# #
# NOTE: See moment.js documentation for format string options: http://momentjs.com/docs/#/displaying/format/
#
[greeter] [greeter]
debug_mode = false debug_mode = false
secure_mode = true secure_mode = true
screensaver_timeout = 300 screensaver_timeout = 300
time_format = LT
time_language = auto
webkit_theme = antergos webkit_theme = antergos
# #

52
src/gresource/js/GreeterConfig.js

@ -26,6 +26,10 @@
*/ */
let _branding = null,
_greeter = null;
/** /**
* Provides theme authors with a way to retrieve values from the greeter's config * Provides theme authors with a way to retrieve values from the greeter's config
* file located at `/etc/lightdm/lightdm-webkit2-greeter.conf`. The greeter will * file located at `/etc/lightdm/lightdm-webkit2-greeter.conf`. The greeter will
@ -45,7 +49,15 @@ class GreeterConfig {
* *
* @readonly * @readonly
*/ */
get branding() {} get branding() {
let props = ['background_images', 'logo', 'user_image'];
if ( null === _branding ) {
props.forEach( prop => _branding[prop] = this.get_str( 'branding', prop ) );
}
return _branding;
}
/** /**
* Holds keys/values from the `greeter` section of the config file. * Holds keys/values from the `greeter` section of the config file.
@ -54,11 +66,26 @@ class GreeterConfig {
* {Boolean} greeter.debug_mode * {Boolean} greeter.debug_mode
* {Boolean} greeter.secure_mode * {Boolean} greeter.secure_mode
* {Number} greeter.screensaver_timeout * {Number} greeter.screensaver_timeout
* {String} greeter.time_format
* {String} greeter.time_language
* {String} greeter.webkit_theme * {String} greeter.webkit_theme
* *
* @readonly * @readonly
*/ */
get greeter() {} get greeter() {
let bools = ['debug_mode', 'secure_mode'],
strings = ['time_format', 'time_language', 'webkit_theme'];
if ( null === _greeter ) {
_greeter = {};
_greeter.screensaver_timeout = this.get_num( 'greeter', 'screensaver_timeout' );
bools.forEach( prop => _greeter[prop] = this.get_bool( 'greeter', prop ) );
strings.forEach( prop => _greeter[prop] = this.get_str( 'greeter', prop ) );
}
return _greeter;
}
/** /**
* Returns the value of `key` from the `config_section` of the greeter's config file. * Returns the value of `key` from the `config_section` of the greeter's config file.
@ -70,7 +97,9 @@ class GreeterConfig {
* *
* @returns {Boolean} Config value for `key`. * @returns {Boolean} Config value for `key`.
*/ */
get_bool( config_section, key ) {} get_bool( config_section, key ) {
return __GreeterConfig.get_bool( config_section, key );
}
/** /**
* Returns the value of `key` from the `config_section` of the greeter's config file. * Returns the value of `key` from the `config_section` of the greeter's config file.
@ -82,7 +111,9 @@ class GreeterConfig {
* *
* @returns {Number} Config value for `key`. * @returns {Number} Config value for `key`.
*/ */
get_num( config_section, key ) {} get_num( config_section, key ) {
return __GreeterConfig.get_num( config_section, key );
}
/** /**
* Returns the value of `key` from the `config_section` of the greeter's config file. * Returns the value of `key` from the `config_section` of the greeter's config file.
@ -94,7 +125,9 @@ class GreeterConfig {
* *
* @returns {String} Config value for `key`. * @returns {String} Config value for `key`.
*/ */
get_str( key ) {} get_str( config_section, key ) {
return __GreeterConfig.get_str( config_section, key );
}
} }
@ -102,8 +135,11 @@ class GreeterConfig {
* @memberOf window * @memberOf window
* @type {LightDM.GreeterConfig} * @type {LightDM.GreeterConfig}
*/ */
window.greeter_config = __GreeterConfig; window.greeter_config = new GreeterConfig();
/* -------->>> DEPRECATED! <<<-------- */ /**
* @deprecated
* @type {LightDM.GreeterConfig}
*/
window.config = window.greeter_config; window.config = window.greeter_config;
/* -------->>> DEPRECATED! <<<-------- */

30
src/gresource/js/ThemeUtils.js

@ -30,7 +30,10 @@ if ( 'undefined' === typeof window.navigator.languages ) {
} }
moment.locale( window.navigator.languages ); moment.locale( window.navigator.languages );
let localized_invalid_date = moment('today', '!@#');
let localized_invalid_date = moment('today', '!@#'),
time_language = null,
time_format = null;
@ -45,9 +48,9 @@ class ThemeUtils {
/** /**
* Binds `this` to class, `context`, for all of the class's methods. * Binds `this` to class, `context`, for all of the class's methods.
* *
* @arg {function(new:*): Object} context An ES6 class (not an instance) with at least one method. * @arg {Object} context An ES6 class instance with at least one method.
* *
* @return {function(new:*): Object} `context` with `this` bound to it for all of its methods. * @return {Object} `context` with `this` bound to it for all of its methods.
*/ */
bind_this( context ) { bind_this( context ) {
let excluded_methods = ['constructor']; let excluded_methods = ['constructor'];
@ -98,8 +101,10 @@ class ThemeUtils {
/** /**
* Get the current time in a localized format based on the `time_format` config file key. * Get the current time in a localized format. Time format and language are auto-detected
* * When `time_format` has a valid value, time will be formatted * by default, but can be set manually in the greeter config file.
* * `language` defaults to the system's language, but can be set manually in the config file.
* * When `time_format` config file option has a valid value, time will be formatted
* according to that value. * according to that value.
* * When `time_format` does not have a valid value, the time format will be `LT` * * When `time_format` does not have a valid value, the time format will be `LT`
* which is `1:00 PM` or `13:00` depending on the system's locale. * which is `1:00 PM` or `13:00` depending on the system's locale.
@ -107,8 +112,19 @@ class ThemeUtils {
* @return {String} The current localized time. * @return {String} The current localized time.
*/ */
get_current_localized_time() { get_current_localized_time() {
let config_format = greeter_config.greeter.time_format; if ( null === time_language ) {
let format = ( '' !== config_format ) ? config_format : 'LT'; let config = greeter_config.greeter,
manual_language = ( '' !== config.time_language && 'auto' !== config.time_language ),
manual_time_format = ( '' !== config.time_format && 'auto' !== config.time_format );
time_language = manual_language ? config.time_language : window.navigator.language;
time_format = manual_time_format ? config.time_format : 'LT';
if ( manual_language ) {
moment.locale( time_language );
}
}
let local_time = moment().format( format ); let local_time = moment().format( format );
if ( local_time === localized_invalid_date ) { if ( local_time === localized_invalid_date ) {

Loading…
Cancel
Save