OSDN Git Service

Added usage to README
authorJohn-Anthony Elenis <johnanthonyelenis@gmail.com>
Fri, 23 Aug 2019 20:43:25 +0000 (16:43 -0400)
committerJohn-Anthony Elenis <johnanthonyelenis@gmail.com>
Fri, 23 Aug 2019 20:43:25 +0000 (16:43 -0400)
LICENSE [new file with mode: 0644]
README.md
css/theme.css [new file with mode: 0644]
images/splash-screen-sample.png [new file with mode: 0644]
index.html
js/theme.js
json/SplashScreen.json

diff --git a/LICENSE b/LICENSE
new file mode 100644 (file)
index 0000000..c4ae266
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,19 @@
+Copyright 2019 John-Anthony Elenis
+
+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
+the Software without restriction, including without limitation the rights to
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
+of the Software, and to permit persons to whom the Software is furnished to do
+so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
index 8bbef9e..2c20eef 100644 (file)
--- a/README.md
+++ b/README.md
@@ -8,8 +8,10 @@ Install the lightdm and its webkit greeter, make sure that no other version of l
 
 If your are not already using lightdm, install `lightdm` and `lightdm-webkit2-greeter`.
 
-#### Arch
-`$ pacman -S lightdm lightdm-webkit2-greeter`
+#### Arch and Manjaro
+`# pacman -S lightdm lightdm-webkit2-greeter`
+#### Debian (Ubuntu)
+`# apt-get install lightdm lightdm-webkit2-greeter`
 
 Now edit the lightdm config, in `/etc/lightdm/lightdm.conf` and set it to use the webkit2 greeter instead.
 ```
@@ -36,5 +38,190 @@ Lastly, set the value of theme in `/etc/lightdm/lightdm-webkit2-greeter.conf` to
 webkit_theme = $name
 ```
 ## Usage
-### Event API
-### Plugins
+### Basic Usage
+See [theme.js](js/theme.js) and [theme.css](css/theme.css) for basic usage.
+
+### API
+The [LoginManager](js/LoginManager.js) provides the basic faclities for
+authenticating and starting the user session through an asynchronous event based
+API. This adds layer of abstraction between UI code and the lightdm interface.
+
+#### LoginManager Interface
+Defined in `js/LoginManager.js` as must be included after all Plugins and other dependencies.
+
+_Example: Creating a LoginManager._
+```
+// define a singleton LoginManager
+let greeter = new LoginManager();
+```
+Any code that uses the LoginManager should only be performed after it has
+finished initializing itself and all of its plugins. The `ready` event can be
+used to so.
+
+_Example: Using LoginManager `ready` event._
+```
+// called after greeter and lightdm are initialized
+$(greeter).on("ready", function(e) {
+  // authentication code goes here
+});
+```
+
+#### Authetication
+A user must be authenticated prior to attempting to login.
+`auth(username="", password="", callback)` will asynchronously authenticate,
+triggering the appropriate `grant` or `deny` event and passing the resulting
+boolean to the callback function.
+
+_Example: Authentcating a user when the enter key is pressed in a password field._
+```
+/* Attempt authentication, 'grant' event will be emitted on sucecss
+and 'deny' will be emitted on failure */
+if (e.keyCode == 13) { // Enter key
+  let username = $user.children("option:selected").val();
+  let pass = $password.val();
+  greeter.auth(username, pass); // no callback specified
+}
+```
+#### Logging in (starting user session)
+Once authentication has been performed you can start a user session with
+`login(session_key)`
+
+_Example: listenting for authentication and starting a user session_
+```
+// when the user is authenticated, do a transition and login
+$(greeter).on("grant", () => {
+  let session_key = $session.children("option:selected").val();
+  greeter.login(session_key);
+})
+.on("deny", () => {
+  // inform the user that the credentials are invalid
+  $password.removeClass("valid").addClass("invalid");
+  $password.val("").prop("placeholder", "Incorrect Password");
+});
+```
+
+#### LoginManager Public Definitions
+Properties          | Definition                               | Description
+  ---               |                                          |---
+  auth              | auth(username="", password="", callback) | Authenticates a user
+  login             | login(session_key)                       | Starts a user session
+  shutdown          | shutdown()                               | Poweroff the pc
+  hibernate         | hibernate()                              | Hibernate the pc
+  restart           | restart()                                | Restart the pc
+  users             | get users()                              | Returns array of user objects
+  sessions          | get sessions()                           | Returns array of sessions objects
+  fillUserSelect    | fillUserSelect($el)                      | Populates jQuery select element with users
+  fillSessionSelect | fillSessionSelect($el)                   | Populates jQuery select element with sessions
+
+#### List of Events
+
+Event    | Description
+---      | ---
+deny     | Triggered after an unsucessful attempt to authenticate using `auth`
+grant    | Triggered after successfuly authenticating using `auth`
+init     | Triggered by LoginManager after the 'load' event has been fired by a plugin
+load     | Triggered by Plugins after they have finished loading their config files
+ready    | Triggered by Plugins and LoginManager after they have finished initailizing
+active   | Triggered once by  SplashScreen Plugin after the user interacts with the SplashScreen
+inactive | Triggered by the SplashScreen Plugin after a period of inactivity
+
+#### Plugins
+Plugins are stored in the LoginManager's `plugin` property and are
+dynamically generated by the `plugins` array in
+[LoginManager.json](json/LoginManager.json).
+
+_Example: The SplashScreen plugin in LoginManager's config_
+```
+"plugins": [
+  "SplashScreen"
+]
+```
+<!--  [SplashScreen](#splash-screen) -->
+
+##### Example: SplashScreen
+The SplashScreen plugin provides facilities to easily add content to a splash
+screen without having to worry about the details of implementation. Splash
+screen  content can be changed in its config file
+[SplashScreen.json](json/SplashScreen.json).
+
+###### General
+
+The general settings for this plugin are specified in the root of the `.json`
+config file. The code will generate the content on this splash
+```
+"img": "",             // path to background image (can be left blank for none)
+"fit": false,          // fits the background image to screen size, if there is one
+"filter": false,       // applies blur to background image
+"vignette": true,      // applies dark vignette to background image
+"active-timeout": 15,  // specifies the timeout for active/inactive events
+"transition": "fade",  // "fade" or "slide" to transition SplashScreen
+```
+
+###### Content: Clocks
+![splash-screen-sample](images/splash-screen-sample.png)
+
+The date in the sample image above is created and automatically
+updated with the following clock object. You can use custom CSS to style and
+position your clock. The `parent-css` property will allow you to add CSS to the
+clocks outer `div`.
+
+```
+"content": {
+  "clock": [{
+    "format": "dddd, MMMM Do",
+    "css": {
+      "color": "white"
+    },
+    "parent-css": {
+      "margin-top": "calc(20vh - 70pt)",
+      "text-align": "center",
+      "font-size": "70pt",
+      "font-family": "Noto Sans",
+      "font-weight": "lighter",
+      "text-shadow": "rgba(0, 0, 0, 0.5) 0px 7px 10px",
+    }
+    ...
+```
+
+To add the sytlized time to our splash screen we need to add another clock. This
+one will consist of two parts one for the actual time and another for the sylized
+AM/PM. This means formats, and thus two css objects.
+
+```
+"content": {
+  "clock": [{
+    ...
+},{
+  "format": ["h:mm", "A"], // two formats for two clocks on the same line
+  "css": [
+    {"font-size": "65pt", "font-weight": 200 },
+    {"font-size": "30pt", "font-weight": "lighter", "margin-left": "10pt"}
+  ],
+  "parent-css": {
+    "margin-top": "20vh",
+    "color": "white",
+    "font-family": "Noto Sans",
+    "text-align": "center",
+    "text-shadow": "rgba(0, 0, 0, 0.5) 0px 7px 10px",
+  }
+}],
+```
+
+###### Content: html
+Provides an interface to add any custom content to the SplashScreen.
+
+_Example: adding welcome text to SplashScreen, see default theme for an image._
+```
+content: {
+  "html": [{
+    "html":"<text style='display: none' class='active-appear'>Press any key to login</text>",
+    "css": {
+      "margin-top": "5vh",
+      "font-weight": "200",
+      "font-size": "23pt",
+      "text-align": "center",
+      "color": "rgba(255, 255, 255, 0.8)"
+    }
+  }]
+}
+```
diff --git a/css/theme.css b/css/theme.css
new file mode 100644 (file)
index 0000000..016549e
--- /dev/null
@@ -0,0 +1,55 @@
+/* Simple example of css used to stylize the login screen */
+* {
+  /* webkit2 is very slow, this is supposed to speed up animations */
+  backface-visibility: hidden;
+}
+body {
+  display: flex;
+  min-height: 100vh;
+  flex-direction: column;
+  color: white;
+  background-color: #37474f;
+  background: -webkit-radial-gradient(center, ellipse cover, #455a64 10%, #263238 100%);
+  overflow: hidden;
+}
+main {
+  flex: 1 0 auto;
+}
+input {
+  color: white;
+}
+.caret {
+  fill: grey !important;
+}
+.power-button {
+  fill: white;
+}
+.power-button:hover {
+  fill: #01579b;
+}
+.power-button:active {
+  fill: #4dd0e1;
+}
+div#console {
+  z-index: 9999;
+  position: absolute;
+  top: 10px;
+}
+div#console .terminal {
+  overflow-y: scroll;
+  background-color: rgba(0,0,0,0.8);
+  font-size: 14pt;
+  color: white;
+  height: 30vh;
+  width: 85vw;
+  resize: both;
+}
+div#console .terminal text {
+  display: block;
+  padding: 0;
+  margin: 0;
+}
+.welcome-text {
+  font-size: 3vh;
+  font-weight: lighter;
+}
diff --git a/images/splash-screen-sample.png b/images/splash-screen-sample.png
new file mode 100644 (file)
index 0000000..e50fd6f
Binary files /dev/null and b/images/splash-screen-sample.png differ
index e7f1613..fe5f33c 100644 (file)
@@ -3,64 +3,7 @@
 <head>
   <link rel="stylesheet" href="css/materialize.min.css">
   <link rel="stylesheet" href="css/splashscreen.css">
-  <style>
-  /* Simple example of css used to stylize the login screen */
-  * {
-    /* webkit2 is very slow, this is supposed to speed up animations */
-    backface-visibility: hidden;
-  }
-  body {
-    display: flex;
-    min-height: 100vh;
-    flex-direction: column;
-    color: white;
-    background-color: #37474f;
-    background: -webkit-radial-gradient(center, ellipse cover, #455a64 10%, #263238 100%);
-    overflow: hidden;
-  }
-  main {
-    flex: 1 0 auto;
-  }
-  input {
-    color: white;
-  }
-  .caret {
-    fill: grey !important;
-  }
-  .power-button {
-    fill: white;
-  }
-  .power-button:hover {
-    fill: #01579b;
-  }
-  .power-button:active {
-    fill: #4dd0e1;
-  }
-  div#console {
-    z-index: 9999;
-    position: absolute;
-    top: 10px;
-  }
-  div#console .terminal {
-    overflow-y: scroll;
-    background-color: rgba(0,0,0,0.8);
-    font-size: 14pt;
-    color: white;
-    height: 30vh;
-    width: 85vw;
-    resize: both;
-  }
-  div#console .terminal text {
-    display: block;
-    padding: 0;
-    margin: 0;
-  }
-  .welcome-text {
-    font-size: 3vh;
-    font-weight: lighter;
-  }
-
-  </style>
+  <link rel="stylesheet" href="css/theme.css">
 </head>
 <!-- Load dependencies -->
 <script src="js/jquery-3.4.1.min.js"></script>
index 4797179..0633157 100644 (file)
@@ -41,12 +41,11 @@ $(greeter).on("ready", function(e) {
                // user has typed, remove placeholder and invalid class
                $password.prop("placeholder", "").removeClass("invalid");
 
-               /* attempt authentication, 'grant' event will be emitted on sucecss
+               /* Attempt authentication, 'grant' event will be emitted on sucecss
                and 'deny' will be emitted on failure */
                if (e.keyCode == 13) {
                        let username = $user.children("option:selected").val();
                        let pass = $password.val();
-                       log.debug("attempt authenticate with: " + username + " " + pass);
                        greeter.auth(username, pass);
                }
 
index 789688e..ac82830 100644 (file)
@@ -19,7 +19,7 @@
                                "font-weight": "lighter",
                                "text-shadow": "rgba(0, 0, 0, 0.5) 0px 7px 10px",
                        }
-               },{
+    },{
                        "format": ["h:mm", "A"],
                        "css": [
                                {"font-size": "65pt", "font-weight": 200 },