2016-05-10 22:48:02 +02:00
/ * *
* LightDMMock "class"
*
* @ author Roel Walraven < mail @ cytodev . io >
*
* A LightDM Mock that is tightly based on the source C code of
* Antergos ' lightdm - webkit2 - greeter . Please note that the deprecation errors
* are intrusive for a reason .
*
* Usage :
* Include the file in your theme that needs mocking
* < script type = "text/javascript" src = "mock/LightDMMock.js" > < / s c r i p t >
* Create a new instance of LightDMMock
2016-07-12 23:05:10 +02:00
* if ( ! ( "lightdm" in window ) ) {
* var LightDMMock = LightDMMock || { } ;
* window . lightdm = new LightDMMock ( autofill , timeout , autoGuest ) ;
* }
2016-05-10 22:48:02 +02:00
*
* @ 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 ]
* /
"use strict" ;
function LightDMMock ( autofill , timeout , autoGuest ) {
2016-08-04 18:31:52 +02:00
window . checkForUpdate ( "v1.0.0" ) ;
2017-02-24 14:04:48 +01:00
// see <https://github.com/Antergos/web-greeter/blob/before-python/src/webkit2-extension.c#L1470-L1504>
2016-05-10 22:48:02 +02:00
this . authentication _user = null ;
2017-02-24 14:04:48 +01:00
this . autologin _guest = false ;
this . autologin _timeout = 0 ;
this . autologin _user = null ;
2016-05-10 22:48:02 +02:00
this . can _hibernate = false ;
this . can _restart = false ;
this . can _shutdown = false ;
2017-02-24 14:04:48 +01:00
this . can _suspend = false ;
this . default _session = null ;
2016-05-10 22:48:02 +02:00
this . has _guest _account = false ;
this . hide _users = false ;
2017-02-24 14:04:48 +01:00
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
2016-05-10 22:48:02 +02:00
2016-07-12 23:51:10 +02:00
if ( typeof autofill === "boolean" && autofill ) {
2017-02-24 14:14:16 +01:00
var me = document . querySelector ( "script[src$=\"LightDMMock.js\"]" ) ;
if ( ! ( me instanceof HTMLElement ) )
return window . console . error ( "Could not find my script element." ) ;
var includePath = me . src ;
if ( includePath === undefined )
return window . console . error ( "Could not find my src attribute." ) ;
includePath = includePath . substr ( 0 , includePath . lastIndexOf ( "/" ) ) ;
var asyncLoadEnd = function ( that ) {
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 ;
if ( typeof timeout === "number" && timeout > 0 ) {
if ( typeof autoGuest === "boolean" && autoGuest ) {
that . autologin _user = null ;
that . autologin _guest = autoGuest ;
}
that . autologin _user = that . users [ 0 ] . username ;
that . autologin _timeout = timeout * 1000 ;
// @fixme: am I deprecated as well?
setTimeout ( function ( ) {
if ( ( typeof autoGuest === "boolean" && autoGuest ) || that . autologin _user !== null )
window . autologin _timer _expired ( ) ;
} . bind ( that ) , that . timed _login _delay ) ;
}
for ( var i = 0 ; i <= that . users ; i ++ ) {
that . users [ i ] . logged _in = Boolean ( Math . floor ( Math . random ( ) * 2 ) ) ;
that . users [ i ] . session = that . sessions [ Math . floor ( ( Math . random ( ) * that . sessions . length ) ) ] . name ;
2016-07-12 23:51:10 +02:00
}
2017-02-24 14:14:16 +01:00
} ;
// see <https://github.com/Antergos/web-greeter/blob/before-python/src/webkit2-extension.c#L1437-L1450>
window . loadJSON ( includePath + "/json/users.json" , function ( that ) {
if ( this . status !== 200 )
return window . console . warn ( "users.json did not load correctly." ) ;
that . users = JSON . parse ( this . responseText ) ;
if ( that . users !== null && that . languages !== null && that . layouts !== null && that . sessions !== null )
asyncLoadEnd ( that ) ;
} , this , asyncLoadEnd ) ;
2016-07-12 23:51:10 +02:00
2017-02-24 14:14:16 +01:00
// 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." ) ;
2016-05-10 22:48:02 +02:00
2017-02-24 14:14:16 +01:00
that . languages = JSON . parse ( this . responseText ) ;
2016-05-10 22:48:02 +02:00
2017-02-24 14:14:16 +01:00
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 ) ;
2016-05-10 22:48:02 +02:00
}
}
2017-02-24 14:21:41 +01:00
/ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Methods *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /
2016-05-10 22:48:02 +02:00
2017-02-24 14:21:58 +01:00
// see <https://github.com/Antergos/web-greeter/blob/before-python/src/webkit2-extension.c#L1511-L1530>
2016-05-10 22:48:02 +02:00
/ * *
* Specifies the username of the user we ' d like to start authenticating as .
* Note that if you call lightdm . authenticate with no argument , LightDM
* ( via PAM ) will issue a show _prompt ( ) call to ask for the username . The
* older function lightdm . start _authentication ( ) has been deprecated .
*
* @ param { String } username [ username to authenticate ]
* /
LightDMMock . prototype . authenticate = function ( username ) {
2016-08-04 16:50:31 +02:00
window . logCall ( "authenticate" , arguments ) ;
2016-05-10 22:48:02 +02:00
window . checkArguments ( arguments , 1 , [ "string" ] ) ;
if ( this . in _authentication ) {
window . show _message ( "Already authenticating " + this . authentication _user , "error" ) ;
return ;
}
var exists = false ;
2016-08-04 16:57:15 +02:00
for ( var i = 0 ; i <= this . users . length - 1 ; i ++ ) {
2017-02-24 14:20:33 +01:00
if ( this . users [ i ] . username === username )
2016-05-10 22:48:02 +02:00
exists = true ;
}
if ( ! exists ) {
window . show _message ( "Invalid username" , "error" ) ;
return ;
}
this . authentication _user = username ;
2017-02-24 14:21:07 +01:00
this . in _authentication = true ;
2016-05-10 22:48:02 +02:00
window . show _prompt ( "Password:" , "password" ) ;
} ;
/ * *
* Authenticates as the guest user .
* /
LightDMMock . prototype . authenticate _as _guest = function ( ) {
2016-08-04 16:50:31 +02:00
window . logCall ( "authenticate_as_guest" , arguments ) ;
2016-05-10 22:48:02 +02:00
window . checkArguments ( arguments , 0 , [ ] ) ;
if ( ! this . has _guest _account )
throw new IlligalUsageException ( "Guest accounts are turned off. Make sure you check the value of 'lightdm.has_guest_account' before calling this function." ) ;
if ( this . in _authentication ) {
window . show _message ( "Already authenticating" + this . authentication _user , "error" ) ;
return ;
}
this . authentication _user = "guest" ;
2017-02-24 14:21:07 +01:00
this . in _authentication = true ;
2016-05-10 22:48:02 +02:00
} ;
/ * *
* Cancels the authentication of any user currently in the
* process of authenticating .
* /
LightDMMock . prototype . cancel _authentication = function ( ) {
2016-08-04 16:50:31 +02:00
window . logCall ( "cancel_authentication" , arguments ) ;
2016-05-10 22:48:02 +02:00
window . checkArguments ( arguments , 0 , [ ] ) ;
this . authentication _user = null ;
this . in _authentication = false ;
} ;
/ * *
2017-02-24 14:07:14 +01:00
* Cancels the authentication of the autologin user . The older function
* lightdm . cancel _timed _login ( ) has been deprecated .
2016-05-10 22:48:02 +02:00
* /
2017-02-24 14:07:14 +01:00
LightDMMock . prototype . cancel _autologin = function ( ) {
window . logCall ( "cancel_autologin" , arguments ) ;
2016-05-10 22:48:02 +02:00
window . checkArguments ( arguments , 0 , [ ] ) ;
2017-02-24 14:07:14 +01:00
this . autologin _user = null ;
this . autologin _guest = false ;
this . autologin _timeout = 0 ;
} ;
2016-05-10 22:48:02 +02:00
2017-02-24 14:07:14 +01:00
/ * *
* Returns the value of a named hint provided by LightDM .
*
* @ param { String } hint _name [ name of the hint to show ]
* /
LightDMMock . prototype . get _hint = function ( hint _name ) {
window . logCall ( "get_hint" , arguments ) ;
window . checkArguments ( arguments , 1 , [ "string" ] ) ;
// @fixme: I have no clue how to simulate this...
2016-05-10 22:48:02 +02:00
} ;
/ * *
* Hibernates the system , if the greeter has the authority to do so .
* /
LightDMMock . prototype . hibernate = function ( ) {
2016-08-04 16:50:31 +02:00
window . logCall ( "hibernate" , arguments ) ;
2016-05-10 22:48:02 +02:00
window . checkArguments ( arguments , 0 , [ ] ) ;
if ( ! this . can _hibernate )
throw new IlligalUsageException ( "LightDM cannot hibernate the system. Make sure you check the value of 'lightdm.can_hibernate' before calling this function." ) ;
window . alert ( "System hibernated." ) ;
document . location . reload ( true ) ;
} ;
/ * *
2017-02-24 14:07:14 +01:00
* When LightDM has prompted for input , provide the response to LightDM . The
* deprecated function was "provide_secret" . This is still available for
* backwards compatibility , but authors of greeters should move
* to using lightdm . respond ( ) .
*
* @ param { String } text [ the response to the challange , usually a password ]
2016-05-10 22:48:02 +02:00
* /
2017-02-24 14:07:14 +01:00
LightDMMock . prototype . respond = function ( text ) {
window . logCall ( "respond" , arguments ) ;
window . checkArguments ( arguments , 1 , [ "string" ] ) ;
2016-05-10 22:48:02 +02:00
2017-02-24 14:07:14 +01:00
if ( ! this . in _authentication )
throw new IlligalUsageException ( "LightDM is currently not in the authentication phase. Make sure to call 'lightdm.authenticate(username)' before calling this function." ) ;
2016-05-10 22:48:02 +02:00
2017-02-24 14:07:14 +01:00
if ( text === "password" ) {
this . is _authenticated = true ;
window . authentication _complete ( ) ;
} else {
window . show _message ( "Invalid password" , "error" ) ;
}
2016-05-10 22:48:02 +02:00
} ;
/ * *
* Restarts the system , if the greeter has the authority to do so .
* /
LightDMMock . prototype . restart = function ( ) {
2016-08-04 16:50:31 +02:00
window . logCall ( "restart" , arguments ) ;
2016-05-10 22:48:02 +02:00
window . checkArguments ( arguments , 0 , [ ] ) ;
if ( ! this . can _restart )
throw new IlligalUsageException ( "LightDM cannot restart the system. Make sure you check the value of 'lightdm.can_restart' before calling this function." ) ;
window . alert ( "System restarted." ) ;
document . location . reload ( true ) ;
} ;
/ * *
* Will set the language for the current LightDM session .
*
* @ param { String } lang [ the language to change to ]
* /
LightDMMock . prototype . set _language = function ( lang ) {
2016-08-04 16:50:31 +02:00
window . logCall ( "set_language" , arguments ) ;
2016-05-10 22:48:02 +02:00
window . checkArguments ( arguments , 1 , [ "string" ] ) ;
this . language = lang ;
} ;
/ * *
2017-02-24 14:07:14 +01:00
* Shuts down the system , if the greeter has the authority to do so .
2016-05-10 22:48:02 +02:00
* /
2017-02-24 14:07:14 +01:00
LightDMMock . prototype . shutdown = function ( ) {
window . logCall ( "shutdown" , arguments ) ;
window . checkArguments ( arguments , 0 , [ ] ) ;
if ( ! this . can _shutdown )
throw new IlligalUsageException ( "LightDM cannot shut down the system. Make sure you check the value of 'lightdm.can_shutdown' before calling this function." ) ;
window . alert ( "System shut down." ) ;
document . location . reload ( true ) ;
2016-07-12 23:51:10 +02:00
} ;
2016-05-10 22:48:02 +02:00
/ * *
* Once LightDM has successfully authenticated the user , start the user ' s
* session by calling this function . "session" is the authenticated user ' s
* session . If no session is passed , start the authenticated user with the
* system default session . The older function lightdm . login ( user , session )
* has been deprecated .
*
* @ param { String } session [ the session name to start ]
* /
2017-02-24 14:07:14 +01:00
LightDMMock . prototype . start _session = function ( session ) {
2016-08-04 16:50:31 +02:00
window . logCall ( "start_session_sync" , arguments ) ;
2016-05-10 22:48:02 +02:00
window . checkArguments ( arguments , 1 , [ "string" ] ) ;
if ( ! this . in _authentication )
throw new IlligalUsageException ( "LightDM is currently not in the authentication phase. Make sure to call 'lightdm.authenticate(username)' before calling this function." ) ;
if ( ! this . is _authenticated )
throw new IlligalUsageException ( "LightDM has no authenticated users to log in. Make sure to call 'lightdm.respond()' before calling this function." ) ;
window . alert ( "LightDM has started a " + session + " session for " + this . authentication _user ) ;
2016-08-04 17:25:36 +02:00
document . location . reload ( true ) ;
2016-05-10 22:48:02 +02:00
} ;
/ * *
2017-02-24 14:07:14 +01:00
* Suspends the system , if the greeter has the authority to do so .
2016-05-10 22:48:02 +02:00
* /
2017-02-24 14:07:14 +01:00
LightDMMock . prototype . suspend = function ( ) {
window . logCall ( "suspend" , arguments ) ;
window . checkArguments ( arguments , 0 , [ ] ) ;
2016-05-10 22:48:02 +02:00
2017-02-24 14:07:14 +01:00
if ( ! this . can _suspend )
throw new IlligalUsageException ( "LightDM cannot suspend the system. Make sure you check the value of 'lightdm.can_suspend' before calling this function." ) ;
window . alert ( "System suspended." ) ;
document . location . reload ( true ) ;
2016-05-10 22:48:02 +02:00
} ;
/ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2017-02-24 14:21:41 +01:00
* Deprecated methods *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /
2016-05-10 22:48:02 +02:00
2017-02-24 14:08:47 +01:00
LightDMMock . prototype . cancel _timed _login = function ( ) {
window . logCall ( "cancel_timed_login" , arguments ) ;
window . deprecationNotifier ( "method" , "lightdm.cancel_timed_login()" , "lightdm.cancel_autologin()" ) ;
} ;
LightDMMock . prototype . start _authentication = function ( ) {
window . logCall ( "start_authentication" , arguments ) ;
window . deprecationNotifier ( "method" , "lightdm.start_authentication()" , "lightdm.authenticate(username)" ) ;
} ;
LightDMMock . prototype . login = function ( ) {
window . logCall ( "login" , arguments ) ;
window . deprecationNotifier ( "method" , "lightdm.login()" , "lightdm.start_session(session)" ) ;
} ;
LightDMMock . prototype . provide _secret = function ( ) {
window . logCall ( "provide_secret" , arguments ) ;
window . deprecationNotifier ( "method" , "lightdm.provide_secret(text)" , "lightdm.respond(text)" ) ;
} ;
LightDMMock . prototype . start _session _sync = function ( ) {
window . logCall ( "login" , arguments ) ;
window . deprecationNotifier ( "method" , "lightdm.start_session_sync(session)" , "lightdm.start_session(session)" ) ;
} ;
/ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Throwables *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /
2016-05-10 22:48:02 +02:00
/ * *
* Throwable IlligalUsageException
*
* @ param { string } message [ description of illigal usage ]
* /
function IlligalUsageException ( message ) {
2016-08-04 17:25:36 +02:00
this . name = "IlligalUsageException" ;
this . message = message ;
2016-05-10 22:48:02 +02:00
this . toString = function ( ) {
return "[" + this . name + "] " + this . message ;
} ;
}
/ * *
* Throwable DeprecationException
*
* @ param { String } type [ method || property ]
2016-07-12 23:51:10 +02:00
* @ param { String } depricated [ deprecated method or property name ]
2016-05-10 22:48:02 +02:00
* @ param { String } alternative [ alternative method or property to use ]
* /
2016-07-12 23:51:10 +02:00
function DeprecationException ( type , deprecated , alternative ) {
2016-08-04 17:25:36 +02:00
this . name = "DeprecationException" ;
this . message = "The " + type + " '" + deprecated + "' is deprecated. Consider using '" + alternative + "' instead." ;
2016-05-10 22:48:02 +02:00
this . toString = function ( ) {
return "[" + this . name + "] " + this . message ;
} ;
}
/ * *
* Throwable IncompatibleArgumentCountException
*
* @ param { Number } expected [ expected length of arguments ]
* @ param { Number } received [ found length of arguments ]
* /
function IncompatibleArgumentCountException ( expected , received ) {
2016-08-04 17:25:36 +02:00
this . name = "IncompatibleArgumentCountException" ;
this . message = "Incorrect number of arguments in function call. Expected " + expected + ", found " + received ;
2016-05-10 22:48:02 +02:00
this . toString = function ( ) {
return "[" + this . name + "] " + this . message ;
} ;
}
/ * *
* Throwable IncompatibleArgumentTypesException
*
* @ param { Number } type [ argument number ( non - zero ) ]
* @ param { String } expected [ expected type ]
* @ param { String } received [ found type ]
* /
function IncompatibleArgumentTypesException ( number , expected , received ) {
2016-08-04 17:25:36 +02:00
this . name = "IncompatibleArgumentTypesException" ;
this . message = "Argument " + number + " is of a wrong type. Expected '" + expected + "', found '" + received + "'" ;
2016-05-10 22:48:02 +02:00
this . toString = function ( ) {
return "[" + this . name + "] " + this . message ;
} ;
}
/ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Helpers *
2017-02-24 14:21:41 +01:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /
2016-05-10 22:48:02 +02:00
/ * *
* global helper deprecationNotifier
* throws ~ balls ~ errors at users who use deprecated methods and properties .
*
* @ param { String } type [ method || property ]
2016-07-12 23:51:10 +02:00
* @ param { String } depricated [ deprecated method or property name ]
2016-05-10 22:48:02 +02:00
* @ param { String } alternative [ alternative method or property to use ]
*
* @ throws { DeprecationException }
* /
2016-07-12 23:51:10 +02:00
window . deprecationNotifier = function ( type , deprecated , alternative ) {
throw new DeprecationException ( type , deprecated , alternative ) ;
2016-05-10 22:48:02 +02:00
} ;
/ * *
* global helper checkArguments
* throws ~ tables ~ errors at users who call methods
* with erroneous arguments .
*
* @ param { Array } args [ the arguments passed to the original method ]
* @ param { Number } length [ the expected amount of arguments ]
* @ param { Arrray } types [ the expected types of the arguments ]
*
* @ throws { IncompatibleArgumentTypesException }
* /
window . checkArguments = function ( args , length , types ) {
2016-07-13 00:09:51 +02:00
if ( args . length !== length )
throw new IncompatibleArgumentCountException ( length , args . length ) ;
2016-05-10 22:48:02 +02:00
for ( var i = 1 ; i <= types . length ; i ++ ) {
2016-08-04 16:24:27 +02:00
if ( typeof args [ i - 1 ] !== types [ i - 1 ] )
throw new IncompatibleArgumentTypesException ( i , types [ i - 1 ] , typeof args [ i - 1 ] ) ;
2016-05-10 22:48:02 +02:00
}
} ;
2016-07-12 23:51:10 +02:00
2016-08-04 16:50:31 +02:00
/ * *
* global helper logCall
* logs a function call with the arguments provided to help with debugging a
* lightdm js script .
*
* @ param { String } name [ called function name ]
* @ param { Array } args [ called function arguments ]
*
* @ return { window . console . info }
* /
window . logCall = function ( name , args ) {
var argv = [ ] ;
if ( args !== undefined && args . length !== 0 ) {
for ( var i = 0 ; i <= args . length ; i ++ ) {
if ( args [ i ] !== undefined )
argv . push ( { type : typeof args [ i ] , value : args [ i ] } ) ;
}
}
if ( argv . length > 0 )
return window . console . info ( "[lightdm." + name + "] called with " + argv . length + " argument(s)" , argv ) ;
return window . console . info ( "[lightdm." + name + "] called with 0 arguments" ) ;
} ;
2016-08-04 18:35:28 +02:00
/ * *
* global helper checkForUpdate
* compares curentVersion with the tag name of GitHub ' s latest release and
* prompts the user to download a new version if it is available .
*
* @ param { String } currentVersion [ the current tag version ]
* /
2016-08-04 18:31:52 +02:00
window . checkForUpdate = function ( currentVersion ) {
var request = new XMLHttpRequest ( ) ;
request . onreadystatechange = function ( ) {
if ( request . readyState === XMLHttpRequest . DONE ) {
switch ( request . status ) {
case 200 :
try {
2017-02-24 14:09:37 +01:00
var latest ;
2016-08-04 18:31:52 +02:00
2017-02-24 14:09:37 +01:00
if ( request . responseText !== undefined )
latest = JSON . parse ( request . responseText ) . tag _name ;
if ( currentVersion !== latest )
2016-08-04 18:31:52 +02:00
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" ) ;
}
break ;
case 404 :
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 ;
}
}
} ;
request . open ( "GET" , "https://api.github.com/repos/CytoDev/LightDMMock/releases/latest" , true ) ;
request . send ( ) ;
} ;
2017-02-24 14:10:16 +01:00
/ * *
* global helper loadJSON
* Loads JSON from a path . Removes the need to b64 encode them in this file .
*
* @ param { String } url [ path to JSON file ]
* @ param { Function } callback [ callback function ]
* /
window . loadJSON = function ( url , callback ) {
var request = new XMLHttpRequest ( ) ;
var onSuccess = function ( ) {
this . callback . apply ( request , request . arguments ) ;
} ;
var onFailure = function ( ) {
window . console . error ( this . statusText ) ;
} ;
request . callback = callback ;
request . arguments = Array . prototype . slice . call ( arguments , 2 ) ;
request . onload = onSuccess ;
request . onerror = onFailure ;
request . open ( "get" , url , true ) ;
request . send ( null ) ;
} ;
2016-07-12 23:51:10 +02:00
/ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Object . watch shim *
2017-02-24 14:21:41 +01:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /
2016-07-12 23:51:10 +02:00
2016-08-04 15:20:23 +02:00
/ *
* object . watch polyfill
*
* 2012 - 04 - 03
*
* By Eli Grey , http : //eligrey.com
* Public Domain .
* NO WARRANTY EXPRESSED OR IMPLIED . USE AT YOUR OWN RISK .
* /
// object.watch
if ( ! Object . prototype . watch ) {
Object . defineProperty ( Object . prototype , "watch" , {
enumerable : false ,
configurable : true ,
writable : false ,
value : function ( prop , handler ) {
var oldval = this [ prop ] ,
newval = oldval ,
getter = function ( ) {
return newval ;
} ,
setter = function ( val ) {
oldval = newval ;
newval = handler . call ( this , prop , oldval , val ) ;
return newval ;
} ;
if ( delete this [ prop ] ) { // can't watch constants
Object . defineProperty ( this , prop , {
get : getter ,
set : setter ,
enumerable : true ,
configurable : true
} ) ;
}
2016-07-12 23:51:10 +02:00
}
2016-08-04 15:20:23 +02:00
} ) ;
2016-07-12 23:51:10 +02:00
}
2016-08-04 15:20:23 +02:00
// object.unwatch
2016-07-12 23:51:10 +02:00
if ( ! Object . prototype . unwatch ) {
2016-08-04 15:20:23 +02:00
Object . defineProperty ( Object . prototype , "unwatch" , {
enumerable : false ,
configurable : true ,
writable : false ,
value : function ( prop ) {
var val = this [ prop ] ;
delete this [ prop ] ; // remove accessors
this [ prop ] = val ;
}
} ) ;
2016-07-12 23:51:10 +02:00
}
2017-02-24 14:21:41 +01:00
/ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Deprecated properties *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /
2016-07-12 23:51:10 +02:00
LightDMMock . watch ( 'default_language' , function ( ) {
window . deprecationNotifier ( "property" , "default_language" , "lightdm.language" ) ;
} ) ;
LightDMMock . watch ( 'default_layout' , function ( ) {
window . deprecationNotifier ( "property" , "default_layout" , "lightdm.layout" ) ;
} ) ;
2017-02-24 14:04:48 +01:00
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" ) ;
} ) ;
2016-07-12 23:51:10 +02:00
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" ) ;
} ) ;
2016-12-15 01:22:03 +01:00
2017-02-24 14:22:31 +01:00
/ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Module loading *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /
/* jshint node : true */
if ( typeof module !== "undefined" && module . exports )
2016-12-15 01:22:03 +01:00
module . exports = LightDMMock ;
2017-02-24 14:22:31 +01:00
/* jshint node : false */