Browse Source

arrange structure so that the real greeter class and the mock greeter class can both be derived from the same base class.

sisyphus
Dustin Falgout 8 years ago
parent
commit
4679fa9714
  1. 186
      src/gresource/js/WK2Greeter.js
  2. 179
      src/gresource/js/base/LightDMGreeter.js

186
src/gresource/js/WK2Greeter.js

@ -0,0 +1,186 @@
/*
* WK2Greeter.js
*
* Copyright © 2016 Antergos Developers <dev@antergos.com>
*
* This file is part of lightdm-webkit2-greeter.
*
* lightdm-webkit2-greeter 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
* (at your option) any later version.
*
* lightdm-webkit2-greeter 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 the 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 lightdm-webkit2-greeter; If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @memberOf LightDM
*/
class WK2Greeter extends LightDMGreeter {
constructor( bridge ) {
if ( 'lightdm' in window ) {
return window.lightdm;
}
super();
window.lightdm = GreeterUtils.bind_this( this );
this.bridge = bridge;
return window.lightdm;
}
get authentication_user() {
return this.bridge.get_string( 'authentication_user' );
}
get autologin_guest() {
return this.bridge.get_bool( 'autologin_guest' );
}
get autologin_timeout() {
return this.bridge.get_num( 'autologin_timeout' );
}
get autologin_user() {
return this.bridge.get_string( 'autologin_user' );
}
get can_hibernate() {
return this.bridge.get_bool( 'can_hibernate' );
}
get can_restart() {
return this.bridge.get_bool( 'can_restart' );
}
get can_shutdown() {
return this.bridge.get_bool( 'can_shutdown' );
}
get can_suspend() {
return this.bridge.get_bool( 'can_suspend' );
}
get default_session() {
return this.bridge.get_string( 'default_session' );
}
get has_guest_account() {
return this.bridge.get_bool( 'has_guest_account' );
}
get hide_users() {
return this.bridge.get_bool( 'hide_users' );
}
get hostname() {
return this.bridge.get_string( 'hostname' );
}
get in_authentication() {
return this.bridge.get_bool( 'in_authentication' );
}
get is_authenticated() {
return this.bridge.get_bool( 'is_authenticated' );
}
get language() {
return this.bridge.get_object( 'language' );
}
get languages() {
return this.bridge.get_objects( 'languages' );
}
get layout() {
return this.bridge.get_object( 'layout' );
}
set layout( value ) {
this._layout = value;
}
get layouts() {
return this.bridge.get_objects( 'layouts' );
}
get lock_hint() {
return this.bridge.get_bool( 'lock_hint' );
}
get num_users() {
return this.users.length;
}
get select_guest_hint() {
return this.bridge.get_bool( 'select_guest_hint' );
}
get select_user_hint() {
return this.bridge.get_string( 'select_user_hint' );
}
get sessions() {
return this.bridge.get_objects( 'sessions' );
}
get users() {
return this.bridge.get_objects( 'users' );
}
authenticate( username = null ) {}
authenticate_as_guest() {}
cancel_authentication() {}
cancel_autologin() {}
get_hint( name ) {}
hibernate() {
return this._do_mocked_system_action('hibernate');
}
respond( response ) {}
restart() {
return this._do_mocked_system_action('restart');
}
set_language( language ) {}
shutdown() {
return this._do_mocked_system_action('shutdown');
}
start_session( session ) {}
suspend() {
return this._do_mocked_system_action('suspend');
}
}
window.WK2Greeter = WK2Greeter;

179
src/gresource/js/base/LightDMGreeter.js

@ -27,82 +27,31 @@
/** /**
* Singleton class which implements the LightDMGreeter Interface. Greeter themes will * Base class for the greeter's JavaScript Theme API. Greeter themes will interact
* interact directly with this class to facilitate the user log in processes. * directly with an object derived from this class to facilitate the user log-in process.
* The greeter will automatically create an instance of this class when it starts. * The greeter will automatically create an instance when it starts.
* The instance can be accessed with the global variable: `lightdm`. * The instance can be accessed using the global variable: `lightdm`.
* @memberOf LightDM * @memberOf LightDM
*/ */
class LightDMGreeter { class LightDMGreeter {
constructor() { constructor() {
if ( null !== lightdm ) { if ( 'lightdm' in window ) {
return lightdm; return window.lightdm;
} }
lightdm = this; window.lightdm = GreeterUtils.bind_this( this );
this._mock_data = MockData();
this._initialize(); return window.lightdm;
}
/**
* @private
*/
_do_mocked_system_action( action ) {
alert(`System ${action} triggered.`);
document.location.reload(true);
return true;
}
/**
* @private
*/
_initialize() {
this._set_default_property_values();
}
/**
* @private
*/
_populate_ldm_object_arrays() {
for ( let object_type of ['sessions', 'users', 'languages', 'layouts'] ) {
let object_name = object_type.slice(0, -1).capitalize(),
ObjectClass = `LightDM${object_name}`;
for ( let object_info of this._mock_data[object_type] ) {
this[object_type].push(MockObjects[ObjectClass](object_info));
}
}
}
/**
* @private
*/
_set_default_property_values() {
for ( let property_type of Object.keys(this._mock_data.greeter.properties) ) {
for ( let property of this._mock_data.greeter.properties[property_type] ) {
if ( property.indexOf('can_') > -1 ) {
// System Power Actions
this[`_${property}`] = true;
} else {
this[`_${property}`] = this._mock_data.greeter.default_values[property_type]();
}
}
}
this._populate_ldm_object_arrays();
} }
/** /**
* The username of the user being authenticated or {@link null} * The username of the user being authenticated or {@link null}
* if no authentication is in progress. * if there is no authentication in progress.
* @type {String|null} * @type {String|null}
* @readonly * @readonly
*/ */
get authentication_user() { get authentication_user() {}
return this._authentication_user;
}
/** /**
* Whether or not the guest account should be automatically logged * Whether or not the guest account should be automatically logged
@ -110,165 +59,126 @@ class LightDMGreeter {
* @type {Boolean} * @type {Boolean}
* @readonly * @readonly
*/ */
get autologin_guest() { get autologin_guest() {}
return this._autologin_guest;
}
/** /**
* The number of seconds to wait before automatically logging in. * The number of seconds to wait before automatically logging in.
* @type {Number} * @type {Number}
* @readonly * @readonly
*/ */
get autologin_timeout() { get autologin_timeout() {}
return this._autologin_timeout;
}
/** /**
* The username with which to automatically log in when the timer expires. * The username with which to automatically log in when the timer expires.
* @type {String} * @type {String}
* @readonly * @readonly
*/ */
get autologin_user() { get autologin_user() {}
return this._autologin_user;
}
/** /**
* Whether or not the greeter can make the system hibernate. * Whether or not the greeter can make the system hibernate.
* @type {Boolean} * @type {Boolean}
* @readonly * @readonly
*/ */
get can_hibernate() { get can_hibernate() {}
return this._can_hibernate;
}
/** /**
* Whether or not the greeter can make the system restart. * Whether or not the greeter can make the system restart.
* @type {Boolean} * @type {Boolean}
* @readonly * @readonly
*/ */
get can_restart() { get can_restart() {}
return this._can_restart;
}
/** /**
* Whether or not the greeter can make the system shutdown. * Whether or not the greeter can make the system shutdown.
* @type {Boolean} * @type {Boolean}
* @readonly * @readonly
*/ */
get can_shutdown() { get can_shutdown() {}
return this._can_shutdown;
}
/** /**
* Whether or not the greeter can make the system suspend/sleep. * Whether or not the greeter can make the system suspend/sleep.
* @type {Boolean} * @type {Boolean}
* @readonly * @readonly
*/ */
get can_suspend() { get can_suspend() {}
return this._can_suspend;
}
/** /**
* The name of the default session. * The name of the default session.
* @type {String} * @type {String}
* @readonly * @readonly
*/ */
get default_session() { get default_session() {}
return this._default_session;
}
/** /**
* Whether or not guest sessions are supported. * Whether or not guest sessions are supported.
* @type {Boolean} * @type {Boolean}
* @readonly * @readonly
*/ */
get has_guest_account() { get has_guest_account() {}
return this._has_guest_account;
}
/** /**
* Whether or not user accounts should be hidden. * Whether or not user accounts should be hidden.
* @type {Boolean} * @type {Boolean}
* @readonly * @readonly
*/ */
get hide_users() { get hide_users() {}
return this._hide_users;
}
/** /**
* The system's hostname. * The system's hostname.
* @type {String} * @type {String}
* @readonly * @readonly
*/ */
get hostname() { get hostname() {}
return this._hostname;
}
/** /**
* Whether or not the greeter is in the process of authenticating. * Whether or not the greeter is in the process of authenticating.
* @type {Boolean} * @type {Boolean}
* @readonly * @readonly
*/ */
get in_authentication() { get in_authentication() {}
return this._in_authentication;
}
/** /**
* Whether or not the greeter has successfully authenticated. * Whether or not the greeter has successfully authenticated.
* @type {Boolean} * @type {Boolean}
* @readonly * @readonly
*/ */
get is_authenticated() { get is_authenticated() {}
return this._is_authenticated;
}
/** /**
* The current language or {@link null} if no language. * The current language or {@link null} if no language.
* @type {LightDMLanguage|null} * @type {LightDMLanguage|null}
* @readonly * @readonly
*/ */
get language() { get language() {}
return this._language;
}
/** /**
* A list of languages to present to the user. * A list of languages to present to the user.
* @type {LightDMLanguage[]} * @type {LightDMLanguage[]}
* @readonly * @readonly
*/ */
get languages() { get languages() {}
return this._languages;
}
/** /**
* The currently active layout for the selected user. * The currently active layout for the selected user.
* @type {LightDMLayout} * @type {LightDMLayout}
*/ */
get layout() { get layout() {}
return this._layout; set layout( value ) {}
}
set layout( value ) {
this._layout = value;
}
/** /**
* A list of keyboard layouts to present to the user. * A list of keyboard layouts to present to the user.
* @type {LightDMLayout[]} * @type {LightDMLayout[]}
* @readonly * @readonly
*/ */
get layouts() { get layouts() {}
return this._layouts;
}
/** /**
* Whether or not the greeter was started as a lock screen. * Whether or not the greeter was started as a lock screen.
* @type {Boolean} * @type {Boolean}
* @readonly * @readonly
*/ */
get lock_hint() { get lock_hint() {}
return this._lock_hint;
}
/** /**
* The number of users able to log in. * The number of users able to log in.
@ -284,36 +194,28 @@ class LightDMGreeter {
* @type {Boolean} * @type {Boolean}
* @readonly * @readonly
*/ */
get select_guest_hint() { get select_guest_hint() {}
return this._select_guest_hint;
}
/** /**
* The username to select by default. * The username to select by default.
* @type {String} * @type {String}
* @readonly * @readonly
*/ */
get select_user_hint() { get select_user_hint() {}
return this._select_user_hint;
}
/** /**
* List of available sessions. * List of available sessions.
* @type {LightDMSession[]} * @type {LightDMSession[]}
* @readonly * @readonly
*/ */
get sessions() { get sessions() {}
return this._sessions;
}
/** /**
* List of available users. * List of available users.
* @type {LightDMUser[]} * @type {LightDMUser[]}
* @readonly * @readonly
*/ */
get users() { get users() {}
return this._users;
}
/** /**
@ -329,7 +231,7 @@ class LightDMGreeter {
authenticate_as_guest() {} authenticate_as_guest() {}
/** /**
* Cancel user authentication that is currently in progress. * Cancel the user authentication that is currently in progress.
*/ */
cancel_authentication() {} cancel_authentication() {}
@ -369,8 +271,7 @@ class LightDMGreeter {
/** /**
* Set the language for the currently authenticated user. * Set the language for the currently authenticated user.
* @arg {String} language The language in the form of a locale specification (e.g. * @arg {String} language The language in the form of a locale specification (e.g. 'de_DE.UTF-8')
* 'de_DE.UTF-8')
* @returns {Boolean} {@link true} if successful, otherwise {@link false} * @returns {Boolean} {@link true} if successful, otherwise {@link false}
*/ */
set_language( language ) {} set_language( language ) {}
@ -379,9 +280,7 @@ class LightDMGreeter {
* Triggers the system to shutdown. * Triggers the system to shutdown.
* @returns {Boolean} {@link true} if shutdown initiated, otherwise {@link false} * @returns {Boolean} {@link true} if shutdown initiated, otherwise {@link false}
*/ */
shutdown() { shutdown() {}
return this._do_mocked_system_action('shutdown');
}
/** /**
* Start a session for the authenticated user. * Start a session for the authenticated user.
@ -394,13 +293,11 @@ class LightDMGreeter {
* Triggers the system to suspend/sleep. * Triggers the system to suspend/sleep.
* @returns {Boolean} {@link true} if suspend/sleep initiated, otherwise {@link false} * @returns {Boolean} {@link true} if suspend/sleep initiated, otherwise {@link false}
*/ */
suspend() { suspend() {}
return this._do_mocked_system_action('suspend');
}
} }
window.LightDMGreeter = LightDMGreeter;

Loading…
Cancel
Save