Commit 33b1a413 authored by Stavros Sachtouris's avatar Stavros Sachtouris Committed by Giorgos Korfiatis
Browse files

Add DEBUG flag doe debuging the javascript code

parent 219ba4fd
......@@ -7,7 +7,9 @@
<script src="static/js/jquery.js"></script>
<script type="text/javascript">
// Setup GUI
var DEBUG = false;
// Setup GUI
var windows = {
"settings": null,
"about": null,
......@@ -58,7 +60,7 @@ var local_folder_menu = new gui.MenuItem({
enabled: false,
click: function () {
var dir = globals['settings']['directory'];
console.log('Open ' + dir);
if (DEBUG) console.log('Open ' + dir);
gui.Shell.showItemInFolder(dir);
}
})
......@@ -69,7 +71,7 @@ var pithos_page_menu = new gui.MenuItem({
icon: 'images/pithos.png',
enabled: false,
click: function () {
console.log('Visit ' + get_pithos_ui());
if (DEBUG) console.log('Visit ' + get_pithos_ui());
gui.Shell.openExternal(get_pithos_ui());
}
});
......@@ -91,11 +93,11 @@ var settings_menu = new gui.MenuItem({
width: 841, height: 520
});
windows['settings'].on('closed', function() {
console.log('Settings windows is closed');
if (DEBUG) console.log('Settings windows is closed');
var new_settings = import_settings();
$.each(new_settings, function(key, setting) {
if (old_settings[key] !== setting) {
console.log('Settings have been modified - updating...');
if (DEBUG) console.log('Settings have been modified - updating...');
put_settings(socket, new_settings);
get_status(socket);
get_settings(socket);
......
......@@ -2,6 +2,7 @@ var gui = require('nw.gui');
var path = require('path');
// Read config file
var DEBUG = false;
var fs = require('fs');
var cnf = JSON.parse(fs.readFileSync(gui.App.argv[0], encoding='utf-8'));
fs.writeFile(gui.App.argv[0], 'consumed');
......@@ -33,12 +34,12 @@ function post_shutdown(socket) {
} // expected response: nothing
function post_pause(socket) {
console.log('SEND post pause');
if (DEBUG) console.log('SEND post pause');
send_json(socket, {'method': 'post', 'path': 'pause'});
} // expected response: {"OK": 200}
function post_start(socket) {
console.log('SEND post start');
if (DEBUG) console.log('SEND post start');
send_json(socket, {'method': 'post', 'path': 'start'});
} // expected response: {"OK": 200}
......@@ -60,12 +61,12 @@ function get_status(socket) {
// Connect to helper
var socket = new WebSocket(cnf['address']);
socket.onopen = function() {
console.log('Send GUI ID to helper');
if (DEBUG) console.log('Send GUI ID to helper');
post_gui_id(this);
}
socket.onmessage = function(e) {
var r = JSON.parse(e.data)
console.log('RECV: ' + r['action'])
if (DEBUG) console.log('RECV: ' + r['action'])
switch(r['action']) {
case 'post gui_id':
if (r['ACCEPTED'] === 202) {
......@@ -73,27 +74,28 @@ socket.onmessage = function(e) {
get_status(this);
globals.authenticated = true;
} else {
console.log('Helper: ' + JSON.stringify(r));
if (DEBUG) console.log('Helper: ' + JSON.stringify(r));
closeWindows();
}
break;
case 'post start':
case 'post pause': console.log('RECV ' + r['OK']);
case 'post pause':
if (DEBUG) console.log('RECV ' + r['OK']);
if (r['OK'] === 200) {
get_status(this);
} else {
console.log('Helper: ' + JSON.stringify(r));
if (DEBUG) console.log('Helper: ' + JSON.stringify(r));
}
break;
case 'get settings':
// console.log(r);
if (DEBUG) console.log(r);
globals['settings'] = r;
break;
case 'put settings':
if (r['CREATED'] === 201) {
get_settings(this);
} else {
console.log('Helper: ' + JSON.stringify(r));
if (DEBUG) console.log('Helper: ' + JSON.stringify(r));
}
break;
case 'get status':
......@@ -109,6 +111,6 @@ socket.onerror = function (e) {
closeWindows();
}
socket.onclose = function() {
console.log('Connection to helper closed');
if (DEBUG) console.log('Connection to helper closed');
closeWindows();
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment