From 7affd4dd01b04bdabcb260d059372431c7c06b0e Mon Sep 17 00:00:00 2001 From: Dustin Falgout Date: Tue, 1 Nov 2016 00:06:20 -0500 Subject: [PATCH] more work on configurable time format --- src/gresource/js/Greeter.js | 6 +-- src/gresource/js/LightDMObjects.js | 16 ++++---- src/gresource/js/ThemeHeartbeat.js | 2 +- src/gresource/js/ThemeUtils.js | 62 +++++++++++++++++++++++++++++- themes/antergos/js/greeter.js | 5 --- 5 files changed, 71 insertions(+), 20 deletions(-) diff --git a/src/gresource/js/Greeter.js b/src/gresource/js/Greeter.js index 2ee5549..40948f4 100644 --- a/src/gresource/js/Greeter.js +++ b/src/gresource/js/Greeter.js @@ -30,7 +30,7 @@ * Base class for the greeter's JavaScript Theme API. Greeter themes will interact * directly with an object derived from this class to facilitate the user log-in process. * The greeter will automatically create an instance when it starts. - * The instance can be accessed using the global variable: `lightdm`. + * The instance can be accessed using the global variable: `lightdm` ({@link window.lightdm}). * * @memberOf LightDM */ @@ -266,9 +266,7 @@ class Greeter { * Triggers the system to restart. * @returns {Boolean} {@link true} if restart initiated, otherwise {@link false} */ - restart() { - return this._do_mocked_system_action('restart'); - } + restart() {} /** * Set the language for the currently authenticated user. diff --git a/src/gresource/js/LightDMObjects.js b/src/gresource/js/LightDMObjects.js index ac913a9..f10d32e 100644 --- a/src/gresource/js/LightDMObjects.js +++ b/src/gresource/js/LightDMObjects.js @@ -31,10 +31,10 @@ /** * Interface for object that holds info about a session. Session objects are not - * created by the theme's code, but rather by the {@link LightDMGreeter} class. + * created by the theme's code, but rather by the {@link LightDM.Greeter} class. * @memberOf LightDM */ -class LightDMSession { +class Session { constructor( { comment, key, name } ) { /** * The comment for the session. @@ -62,10 +62,10 @@ class LightDMSession { /** * Interface for object that holds info about a language on the system. Language objects are not - * created by the theme's code, but rather by the {@link LightDMGreeter} class. + * created by the theme's code, but rather by the {@link LightDM.Greeter} class. * @memberOf LightDM */ -class LightDMLanguage { +class Language { constructor( { code, name, territory } ) { /** * The code for the language. @@ -93,10 +93,10 @@ class LightDMLanguage { /** * Interface for object that holds info about a keyboard layout on the system. Language - * objects are not created by the theme's code, but rather by the {@link LightDMGreeter} class. + * objects are not created by the theme's code, but rather by the {@link LightDM.Greeter} class. * @memberOf LightDM */ -class LightDMLayout { +class Layout { constructor( { description, name, short_description } ) { /** * The description for the layout. @@ -124,10 +124,10 @@ class LightDMLayout { /** * Interface for object that holds info about a user account on the system. User - * objects are not created by the theme's code, but rather by the {@link LightDMGreeter} class. + * objects are not created by the theme's code, but rather by the {@link LightDM.Greeter} class. * @memberOf LightDM */ -class LightDMUser { +class User { constructor( user_info ) { /** * The display name for the user. diff --git a/src/gresource/js/ThemeHeartbeat.js b/src/gresource/js/ThemeHeartbeat.js index bd3d8a0..29c393b 100644 --- a/src/gresource/js/ThemeHeartbeat.js +++ b/src/gresource/js/ThemeHeartbeat.js @@ -1,5 +1,5 @@ /* - * heartbeat.js + * ThemeHeartbeat.js * * Copyright © 2016 Antergos Developers * diff --git a/src/gresource/js/ThemeUtils.js b/src/gresource/js/ThemeUtils.js index 0869c60..ad7ddd3 100644 --- a/src/gresource/js/ThemeUtils.js +++ b/src/gresource/js/ThemeUtils.js @@ -25,6 +25,14 @@ * along with lightdm-webkit2-greeter; If not, see . */ +if ( 'undefined' === typeof window.navigator.languages ) { + window.navigator.languages = [ window.navigator.language ]; +} + +moment.locale( window.navigator.languages ); +let localized_invalid_date = moment('today', '!@#'); + + /** * @namespace LightDM */ @@ -32,7 +40,7 @@ /** * Provides various utility methods for use by theme authors. The greeter will automatically * create an instance of this class when it starts. The instance can be accessed - * with the global variable: `theme_utils`. + * with the global variable: `theme_utils` ({@link window.theme_utils}). * * @memberOf LightDM */ @@ -44,7 +52,7 @@ class ThemeUtils { * * @return {function(new:*): Object} `context` with `this` bound to it for all of its methods. */ - static bind_this( context ) { + bind_this( context ) { let excluded_methods = ['constructor']; function not_excluded( _method, _context ) { @@ -67,6 +75,55 @@ class ThemeUtils { } } } + + + /** + * Returns the contents of directory found at `path` provided that the (normalized) `path` + * meets at least one of the following conditions: + * * Is located within the greeter themes' root directory. + * * Has been explicitly allowed in the greeter's config file. + * * Is located within the greeter's shared data directory (`/var/lib/lightdm-data`) + * + * @param {String} path The abs path to desired directory. + * + * @returns {String[]} List of abs paths for the files and directories found in `path`. + */ + dirlist( path ) {} + + /** + * Escape HTML entities in a string. + * + * @param {String} text The text to be escaped. + * + * @returns {String} + */ + esc_html( text ) {} + + + /** + * Get the current time in a localized format based on the `time_format` config file key. + * * When `time_format` has a valid value, time will be formatted + * according to that value. + * * 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. + */ + get_current_localized_time() { + let config_format = greeter_config.greeter.time_format; + let format = ( '' !== config_format ) ? config_format : 'LT'; + let local_time = moment().format( format ); + + if ( local_time === localized_invalid_date ) { + local_time = moment().format( 'LT' ); + } + + return local_time; + } + + + /** + * @deprecated Use {@link theme_utils.esc_html()} instead. + */ + txt2html( text ) {} } @@ -76,6 +133,7 @@ class ThemeUtils { */ window.theme_utils = __ThemeUtils; window.theme_utils.bind_this = ThemeUtils.bind_this; +window.theme_utils.get_current_localized_time = ThemeUtils.get_current_localized_time; /* -------->>> DEPRECATED! <<<-------- */ window.greeterutil = window.theme_utils; diff --git a/themes/antergos/js/greeter.js b/themes/antergos/js/greeter.js index e8e2dad..132a51b 100644 --- a/themes/antergos/js/greeter.js +++ b/themes/antergos/js/greeter.js @@ -64,11 +64,6 @@ class AntergosThemeUtils { this.$log_container = $('#logArea'); this.recursion = 0; this.cache_backend = ''; - this.heartbeat = ''; - - if ( 'undefined' === typeof window.navigator.languages ) { - window.navigator.languages = [ window.navigator.language ]; - } this.setup_cache_backend(); this.init_config_values();