From 1569a80607d302f1c437090aa714a9a0c7eaf153 Mon Sep 17 00:00:00 2001 From: Dustin Falgout Date: Tue, 22 Nov 2016 03:38:32 -0600 Subject: [PATCH] update default theme to use theme_utils for its clock. This closes #83 --- src/gresource/js/GreeterConfig.js | 39 ++++++++++++++++++++++++------- src/gresource/js/ThemeUtils.js | 2 +- themes/antergos/js/greeter.js | 8 ++----- 3 files changed, 33 insertions(+), 16 deletions(-) diff --git a/src/gresource/js/GreeterConfig.js b/src/gresource/js/GreeterConfig.js index e1e8a0d..8763864 100644 --- a/src/gresource/js/GreeterConfig.js +++ b/src/gresource/js/GreeterConfig.js @@ -30,6 +30,19 @@ let _branding = null, _greeter = null; +function set_values( defaults, target_obj, method ) { + let keys = Object.keys(defaults); + + keys.forEach( prop => { + try { + target_obj[prop] = method( 'greeter', prop ); + } catch(err) { + target_obj[prop] = defaults[prop]; + } + }); +} + + /** * 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 @@ -50,10 +63,17 @@ class GreeterConfig { * @readonly */ get branding() { - let props = ['background_images', 'logo', 'user_image']; - if ( null === _branding ) { - props.forEach( prop => _branding[prop] = this.get_str( 'branding', prop ) ); + let theme_dir = '/usr/share/lightdm-webkit/themes/antergos', + props = { + 'background_images': '/usr/share/backgrounds', + 'logo': `${theme_dir}/img/antergos-logo-user.png`, + 'user_image': `${theme_dir}/img/antergos.png` + }; + + _branding = {}; + + set_values( props, _branding, this.get_str ); } return _branding; @@ -73,15 +93,16 @@ class GreeterConfig { * @readonly */ get greeter() { - let bools = ['debug_mode', 'secure_mode'], - strings = ['time_format', 'time_language', 'webkit_theme']; - if ( null === _greeter ) { + let bools = {'debug_mode': true, 'secure_mode': true}, + strings = {'time_format': 'LT', 'time_language': 'auto', 'webkit_theme': 'antergos'}, + numbers = {'screensaver_timeout': 30}; + _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 ) ); + set_values( bools, _greeter, this.get_bool ); + set_values( strings, _greeter, this.get_str ); + set_values( numbers, _greeter, this.get_num ); } return _greeter; diff --git a/src/gresource/js/ThemeUtils.js b/src/gresource/js/ThemeUtils.js index de48c7b..66b6f85 100644 --- a/src/gresource/js/ThemeUtils.js +++ b/src/gresource/js/ThemeUtils.js @@ -125,7 +125,7 @@ const ThemeUtils = { } } - let local_time = moment().format( format ); + let local_time = moment().format( time_format ); if ( local_time === localized_invalid_date ) { local_time = moment().format( 'LT' ); diff --git a/themes/antergos/js/greeter.js b/themes/antergos/js/greeter.js index 132a51b..12a7b05 100644 --- a/themes/antergos/js/greeter.js +++ b/themes/antergos/js/greeter.js @@ -588,14 +588,10 @@ class AntergosTheme { * Setup the clock widget. */ initialize_clock() { - var saved_format = _util.cache_get( 'clock', 'time_format' ), - format = (null !== saved_format) ? saved_format : 'LT'; - - moment.locale( window.navigator.languages ); - this.$clock.html( moment().format( format ) ); + this.$clock.html( theme_utils.get_current_localized_time() ); setInterval( () => { - _self.$clock.html( moment().format( format ) ); + _self.$clock.html( theme_utils.get_current_localized_time() ); }, 60000 ); }