~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to www/media/console/console.js

  • Committer: mattgiuca
  • Date: 2008-01-31 00:10:03 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:343
console: Small refactoring of how server starts up. Currently does not affect
behaviour, but makes it very easy to get the server to start lazily, when the
first line is entered. (Currently starts up on init, due to bug 1883194.)

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
console_filler = null;
37
37
 
38
38
windowpane_mode = false;
 
39
server_started = false;
39
40
 
40
 
/* Starts the console server.
41
 
 * Returns an object with fields "host", "port", "magic" describing the
42
 
 * server.
 
41
/* Starts the console server, if it isn't already.
 
42
 * This can be called any number of times - it only starts the one server.
 
43
 * This is a separate step from console_init, as the server is only to be
 
44
 * started once the first command is entered.
 
45
 * Does not return a value. Writes to global variables
 
46
 * server_host, server_port, server_magic.
43
47
 */
44
48
function start_server()
45
49
{
 
50
    if (server_started) return;
46
51
    var xhr = ajax_call("consoleservice", "start", {}, "POST");
47
52
    var json_text = xhr.responseText;
48
 
    return JSON.parse(json_text);
 
53
    var server_info = JSON.parse(json_text);
 
54
    server_host = server_info.host;
 
55
    server_port = server_info.port;
 
56
    server_magic = server_info.magic;
 
57
    server_started = true;
49
58
}
50
59
 
51
60
/** Initialises the console. All apps which import console are required to
65
74
        windowpane_mode = true;
66
75
        console_minimize();
67
76
    }
68
 
    /* Start the server */
69
 
    var server_info = start_server();
70
 
    server_host = server_info.host;
71
 
    server_port = server_info.port;
72
 
    server_magic = server_info.magic;
 
77
    /* TEMP: Start the server now.
 
78
     * Ultimately we want the server to start only when a line is typed, but
 
79
     * it currently does it asynchronously and doesn't start in time for the
 
80
     * first line. */
 
81
    start_server();
73
82
}
74
83
 
75
84
/** Hide the main console panel, so the console minimizes to just an input box
173
182
 */
174
183
function console_enter_line(inputline)
175
184
{
 
185
    /* Start the server if it hasn't already been started */
 
186
    start_server();
176
187
    var digest = hex_md5(inputline + magic);
177
188
    var args = {"host": server_host, "port": server_port,
178
189
                    "digest":digest, "text":inputline};