Compare commits

..

No commits in common. "master" and "dev" have entirely different histories.
master ... dev

6 changed files with 268 additions and 512 deletions

2
.gitignore vendored
View File

@ -1,2 +0,0 @@
# jsdoc-generated documentation
doc

23
.vscode/tasks.json vendored
View File

@ -1,23 +0,0 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "jsdoc",
"type": "process",
"command": "jsdoc",
"args": ["src/LightDMMock.js", "-c", "jsdoc.json", "-d", "doc"],
"detail": "Generate documentation",
"presentation": {
"echo": false,
"reveal": "silent",
"showReuseMessage": false,
"panel": "dedicated",
"close": true,
},
"group": {
"kind": "build",
"isDefault": true,
},
}
]
}

View File

@ -1,3 +0,0 @@
{
"plugins": ["plugins/markdown"]
}

View File

@ -1,6 +1,6 @@
The MIT License (MIT) The MIT License (MIT)
Copyright (c) 2021 EliasSchriefer <elischriefer@gmail.com> Copyright (c) 2016 Roel Walraven <mail@cytodev.io>
Permission is hereby granted, free of charge, to any person obtaining a copy of Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in this software and associated documentation files (the "Software"), to deal in

View File

@ -1,74 +1,75 @@
# LightDMMock # LightDMMock
A LightDM Mock that is written in modern JavaScript and based on [cytodev](https://github.com/cytodev)'s [LightDMMock](https://github.com/cytodev/LightDMMock), the lightdm-webkit2-greeter [manual](https://man.archlinux.org/man/community/lightdm-webkit2-greeter/lightdm-webkit2-greeter.1.en), the [LightDM API documentation](https://people.ubuntu.com/~robert-ancell/lightdm/reference/), and the latest version of [Antergos](https://github.com/Antergos)' lightdm-webkit2-greeter [source code](https://github.com/Antergos/web-greeter). <font style="color:red">Please note that the deprecation errors are intrusive for a reason.</font> A LightDM Mock that is tightly based on the source [C code](https://github.com/Antergos/web-greeter/blob/before-python/src/webkit2-extension.c) of [Antergos](https://github.com/Antergos)' [lightdm-webkit2-greeter](https://github.com/Antergos/lightdm-webkit2-greeter). <font style="color:red">Please note that the deprecation errors are intrusive for a reason.</font>
## Usage
1. Clone the repo
```bash
git clone https://git.sfs.ddnss.org/EliasSchriefer/LightDMMock
```
2. Set the type of your JavaScript to `module` in your theme that needs mocking
```html
<script type="module" src="main.js"></script>
```
```html
<script type="module">
...
</script>
```
3. Import `LightDMMock` and create a new instance
```javascript
import LightDMMock from "LightDMMock/src/LightDMMock.js";
## Usage:
[1]. Clone the repo
````bash
git clone git@github.com:CytoDev/LightDMMock.git
````
[2]. Include the file in your theme that needs mocking<br>
````html
<script type="text/javascript" src="mock/LightDMMock.js"></script>
````
[3]. Create a new instance of LightDMMock
````javascript
if(!("lightdm" in window)) {
var LightDMMock = LightDMMock || {};
window.lightdm = new LightDMMock(autofill, timeout, autoGuest); window.lightdm = new LightDMMock(autofill, timeout, autoGuest);
``` }
````
## Note ## Note:
If you plan on using the `.face` files in the mock you have to include the path to `LightDMMock/src`. The `.face` files linked in `users.json` are absolute links to `/home/[username]/.face`. If you plan on using the `.face` files in the mock you have to include the path to `LightDMMock/src`. The `.face` files linked in `users.json` are absolute links to `/home/[username]/.face`.
## Parameters of `LightDMMock()` ## Parameters of LightDMMock()
> **autofill**: `boolean` #### autofill
> > **_`boolean`_**<br>
> Whether or not the arrays for users, languages, layouts, and sessions need to be filled with mock data. I advise to test both to make your theme less prone to crashing. > Wether or not the arrays for users, languages, layouts, and sessions need to be filled with mock data. I advise to test both to make your theme less prone to crashing.
> ---
> **timeout**: `number`
> #### timeout
> **_`number`_**<br>
> Value to use for simulated autologin (this value is in seconds). > Value to use for simulated autologin (this value is in seconds).
> ---
> **autoGuest**: `boolean`
> #### autoGuest
> Whether or not to simulate automatic guest login. This will also enable a guest account in `lightdm.has_guest_account`. > **_`boolean`_**<br>
> Wether or not to simulate automatic guest login. This will also enable a guest account in `lightdm.has_guest_account`.
--- ---
### A friendly reminder ### A friendly reminder
The following functions **must** be provided by the custom greeter, which LightDM will call in the process of authenticating the user. This can be found in the original documentation (man pages) of the webkit-greeter, but I have posted them here for your convenience. The following functions __must__ be provided by the custom greeter, which LightDM will call in the process of authenticating the user. This can be found in the original documentation (man pages) of the webkit-greeter, but I have posted them here for your convenience.
> **show_prompt(text, type)** > __show\_prompt(text, type)__<br>
> > ````
> This will be called when LightDM needs to prompt the user for some reason, such > This will be called when LightDM needs to prompt the user for some reason, such
> as asking for a password. The "text" parameter will be the text of the prompt, > as asking for a password. The "text" parameter will be the text of the prompt,
> and the "type" parameter will either be "text" for a visible prompt, or > and the "type" parameter will either be "text" for a visible prompt, or
> "password" for a prompt that the input should be hidden. > "password" for a prompt that the input should be hidden.
> ````
> >
> **show_message(text, type)**
> > __show\_message(text, type)__<br>
> ````
> This will be called when LightDM needs to display some info for the user. The > This will be called when LightDM needs to display some info for the user. The
> "text" parameter will be the text of the message, and the "type" parameter will > "text" parameter will be the text of the message, and the "type" parameter will
> either be "info" for an information message, or "error" for an error message > either be "info" for an information message, or "error" for an error message
> that LightDM has encountered. > that LightDM has encountered.
> ````
> >
> **authentication_complete()** > __authentication\_complete()__<br>
> > ````
> This function is called by LightDM when authentication has completed. > This function is called by LightDM when authentication has completed.
> ````
> >
> **autologin_timer_expired()** > __autologin\_timer\_expired()__<br>
> > ````
> This function is called by LightDM when an autologin user's login timer has > This function is called by LightDM when an autologin user's login timer has
> expired. The greeter should reset the authentication process. > expired. The greeter should reset the authentication process.
> ````
### License ### License:
This project is licensed under the MIT License. You can find a copy of the license [here](https://git.sfs.ddnss.org/EliasSchriefer/LightDMMock/license.md). This project is licensed under the MIT License. You can find a copy of the license [here](https://github.com/CytoDev/LightDMMock/license.md).
### Contributions ### Contributions:
You are more than welcome to submit issues as well as feature requests or just a 'how-ya-doin' in the [issue tracker](https://git.sfs.ddnss.org/EliasSchriefer/LightDMMock/issues/new). Contributing to the project can be done by forking it and submitting a pull request once it's all tested and tidy. You are more than welcome to submit issues as well as feature requests or just a 'how-ya-doin' in the [issue tracker](https://github.com/CytoDev/LightDMMock/issues/new). Contributing to the project can be done by forking it and submitting a pull request once it's all tested and tidy.

View File

@ -1,365 +1,156 @@
/** /**
* @author Elias Schriefer <elischriefer@gmail.com> * LightDMMock "class"
* @alias lightdm
* @classdesc
* A LightDM Mock that is written in modern JavaScript and based on
* [cytodev](https://github.com/cytodev)'s
* [LightDMMock](https://github.com/cytodev/LightDMMock), the lightdm-webkit2-greeter
* [manual](https://man.archlinux.org/man/community/lightdm-webkit2-greeter/lightdm-webkit2-greeter.1.en),
* the [LightDM API documentation](https://people.ubuntu.com/~robert-ancell/lightdm/reference/),
* and the latest version of [Antergos](https://github.com/Antergos)'
* lightdm-webkit2-greeter [source code](https://github.com/Antergos/web-greeter).
* <font style="color:red">Please note that the deprecation errors are intrusive for a reason.</font>
* *
* This is a rewrite in modern JavaScript. * @author Roel Walraven <mail@cytodev.io>
* *
* ##### Usage: * A LightDM Mock that is tightly based on the source C code of
* 1. Set the type of your JavaScript to `module` in your theme that needs mocking * Antergos' lightdm-webkit2-greeter. Please note that the deprecation errors
* ```html * are intrusive for a reason.
* <script type="module" src="main.js"></script>
* ```
* ```html
* <script type="module">
* ...
* </script>
* ```
*
* 2. Import {@link LightDMMock} and create a new instance
* ```javascript
* import LightDMMock from "LightDMMock/src/LightDMMock.js";
* *
* Usage:
* Include the file in your theme that needs mocking
* <script type="text/javascript" src="mock/LightDMMock.js"></script>
* Create a new instance of LightDMMock
* if(!("lightdm" in window)) {
* var LightDMMock = LightDMMock || {};
* window.lightdm = new LightDMMock(autofill, timeout, autoGuest); * window.lightdm = new LightDMMock(autofill, timeout, autoGuest);
* ``` * }
* * If you want to use the .face images don't forget to add the path to
* If you want to use the `.face` images don't forget to add the path to * LightDMMock/src to the image src. The users.json file has absolute paths
* `LightDMMock/src` to the image src. The `users.json` file has absolute paths
* like you would expect on a real filesystem. * like you would expect on a real filesystem.
*
* @param {boolean} autofill [wether or not the arrays for users, languages,
* layouts, and sessions need to be filled with mock
* data. I advise to test both to make your theme
* less prone to crashing.]
* @param {number} timeout [Value to use for simulated autologin (this value
* is in seconds).]
* @param {boolean} autoGuest [Wether or not to simulate automatic guest login.
* This will also enable a guest account
* in lightdm.has_guest_account]
*/ */
class LightDMMock { "use strict";
function LightDMMock(autofill, timeout, autoGuest) {
window.checkForUpdate("v1.1.0");
// see <https://github.com/Antergos/web-greeter/blob/before-python/src/webkit2-extension.c#L1470-L1504> // see <https://github.com/Antergos/web-greeter/blob/before-python/src/webkit2-extension.c#L1470-L1504>
// and <https://github.com/Antergos/web-greeter/blob/master/web-greeter/resources/js/docs/Greeter.js#L49-L240>
/** this.authentication_user = null;
* @type {?String} this.autologin_guest = false;
* @desc this.autologin_timeout = 0;
* The username of the authentication user being authenticated this.autologin_user = null;
* or null if no authentication is in progress. this.can_hibernate = false;
*/ this.can_restart = false;
authentication_user = null; this.can_shutdown = false;
this.can_suspend = false;
this.default_session = null;
this.has_guest_account = false;
this.hide_users = false;
this.hostname = null;
this.in_authentication = false;
this.is_authenticated = false;
this.language = null;
this.languages = null;
this.layout = null;
this.layouts = null;
this.lock_hint = false;
this.num_users = 0;
this.select_guest_hint = null;
this.select_user_hint = null;
this.sessions = null;
this.users = null;
this.default_language = null; // Deprecated
this.default_layout = null; // Deprecated
this.select_guest = null; // Deprecated
this.select_user = null; // Deprecated
this.timed_login_delay = null; // Deprecated
this.timed_login_user = null; // Deprecated
/** if(typeof autofill === "boolean" && autofill) {
* @type {boolean} var me = document.querySelector("script[src$=\"LightDMMock.js\"]");
* @desc
* Indicates the guest user should be used for autologin.
*/
autologin_guest = false;
/** if(!(me instanceof HTMLElement))
* @type {number} return window.console.error("Could not find my script element.");
* @desc
* The number of seconds to wait before automatically logging
* in. The older variable {@link lightdm.timed_user_delay} has
* been deprecated.
*/
autologin_timeout = 0;
/** var includePath = me.src;
* @type {?String}
* @desc
* The name of the user account that should be logged into
* automatically after timed login delay has passed. The older
* variable {@link lightdm.timed_login_user} has been deprecated.
*/
autologin_user = null;
/** if(includePath === undefined)
* @type {boolean} return window.console.error("Could not find my src attribute.");
* @desc
* Whether or not the system can be made to hibernate by the
* greeter.
*/
can_hibernate = false;
/**
* @type {boolean}
* @desc
* Whether or not the system can be restarted by the greeter.
*/
can_restart = false;
/**
* @type {boolean}
* @desc
* Whether or not the system can be shutdown by the greeter.
*/
can_shutdown = false;
/**
* @type {boolean}
* @desc
* Whether or not the system can be suspended by the greeter.
*/
can_suspend = false;
/**
* @deprecated
*/
default_language = null;
/**
* @deprecated
*/
default_layout = null;
/**
* @type {?String}
* @desc
* The name of the default session (as configured in
* `lightdm.conf`).
*/
default_session = null;
/**
* @type {boolean}
* @desc
* A guest account is available for login.
*/
has_guest_account = false;
/**
* @type {boolean}
* @desc
* The whole list of users should not be displayed.
*/
hide_users = false;
/**
* @type {String}
* @desc
* The hostname of the system.
*/
hostname = null;
/**
* @type {boolean}
* @desc
* Indicates if the user has successfully authenticated.
*/
is_authenticated = false;
/**
* @type {boolean}
* @desc
* Indicates if lightdm is currently in the authentication
* phase.
*/
in_authentication = false;
/**
* @type {?String}
* @desc
* The currently selected language. The older variable name
* {@link lightdm.default_language} is deprecated.
*/
language = null;
/**
* @type {LightDMLanguage[]}
* @desc
* The languages that are available on the system.
*/
languages = null;
/**
* @type {String}
* @desc
* The name of the currently active keyboard layout. To change
* the layout, assign a valid layout name to this variable. The older
* variable name {@link lightdm.default_layout} is deprecated.
*/
layout = null;
/**
* @type {LightDMLayout[]}
* @desc
* The keyboard layouts that are available on the system.
*/
layouts = null;
/**
* @type {boolean}
* @desc
* `true` if the greeter was triggered by locking the seat.
*/
lock_hint = false;
/**
* @type {number}
* @desc
* The number of users able to log in.
*/
num_users = 0;
/**
* @deprecated
* @type {boolean}
* @desc
* The guest user should be selected by default for login.
*/
select_guest = null;
/**
* @type {boolean}
* @desc
* `true` if the guest account should be selected by default.
*/
select_guest_hint = false;
/**
* @deprecated
* @type {?String}
* @desc
* The username that should be selected by default for login.
*/
select_user = null;
/**
* @type {?String}
* @desc
* A username or `null` if no particular user should be selected.
*/
select_user_hint = null;
/**
* @type {LightDMSession[]}
* @desc
* The sessions that are available on the system.
*/
sessions = null;
/**
* @deprecated
*/
timed_login_delay = null;
/**
* @deprecated
*/
timed_login_user = null;
/**
* @type {LightDMUser[]}
* @desc
* The users that are able to log in.
*/
users = null;
/**
* @param {boolean} [autofill=false]
* Whether or not the arrays for users, languages, layouts, and sessions need to be filled with mock
* data. I advise to test both to make your theme less prone to crashing.
*
* @param {number} [timeout=0]
* Value to use for simulated autologin (this value is in seconds).
*
* @param {boolean} [autoGuest=false]
* Whether or not to simulate automatic guest login. This will also enable a guest account in
* {@link LightDMMock.has_guest_account lightdm.has_guest_account}
*/
constructor(autofill = false, timeout = 0, autoGuest = false) {
checkForUpdate("v1.1.0");
if (typeof autofill == "boolean" && autofill) {
let includePath = import.meta.url;
if (includePath == undefined) {
return console.error("Could not get module URL.");
}
includePath = includePath.substr(0, includePath.lastIndexOf("/")); includePath = includePath.substr(0, includePath.lastIndexOf("/"));
const rejectionHandler = response => { var asyncLoadEnd = function(that) {
console.warn(`${response.url.substr(response.url.lastIndexOf("/") + 1)} did not load correctly.`); that.default_session = that.sessions[0].name;
}; that.language = that.languages[0].name;
that.layout = that.layouts[0].name;
that.num_users = that.users.length;
// see <https://github.com/Antergos/web-greeter/blob/master/web-greeter/resources/js/docs/LightDMObjects.js#L169-L253> if(typeof timeout === "number" && timeout > 0) {
const usersJSON = loadJSON(`${includePath}/json/users.json`); if(typeof autoGuest === "boolean" && autoGuest) {
usersJSON that.autologin_user = null;
.then(json => { that.autologin_guest = autoGuest;
this.users = json;
}, rejectionHandler)
// see <https://github.com/Antergos/web-greeter/blob/master/web-greeter/resources/js/docs/LightDMObjects.js#L85-L124>
const languagesJSON = loadJSON(`${includePath}/json/languages.json`);
languagesJSON
.then(json => {
this.languages = json;
}, rejectionHandler);
// see <https://github.com/Antergos/web-greeter/blob/master/web-greeter/resources/js/docs/LightDMObjects.js#L127-L166>
const layoutsJSON = loadJSON(`${includePath}/json/layouts.json`);
layoutsJSON
.then(json => {
this.layouts = json;
}, rejectionHandler);
// see <https://github.com/Antergos/web-greeter/blob/master/web-greeter/resources/js/docs/LightDMObjects.js#L43-L82>
const sessionsJSON = loadJSON(`${includePath}/json/sessions.json`);
sessionsJSON
.then(json => {
this.sessions = json;
}, rejectionHandler);
Promise.all([usersJSON, languagesJSON, layoutsJSON, sessionsJSON])
.then(() => {
this.default_session = this.sessions[0].name;
this.language = this.languages[0].name;
this.layout = this.layouts[0].name;
this.num_users = this.users.length;
if (typeof timeout == "number" && timeout > 0) {
if (typeof autoGuest == "boolean" && autoGuest) {
this.autologin_user = null;
this.autologin_guest = autoGuest;
} else {
this.autologin_user = this.users[0].username;
} }
this.autologin_timeout = timeout * 1000; that.autologin_user = that.users[0].username;
that.autologin_timeout = timeout * 1000;
setTimeout(() => { // @fixme: am I deprecated as well?
if ((typeof autoGuest == "boolean" && autoGuest) || this.autologin_user != null) setTimeout(function() {
if((typeof autoGuest === "boolean" && autoGuest) || that.autologin_user !== null)
window.autologin_timer_expired(); window.autologin_timer_expired();
}, this.autologin_timeout); }.bind(that), that.timed_login_delay);
} }
for (let user of this.users) { for(var i = 0; i <= that.users; i++) {
user.logged_in = Boolean(Math.floor(Math.random() * 2)); that.users[i].logged_in = Boolean(Math.floor(Math.random() * 2));
user.session = this.sessions[Math.floor((Math.random() * this.sessions.length))].name; that.users[i].session = that.sessions[Math.floor((Math.random() * that.sessions.length))].name;
} }
});
const deprecations = {
properties: [
{ deprecated: "default_language", alternative: "lightdm.language" },
{ deprecated: "default_layout", alternative: "lightdm.layout" },
{ deprecated: "select_guest", alternative: "lightdm.select_guest_hint" },
{ deprecated: "select_user", alternative: "lightdm.select_user_hint" },
{ deprecated: "timed_login_user", alternative: "lightdm.autologin_user" },
{ deprecated: "timed_login_delay", alternative: "lightdm.autologin_timeout" },
],
}; };
return new Proxy(this, { // see <https://github.com/Antergos/web-greeter/blob/before-python/src/webkit2-extension.c#L1437-L1450>
get: (o, k, r) => { window.loadJSON(includePath + "/json/users.json", function(that) {
if (deprecations.properties.map(o => o.deprecated).includes(k)) { if(this.status !== 200)
deprecationNotifier("property", k, deprecations.properties.alternative) return window.console.warn("users.json did not load correctly.");
} else {
return Reflect.get(o, k, r); that.users = JSON.parse(this.responseText);
}
} if(that.users !== null && that.languages !== null && that.layouts !== null && that.sessions !== null)
}); asyncLoadEnd(that);
} }, this, asyncLoadEnd);
// see <https://github.com/Antergos/web-greeter/blob/before-python/src/webkit2-extension.c#L1452-L1456>
window.loadJSON(includePath + "/json/languages.json", function(that) {
if(this.status !== 200)
return window.console.warn("languages.json did not load correctly.");
that.languages = JSON.parse(this.responseText);
if(that.users !== null && that.languages !== null && that.layouts !== null && that.sessions !== null)
asyncLoadEnd(that);
}, this, asyncLoadEnd);
// see <https://github.com/Antergos/web-greeter/blob/before-python/src/webkit2-extension.c#L1458-L1462>
window.loadJSON(includePath + "/json/layouts.json", function(that) {
if(this.status !== 200)
return window.console.warn("layouts.json did not load correctly.");
that.layouts = JSON.parse(this.responseText);
if(that.users !== null && that.languages !== null && that.layouts !== null && that.sessions !== null)
asyncLoadEnd(that);
}, this, asyncLoadEnd);
// see <https://github.com/Antergos/web-greeter/blob/before-python/src/webkit2-extension.c#L1464-L1468>
window.loadJSON(includePath + "/json/sessions.json", function(that) {
if(this.status !== 200)
return window.console.warn("sessions.json did not load correctly.");
that.sessions = JSON.parse(this.responseText);
if(that.users !== null && that.languages !== null && that.layouts !== null && that.sessions !== null)
asyncLoadEnd(that);
}, this, asyncLoadEnd);
} }
} }
@ -673,21 +464,16 @@ function IncompatibleArgumentTypesException(number, expected, received) {
******************************************************************************/ ******************************************************************************/
/** /**
* @desc * global helper deprecationNotifier
* throws ~balls~ errors at users who use deprecated methods and properties. * throws ~balls~ errors at users who use deprecated methods and properties.
* *
* @param {String} type * @param {String} type [method||property]
* "method" or "property" * @param {String} depricated [deprecated method or property name]
* * @param {String} alternative [alternative method or property to use]
* @param {String} deprecated
* deprecated method or property name
*
* @param {String} alternative
* alternative method or property to use
* *
* @throws {DeprecationException} * @throws {DeprecationException}
*/ */
export const deprecationNotifier = (type, deprecated, alternative) => { window.deprecationNotifier = function(type, deprecated, alternative) {
throw new DeprecationException(type, deprecated, alternative); throw new DeprecationException(type, deprecated, alternative);
}; };
@ -739,110 +525,72 @@ window.logCall = function(name, args) {
}; };
/** /**
* @desc * global helper checkForUpdate
* Compares `curentVersion` with the tag name of Gitea's latest release and * compares curentVersion with the tag name of GitHub's latest release and
* prompts the user to download a new version if it is available. * prompts the user to download a new version if it is available.
* *
* @param {String} currentVersion * @param {String} currentVersion [the current tag version]
* the current tag version
*/ */
export const checkForUpdate = async currentVersion => { window.checkForUpdate = function(currentVersion) {
const errMessage = "Could not check for new version of LightDMMock. Please check for a new version manually by visiting https://git.sfs.ddnss.org/EliasSchriefer/LightDMMock/releases/latest"; var request = new XMLHttpRequest();
const response = await fetch("https://git.sfs.ddnss.org/api/v1/repos/EliasSchriefer/LightDMMock/releases");
if (response.ok) { request.onreadystatechange = function() {
if(request.readyState === XMLHttpRequest.DONE) {
switch(request.status) {
case 200:
try { try {
const request = (await request.json())?.[0]?.tag_name; var latest;
if (currentVersion != latest) { if(request.responseText !== undefined)
console.warn(`You are using an outdated version of LightDMMock. Please download the new version from https://git.sfs.ddnss.org/EliasSchriefer/LightDMMock/releases/tag/${latest}`); latest = JSON.parse(request.responseText).tag_name;
if(currentVersion !== latest)
window.console.warn("You are using an outdated version of LightDMMock. Please download the new version from https://github.com/CytoDev/LightDMMock/releases/" + latest);
} catch(e) {
window.console.error(e.toString());
window.console.warn("Could not check for new version of LightDMMock. Please check for a new version manually by visiting https://github.com/CytoDev/LightDMMock/releases/latest");
} }
} catch (err) { break;
console.error(err.toString()); case 404:
console.warn(errMessage); window.console.warn("Could not check for new version of LightDMMock. Please check for a new version manually by visiting https://github.com/CytoDev/LightDMMock/releases/latest");
break;
default:
break;
} }
} else if (response.status == 404) {
console.warn(errMessage);
} }
}; };
request.open("GET", "https://api.github.com/repos/CytoDev/LightDMMock/releases/latest", true);
request.send();
};
/** /**
* @desc * global helper loadJSON
* Loads JSON from a path. Removes the need to b64 encode them in this file. * Loads JSON from a path. Removes the need to b64 encode them in this file.
* *
* @param {String} url * @param {String} url [path to JSON file]
* path to JSON file * @param {Function} callback [callback function]
*
* @throws {Response} Response with status code other than 200 Ok
*/ */
export const loadJSON = async url => { window.loadJSON = function(url, callback) {
let response = await fetch(url); var request = new XMLHttpRequest();
if (response.ok) { var onSuccess = function() {
return await response.json(); this.callback.apply(request, request.arguments);
} else {
console.error(response.statusText);
throw response;
}
}; };
/****************************************************************************** var onFailure = function() {
* External global functions * window.console.error(this.statusText);
******************************************************************************/ };
/** request.callback = callback;
* @namespace window request.arguments = Array.prototype.slice.call(arguments, 2);
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Window/window} request.onload = onSuccess;
*/ request.onerror = onFailure;
/** request.open("get", url, true);
* @function show_prompt request.send(null);
* @memberof window };
* @desc
* This will be called when LightDM needs to prompt the user for some
* reason, such as asking for a password.
*
* @param {String} text
* Will be the text of the prompt
*
* @param {String} type
* Will either be
* - "text" for a visible prompt, or
* - "password" for a prompt that the input should be hidden.
*/
/**
* @function show_message
* @memberof window
* @desc
* This will be called when LightDM needs to display some info for the
* user.
*
* @param {String} text
* Will be the text of the message
*
* @param {String} type
* Will either be
* - "info" for an information message, or
* - "error" for an error message that LightDM has encountered.
*/
/**
* @function authentication_complete
* @memberof window
* @desc
* This function is called by LightDM when authentication has
* completed.
*/
/**
* @function autologin_timer_expired
* @memberof window
* @desc
* This function is called by LightDM when an autologin user's login
* timer has expired. The greeter should reset the authentication
* process.
*/
/****************************************************************************** /******************************************************************************
* Object.watch shim * * Object.watch shim *
@ -902,8 +650,43 @@ if(!Object.prototype.unwatch) {
}); });
} }
/******************************************************************************
* Deprecated properties *
******************************************************************************/
LightDMMock.watch('default_language', function() {
window.deprecationNotifier("property", "default_language", "lightdm.language");
});
LightDMMock.watch('default_layout', function() {
window.deprecationNotifier("property", "default_layout", "lightdm.layout");
});
LightDMMock.watch('select_guest', function() {
window.deprecationNotifier("property", "select_guest", "lightdm.select_guest_hint");
});
LightDMMock.watch('select_user', function() {
window.deprecationNotifier("property", "select_user", "lightdm.select_user_hint");
});
LightDMMock.watch('timed_login_user', function() {
window.deprecationNotifier("property", "timed_login_user", "lightdm.autologin_user");
});
LightDMMock.watch('timed_login_delay', function() {
window.deprecationNotifier("property", "timed_login_delay", "lightdm.autologin_timeout");
});
/****************************************************************************** /******************************************************************************
* Module loading * * Module loading *
******************************************************************************/ ******************************************************************************/
export default LightDMMock; /* jshint node : true */
if(typeof module !== "undefined" && module.exports)
module.exports = LightDMMock;
/* jshint node : false */