Browse Source

almost finished with initial implementation

sisyphus
Dustin Falgout 8 years ago
parent
commit
5925c78bf2
  1. 4
      themes/antergos/index.html
  2. 55
      themes/antergos/js/greeter.js
  3. 2
      themes/antergos/package.json
  4. 26
      web-greeter/bridge/Greeter.py
  5. 22
      web-greeter/bridge/ThemeUtils.py
  6. 23
      web-greeter/resources/js/ThemeUtils.js
  7. 19
      web-greeter/resources/js/bootstrap.js
  8. 2
      web-greeter/whither.yml

4
themes/antergos/index.html

@ -50,8 +50,8 @@
<script src="../_vendor/js/js.cookie.min.js"></script>
<!-- Theme JavaScript -->
<script type="text/javascript" src="js/translations.js"></script>
<script type="text/javascript" src="js/greeter.js"></script>
<script src="js/translations.js"></script>
<script src="js/greeter.js"></script>
</head>

55
themes/antergos/js/greeter.js

@ -182,36 +182,28 @@ class AntergosThemeUtils {
* Get some values from `lightdm-webkit2-greeter.conf` and save them for later.
*/
init_config_values() {
var logo, user_image, debug, background_images, background_images_dir;
if ( 'undefined' !== typeof( config ) ) {
logo = config.get_str( 'branding', 'logo' ) || 'img/antergos.png';
user_image = config.get_str( 'branding', 'user_image' ) || 'img/antergos-logo-user.png';
background_images_dir = config.get_str( 'branding', 'background_images' ) || '/usr/share/backgrounds';
debug = config.get_bool( 'greeter', 'debug_mode' ) || false;
if ( 'undefined' === typeof( greeter_config ) ) {
greeter_config = {branding: {}, greeter: {}};
}
if ( background_images_dir ) {
background_images = greeterutil.dirlist( background_images_dir ) || [];
_util.log(background_images);
}
this.logo = greeter_config.branding.logo || 'img/antergos.png';
this.user_image = greeter_config.branding.user_image || 'img/antergos-logo-user.png';
this.background_images_dir = greeter_config.branding.background_images || '/usr/share/backgrounds';
this.debug = greeter_config.greeter.debug_mode || false;
this.background_images = [];
if ( background_images && background_images.length ) {
background_images = this.find_images( background_images );
}
if ( this.background_images_dir ) {
theme_utils.dirlist( this.background_images_dir, true, ( result ) => {
this.background_images = result || [];
_util.log( this.background_images );
} );
}
this.logo = logo;
this.debug = debug;
this.user_image = user_image;
this.background_images = background_images;
this.background_images_dir = background_images_dir;
}
is_not_empty( value ) {
let empty_values = [null, 'null', undefined, 'undefined'];
return empty_values.findIndex(v => v === value) === -1;
return ! empty_values.includes(value);
}
@ -219,7 +211,7 @@ class AntergosThemeUtils {
var images = [],
subdirs = [];
for ( var file of dirlist ) {
for ( let file of dirlist ) {
if ( file.match( /(png|PNG)|(jpg|JPEG)|(bmp|BMP)/ ) ) {
images.push( file );
} else if ( ! file.match( /\w+\.\w+/ ) ) {
@ -227,14 +219,17 @@ class AntergosThemeUtils {
}
}
if ( subdirs.length && ! images.length && this.recursion < 3 ) {
if ( subdirs.length && images.length < 20 && this.recursion < 3 ) {
this.recursion++;
for ( var dir of subdirs ) {
var list = greeterutil.dirlist( dir );
if ( list && list.length ) {
images.push.apply( images, this.find_images( list ) );
}
for ( let dir of subdirs ) {
theme_utils.dirlist( dir, ( result ) => {
if ( result && result.length ) {
images.push.apply( images, this.find_images( result ) );
}
} );
}
}
@ -896,7 +891,7 @@ class AntergosTheme {
/**
* Initialize the theme once the window has loaded.
*/
$( window ).on('load', () => {
$( window ).on( 'GreeterReady', () => {
new AntergosThemeUtils();
new AntergosTheme();
} );

2
themes/antergos/package.json

@ -18,7 +18,7 @@
"config": {},
"wg_theme": {
"display_name": "Default",
"supports": ["2.2", "3"],
"supports": ["3"],
"entry_point": "./index.html",
"styles": [
"bootswatch-paper",

26
web-greeter/bridge/Greeter.py

@ -53,12 +53,22 @@ LightDMUsers = LightDM.UserList()
class Greeter(BridgeObject):
authentication_complete = bridge.signal(LightDM.Greeter)
autologin_timer_expired = bridge.signal(LightDM.Greeter)
idle = bridge.signal(LightDM.Greeter)
reset = bridge.signal(LightDM.Greeter)
show_message = bridge.signal((LightDM.Greeter, str, str), arguments=('text', 'type'))
show_prompt = bridge.signal((LightDM.Greeter, str, str), arguments=('text', 'type'))
authentication_complete = bridge.signal(LightDM.Greeter, name='authentication_complete')
autologin_timer_expired = bridge.signal(LightDM.Greeter, name='autologin_timer_expired')
idle = bridge.signal(LightDM.Greeter, name='idle')
reset = bridge.signal(LightDM.Greeter, name='reset')
show_message = bridge.signal(
(LightDM.Greeter, str, LightDM.MessageType),
name='show_message',
arguments=('text', 'type')
)
show_prompt = bridge.signal(
(LightDM.Greeter, str, LightDM.PromptType),
name='show_prompt',
arguments=('text', 'type')
)
def __init__(self, themes_dir, *args, **kwargs):
super().__init__(name='LightDMGreeter', *args, **kwargs)
@ -81,8 +91,8 @@ class Greeter(BridgeObject):
LightDMGreeter.connect('autologin-timer-expired', self.authentication_complete.emit)
LightDMGreeter.connect('idle', self.idle.emit)
LightDMGreeter.connect('reset', self.reset.emit)
LightDMGreeter.connect('show-message', self.reset.emit)
LightDMGreeter.connect('show-prompt', self.reset.emit)
LightDMGreeter.connect('show-message', self.show_message.emit)
LightDMGreeter.connect('show-prompt', self.show_prompt.emit)
@bridge.prop(str)
def authentication_user(self):

22
web-greeter/bridge/ThemeUtils.py

@ -28,7 +28,7 @@
# Standard Lib
import os
import os.path as path
from glob import glob
# 3rd-Party Libs
from whither.bridge import (
@ -47,14 +47,14 @@ class ThemeUtils(BridgeObject):
self._user_config = user_config
self._greeter = greeter
@bridge.method(Variant)
def dirlist(self, dir_path):
@bridge.method(str, bool, name='dirlist', result=Variant)
def dirlist(self, dir_path, only_images=True):
if not dir_path or not isinstance(dir_path, str):
return []
dir_path = path.realpath(path.normpath(dir_path))
dir_path = os.path.realpath(os.path.normpath(dir_path))
if not path.isabs(dir_path) or not path.isdir(dir_path):
if not os.path.isabs(dir_path) or not os.path.isdir(dir_path):
return []
allowed = False
@ -73,7 +73,15 @@ class ThemeUtils(BridgeObject):
if not allowed:
return []
return (path.join(dir_path, f) for f in os.listdir(dir_path))
if only_images:
file_types = ('jpg', 'jpeg', 'png', 'gif', 'bmp')
result = [
glob('{0}/**/*.{1}'.format(dir_path, ftype), recursive=True)
for ftype in file_types
]
result = [image for image_list in result for image in image_list]
else:
result = [os.path.join(dir_path, f) for f in os.listdir(dir_path)]
return result

23
web-greeter/resources/js/ThemeUtils.js

@ -25,11 +25,6 @@
* along with lightdm-webkit2-greeter; If not, see <http://www.gnu.org/licenses/>.
*/
/*if ( 'undefined' === typeof window.navigator.languages ) {
window.navigator.languages = [ window.navigator.language ];
}*/
let localized_invalid_date = null,
time_language = null,
@ -109,20 +104,20 @@ class ThemeUtils {
* * Is located within the greeter's shared data directory (`/var/lib/lightdm-data`).
* * Is located in `/tmp`.
*
* @param {string} path The abs path to desired directory.
*
* @returns {string[]} List of abs paths for the files and directories found in `path`.
* @param {string} path The abs path to desired directory.
* @param {boolean} only_images Include only images in the results. Default `true`.
* @param {function(string[])} callback Callback function to be called with the result.
*/
dirlist( path ) {
dirlist( path, only_images = true, callback ) {
let allowed = false;
if ( '' === path || 'string' !== typeof path ) {
console.log('[ERROR] theme_utils.dirlist(): path must be a non-empty string!');
return [];
return callback([]);
} else if ( null !== path.match(/^[^/].+/) ) {
console.log('[ERROR] theme_utils.dirlist(): path must be absolute!');
return[];
return callback([]);
}
if ( null !== path.match(/\/\.+(?=\/)/) ) {
@ -136,15 +131,15 @@ class ThemeUtils {
if ( ! Object.keys( allowed_dirs ).some( dir => path.startsWith( allowed_dirs[dir] ) ) ) {
console.log(`[ERROR] theme_utils.dirlist(): path is not allowed: ${path}`);
return [];
return callback([]);
}
try {
return _ThemeUtils.dirlist( path );
return _ThemeUtils.dirlist( path, only_images, callback );
} catch( err ) {
console.log( `[ERROR] theme_utils.dirlist(): ${err}` );
return [];
return callback([]);
}
}

19
web-greeter/resources/js/bootstrap.js vendored

@ -25,12 +25,12 @@
* along with lightdm-webkit2-greeter; If not, see <http://www.gnu.org/licenses/>.
*/
let _channel;
const _ready_event = new Event( 'GreeterReady' );
(() => {
let _channel;
const _ready_event = new Event( 'GreeterReady' );
function initialize() {
new QWebChannel( qt.webChannelTransport, channel => {
function channel_ready_cb( channel ) {
_channel = channel;
/**
@ -75,11 +75,14 @@ function initialize() {
*/
window.greeterutil = window.theme_utils;
setTimeout(function() {
setTimeout( function () {
window.dispatchEvent( _ready_event );
}, 400);
}, 2 );
}
document.addEventListener( 'DOMContentLoaded', ( event ) => {
new QWebChannel( qt.webChannelTransport, channel_ready_cb );
});
}
})();
setTimeout( initialize, 50 );

2
web-greeter/whither.yml

@ -28,4 +28,4 @@ WebGreeter:
# App's Config
app:
themes_dir: /usr/share/lightdm-webkit/themes
themes_dir: /home/dustin/github/antergos/lightdm-webkit2-greeter/themes

Loading…
Cancel
Save