From 94c94f2e4f9d9ada5851923cecbc5c04d98bf651 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Fri, 21 Sep 2012 04:46:26 -0400 Subject: [PATCH] added appcache paramter to config.json --- ChangeLog | 2 + config.json | 1 + lib/client/socket.js | 9 +++- lib/client/terminal.js | 48 ++++++++----------- .../terminal/jquery-terminal/index.html | 4 +- lib/server/appcache.js | 34 +++++++++++-- server.js | 14 ++++-- 7 files changed, 74 insertions(+), 38 deletions(-) diff --git a/ChangeLog b/ChangeLog index ce696f93..59e0646d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -60,6 +60,8 @@ disabled in browsers. * Added ability to execute commands on server thrue terminal. +* Added appcache paramter to config.json + 2012.08.24, Version 0.1.6 diff --git a/config.json b/config.json index d58f0b2d..5356b723 100644 --- a/config.json +++ b/config.json @@ -1,5 +1,6 @@ { "cache" : {"allowed" : false}, + "appcache" : true, "minification" : { "js" : false, "css" : true, diff --git a/lib/client/socket.js b/lib/client/socket.js index 79dcb9af..100e3b7c 100644 --- a/lib/client/socket.js +++ b/lib/client/socket.js @@ -1,13 +1,18 @@ /* module make possible connectoin thrue socket.io on a client */ -var CloudCommander, io, socket, Term; +var CloudCommander, io, socket; (function(){ "use strict"; - var Util = CloudCommander.Util; + + var cloudcmd = CloudCommander, + Util = cloudcmd.Util, + Term = cloudcmd.Terminal.JqueryTerminal.Term; Util.jsload("/socket.io/lib/socket.io.js", { onload : function(){ socket = io.connect(document.location.hostname); + cloudcmd.Socket = socket; + socket.on('connect', function () { console.log('socket connected'); }); diff --git a/lib/client/terminal.js b/lib/client/terminal.js index f42c7e7d..475664d1 100644 --- a/lib/client/terminal.js +++ b/lib/client/terminal.js @@ -1,21 +1,23 @@ -var CloudCommander, $, Term, socket; +var CloudCommander, $; /* object contains terminal jqconsole */ (function(){ "use strict"; - var cloudcmd = CloudCommander, - Util = CloudCommander.Util, - KeyBinding = CloudCommander.KeyBinding, + var cloudcmd = CloudCommander, + + Util = cloudcmd.Util, + KeyBinding = cloudcmd.KeyBinding, TerminalId, - Hidden = false; + Term, + Hidden = false; - cloudcmd.Terminal = {}; + cloudcmd.Terminal = {}; - var jqconsole = {}; + var JqueryTerminal = {}; - jqconsole.load = (function(){ + JqueryTerminal.load = (function(){ Util.cssLoad({ src : 'lib/client/terminal/jquery-terminal/jquery.terminal.css' }); @@ -25,8 +27,8 @@ var CloudCommander, $, Term, socket; var lLoadTerm_func = function(){ Util.jsload('lib/client/terminal/jquery-terminal/jquery.terminal.js', function(){ - jqconsole.init(); - jqconsole.show(); + JqueryTerminal.init(); + JqueryTerminal.show(); }); }; @@ -35,7 +37,7 @@ var CloudCommander, $, Term, socket; }); - jqconsole.init = (function(){ + JqueryTerminal.init = (function(){ if(!TerminalId){ var lFM = Util.getById('fm'); if(lFM) @@ -50,7 +52,7 @@ var CloudCommander, $, Term, socket; console.log('Error. Something went wrong FM not found'); }); - jqconsole.show = function(){ + JqueryTerminal.show = function(){ Util.Images.hideLoad(); Util.hidePanel(); KeyBinding.unSet(); @@ -59,24 +61,14 @@ var CloudCommander, $, Term, socket; $('#terminal').terminal(function(command, term) { Term = term; term.echo(''); - socket.send(command); + cloudcmd.Socket.send(command); }); }); }; - - function jqueryLoad (pCallBack) - { - /* загружаем jquery: */ - Util.jsload('lib/client/terminal/jquery-terminal/jquery-1.7.1.min.js', - function(){ - if(typeof pCallBack === 'function') - pCallBack(); - }); -} - cloudcmd.Terminal.Keys = (function(){ + cloudcmd.Terminal.Keys = (function(){ /* loading js and css*/ - Util.jqueryLoad( jqconsole.load ); + Util.jqueryLoad( JqueryTerminal.load ); var key_event = function(event){ /* если клавиши можно обрабатывать */ @@ -86,7 +78,7 @@ var CloudCommander, $, Term, socket; Util.show(TerminalId); TerminalId.focus(); - jqconsole.show(); + JqueryTerminal.show(); } if(!Hidden && event.keyCode === cloudcmd.KEY.ESC){ @@ -107,5 +99,7 @@ var CloudCommander, $, Term, socket; document.onkeypress = key_event; }); - cloudcmd.Terminal.jqconsole = jqconsole; + JqueryTerminal.Term = Term; + cloudcmd.Terminal.JqueryTerminal = JqueryTerminal; + })(); \ No newline at end of file diff --git a/lib/client/terminal/jquery-terminal/index.html b/lib/client/terminal/jquery-terminal/index.html index 1ae8ae4b..37496a42 100644 --- a/lib/client/terminal/jquery-terminal/index.html +++ b/lib/client/terminal/jquery-terminal/index.html @@ -1,5 +1,5 @@ - - + + diff --git a/lib/server/appcache.js b/lib/server/appcache.js index 9ddfa55b..e4e7aaf2 100644 --- a/lib/server/appcache.js +++ b/lib/server/appcache.js @@ -58,9 +58,19 @@ exports.watch = function(pFileName){ if(!FileNames[pFileName] && pFileName !== './cloudcmd.appcache'){ - try{ - fs_watch(pFileName, on_fs_watch(pFileName)); - }catch(pError){} + + /* adding try...catch + * if watched files would be more then system limit + */ + var lWatch_f = tryCatch(function(){ + fs_watch(pFileName, on_fs_watch(pFileName)); + }); + /* if file.exists function exist and + * file actually exists + */ + if(fs.exists) + fs.exists(pFileName, lWatch_f); + else lWatch_f(); NamesList_s += pFileName + '\n'; FileNames[pFileName] = true; @@ -125,4 +135,22 @@ function cloudRequire(pModule){ catch(pError){ return false; } +} + +/** + * function execute param function in + * try...catch block + * + * @param pFunction_f + */ +function tryCatch(pFunction_f){ + return function(){ + var lRet = true; + try{ + pFunction_f(); + } + catch(pError){lRet = pError;} + + return lRet; + }; } \ No newline at end of file diff --git a/server.js b/server.js index 93f324b0..1e6e9443 100644 --- a/server.js +++ b/server.js @@ -12,6 +12,7 @@ var CloudServer = { cache : { allowed : true }, + appcache : false, minification : { js : false, css : false, @@ -134,9 +135,10 @@ CloudServer.init = (function(){ /* Если нужно минимизируем скрипты */ this.Minify.doit(); - /* создаём файл app cache */ + var lAppCache = CloudServer.AppCache; - if(lAppCache && this.Config.server){ + /* создаём файл app cache */ + if(this.Config.appcache && lAppCache && this.Config.server){ lAppCache.addFiles( [{'//themes.googleusercontent.com/static/fonts/droidsansmono/v4/ns-m2xQYezAtqh7ai59hJUYuTAAIFFn5GTWtryCmBQ4.woff' : './font/DroidSansMono.woff'}, {'//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js' : './lib/client/jquery.js'}, @@ -310,7 +312,8 @@ CloudServer._controller = function(pReq, pRes) console.log('reading '+lName); /* watching is file changed */ - CloudServer.AppCache.watch(lName); + if(CloudServer.Config.appcache) + CloudServer.AppCache.watch(lName); /* сохраняем указатель на response и имя */ CloudServer.Responses[lName] = pRes; @@ -673,7 +676,10 @@ CloudServer.indexReaded = function(pList){ /* меняем title */ pIndex = pIndex.replace('Cloud Commander', '' + CloudFunc.setTitle() + ''); - + + if(!CloudServer.Config.appcache) + pIndex = pIndex.replace('/cloudcmd.appcache', ''); + var lHeader; /* если браузер поддерживает gzip-сжатие*/ lHeader = CloudServer.generateHeaders('index.html', CloudServer.Gzip);