Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduced a log console to the webpage.
Now errors are displayed directly on the webpage avoiding the alerts on every device that subsequently would need clearing. The following functions are also now available for custom logging to the webpage: * log.info() * log.error() * log.warn(); * log.trace(); * log.debug();
- Loading branch information
David Bankier
authored and
David Bankier
committed
Mar 18, 2012
1 parent
05a3dd5
commit 570cef4
Showing
7 changed files
with
101 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
['info','error','debug','trace','warn'].forEach(function(level){ | ||
exports[level] = function(message) { | ||
Ti.App.fireEvent("socket:log", { | ||
level: level.toUpperCase(), | ||
message: message | ||
}); | ||
} | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,74 @@ | ||
/*globals, exports, require*/ | ||
var LoginView = require('/ui/LoginView').LoginView; | ||
var Activity = require('/ui/Activity').Activity; | ||
var log = require('/api/Log'); | ||
|
||
exports.StartScreen = function() { | ||
var win = Ti.UI.createWindow({ | ||
backgroundColor : 'white', | ||
exitOnClose : true | ||
}); | ||
var win = Ti.UI.createWindow({ | ||
backgroundColor : 'white', | ||
exitOnClose : true | ||
}); | ||
|
||
var activity = new Activity("Connecting..."); | ||
var activity = new Activity("Connecting..."); | ||
|
||
var webview = Ti.UI.createWebView({ | ||
url : '/webview.html', | ||
top : 0, | ||
left : 0, | ||
width : 1, | ||
height : 1 | ||
}); | ||
win.add(webview); | ||
var webview = Ti.UI.createWebView({ | ||
url : '/webview.html', | ||
top : 0, | ||
left : 0, | ||
width : 1, | ||
height : 1 | ||
}); | ||
win.add(webview); | ||
|
||
var login = new LoginView(); | ||
|
||
login.addEventListener("connect", function(o) { | ||
activity.show(); | ||
Ti.App.fireEvent('socket:connect', { | ||
address : Ti.App.Properties.getString("address"), | ||
name : Ti.Platform.osname + ", " + Ti.Platform.version + ", " + Ti.Platform.address | ||
}); | ||
}); | ||
win.add(login); | ||
var login = new LoginView(); | ||
|
||
var current; | ||
Ti.App.addEventListener("message", function(message) { | ||
try { | ||
if(current && current.close !== undefined) { | ||
current.close(); | ||
} | ||
current = eval(message.code); | ||
if(current && current.open !== undefined) { | ||
current.open(); | ||
} | ||
} catch (e) { | ||
if(Ti.Platform.osname === 'android') { | ||
alert(e.toString()); | ||
} else { //iOS Error | ||
alert("Line: " + e.line + "\n" + e.message); | ||
} | ||
} | ||
}); | ||
login.addEventListener("connect", function(o) { | ||
activity.show(); | ||
Ti.App.fireEvent('socket:connect', { | ||
address : Ti.App.Properties.getString("address"), | ||
name : Ti.Platform.osname + ", " + Ti.Platform.version + ", " + Ti.Platform.address | ||
}); | ||
}); | ||
win.add(login); | ||
|
||
Ti.App.addEventListener("connected", function(o) { | ||
activity.hide(); | ||
alert("Connected"); | ||
win.remove(login); | ||
}); | ||
var current; | ||
Ti.App.addEventListener("message", function(message) { | ||
try { | ||
if(current && current.close !== undefined) { | ||
current.close(); | ||
} | ||
current = eval(message.code); | ||
if(current && current.open !== undefined) { | ||
current.open(); | ||
} | ||
log.info("Deployed"); | ||
} catch (e) { | ||
var error_message; | ||
if(Ti.Platform.osname === 'android') { | ||
error_message = e.toString(); | ||
} else { //iOS Error | ||
error_message = "Line " + e.line + ": " + e.message; | ||
} | ||
log.error(error_message); | ||
} | ||
}); | ||
|
||
Ti.App.addEventListener("connectfailed", function(o) { | ||
activity.hide(); | ||
alert("Connect Failed"); | ||
win.add(login); | ||
}); | ||
Ti.App.addEventListener("connected", function(o) { | ||
activity.hide(); | ||
alert("Connected"); | ||
win.remove(login); | ||
}); | ||
|
||
Ti.App.addEventListener("disconnected", function(o) { | ||
alert("Disconnected"); | ||
win.add(login); | ||
}); | ||
return win; | ||
Ti.App.addEventListener("connectfailed", function(o) { | ||
activity.hide(); | ||
alert("Connect Failed"); | ||
win.add(login); | ||
}); | ||
|
||
Ti.App.addEventListener("disconnected", function(o) { | ||
alert("Disconnected"); | ||
win.add(login); | ||
}); | ||
|
||
return win; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,4 +12,8 @@ | |
.span3 | ||
h3 Devices | ||
ul.device_list | ||
.row | ||
.span12 | ||
h3 Console | ||
.console | ||
|