Log client startup errors to console
[KiwiIRC.git] / client / src / app.js
index 2c740aecbf32fa6c8ae4cec430da62f41d8c4ac2..619507cc7e2569c22b6f35c2cf12d77573571142 100644 (file)
@@ -8,6 +8,7 @@ _kiwi.misc = {};
 _kiwi.model = {};\r
 _kiwi.view = {};\r
 _kiwi.applets = {};\r
+_kiwi.utils = {};\r
 \r
 \r
 /**\r
@@ -20,8 +21,10 @@ _kiwi.global = {
     settings: undefined, // Instance of _kiwi.model.DataStore\r
     plugins: undefined, // Instance of _kiwi.model.PluginManager\r
     events: undefined, // Instance of PluginInterface\r
+    rpc: undefined, // Instance of WebsocketRpc\r
     utils: {}, // References to misc. re-usable helpers / functions\r
 \r
+    // Make public some internal utils for plugins to make use of\r
     initUtils: function() {\r
         this.utils.randomString = randomString;\r
         this.utils.secondsToTime = secondsToTime;\r
@@ -30,10 +33,9 @@ _kiwi.global = {
         this.utils.formatIRCMsg = formatIRCMsg;\r
         this.utils.styleText = styleText;\r
         this.utils.hsl2rgb = hsl2rgb;\r
-    },\r
 \r
-    rpc: function() {\r
-        _kiwi.gateway.rpc.call.call(_kiwi.gateway.rpc, arguments);\r
+        this.utils.notifications = _kiwi.utils.notifications;\r
+        this.utils.formatDate = _kiwi.utils.formatDate;\r
     },\r
 \r
     addMediaMessageType: function(match, buildHtml) {\r
@@ -117,8 +119,9 @@ _kiwi.global = {
                 kiwi: 'kiwi', raw: 'raw', kick: 'kick', topic: 'topic',\r
                 part: 'part', join: 'join', action: 'action', ctcp: 'ctcp',\r
                 ctcpRequest: 'ctcpRequest', ctcpResponse: 'ctcpResponse',\r
-                notice: 'notice', msg: 'privmsg', changeNick: 'changeNick',\r
-                channelInfo: 'channelInfo', mode: 'mode', quit: 'quit'\r
+                notice: 'notice', msg: 'privmsg', say: 'privmsg',\r
+                changeNick: 'changeNick', channelInfo: 'channelInfo',\r
+                mode: 'mode', quit: 'quit'\r
             };\r
 \r
             _.each(funcs, function(gateway_fn, func_name) {\r
@@ -134,6 +137,18 @@ _kiwi.global = {
                 };\r
             });\r
 \r
+            // Now for some network related functions...\r
+            obj.createQuery = function(nick) {\r
+                var network, restricted_keys;\r
+\r
+                network = getNetwork();\r
+                if (!network) {\r
+                    return;\r
+                }\r
+\r
+                return network.createQuery(nick);\r
+            };\r
+\r
             // Add the networks getters/setters\r
             obj.get = function(name) {\r
                 var network, restricted_keys;\r
@@ -178,14 +193,18 @@ _kiwi.global = {
                 };\r
             });\r
 \r
+            // Give access to the control input textarea\r
+            obj.input = _kiwi.app.controlbox.$('.inp');\r
+\r
             return obj;\r
         }\r
     },\r
 \r
     // Entry point to start the kiwi application\r
     init: function (opts, callback) {\r
-        var localePromise, themePromise,\r
+        var locale_promise, theme_promise,\r
             that = this;\r
+\r
         opts = opts || {};\r
 \r
         this.initUtils();\r
@@ -197,7 +216,7 @@ _kiwi.global = {
         // Set the window title\r
         window.document.title = opts.server_settings.client.window_title || 'Kiwi IRC';\r
 \r
-        localePromise = new Promise(function (resolve) {\r
+        locale_promise = new Promise(function (resolve) {\r
             var locale = _kiwi.global.settings.get('locale') || 'magic';\r
             $.getJSON(opts.base_path + '/assets/locales/' + locale + '.json', function (locale) {\r
                 if (locale) {\r
@@ -209,7 +228,7 @@ _kiwi.global = {
             });\r
         });\r
 \r
-        themePromise = new Promise(function (resolve) {\r
+        theme_promise = new Promise(function (resolve) {\r
             var text_theme = opts.server_settings.client.settings.text_theme || 'default';\r
             $.getJSON(opts.base_path + '/assets/text_themes/' + text_theme + '.json', function(text_theme) {\r
                 opts.text_theme = text_theme;\r
@@ -218,7 +237,7 @@ _kiwi.global = {
         });\r
 \r
 \r
-        Promise.all([localePromise, themePromise]).then(function () {\r
+        Promise.all([locale_promise, theme_promise]).then(function () {\r
             _kiwi.app = new _kiwi.model.Application(opts);\r
 \r
             // Start the client up\r
@@ -231,6 +250,9 @@ _kiwi.global = {
             _kiwi.global.plugins = new _kiwi.model.PluginManager();\r
 \r
             callback();\r
+\r
+        }).then(null, function(err) {\r
+            console.error(err.stack);\r
         });\r
     },\r
 \r