Repository: cordova-ubuntu
Updated Branches:
  refs/heads/master 7c96ab3d5 -> 2e2083f60


Improve debugging behavior; Add ip option


Project: http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/commit/e64d5582
Tree: http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/tree/e64d5582
Diff: http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/diff/e64d5582

Branch: refs/heads/master
Commit: e64d55827b35f462b381a8a9eedd9b146534b138
Parents: 9509e62
Author: Alexandre Abreu <[email protected]>
Authored: Mon May 9 16:45:46 2016 -0400
Committer: Alexandre Abreu <[email protected]>
Committed: Mon May 9 16:45:46 2016 -0400

----------------------------------------------------------------------
 CordovaUbuntu/CordovaViewInternal.qml | 18 ++++++++++++++-
 main.cpp                              | 36 ++++++++++++++++++++++++++++--
 2 files changed, 51 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/blob/e64d5582/CordovaUbuntu/CordovaViewInternal.qml
----------------------------------------------------------------------
diff --git a/CordovaUbuntu/CordovaViewInternal.qml 
b/CordovaUbuntu/CordovaViewInternal.qml
index 02dea8c..47ea2ab 100644
--- a/CordovaUbuntu/CordovaViewInternal.qml
+++ b/CordovaUbuntu/CordovaViewInternal.qml
@@ -82,11 +82,27 @@ OrientationHelper {
                 request.accept();
             }
 
+            onJavaScriptConsoleMessage: {
+                var msg = "[JS] (%1:%2) 
%3".arg(sourceId).arg(lineNumber).arg(message)
+                if (level === WebView.LogSeverityVerbose) {
+                    console.log(msg)
+                } else if (level === WebView.LogSeverityInfo) {
+                    console.info(msg)
+                } else if (level === WebView.LogSeverityWarning) {
+                    console.warn(msg)
+                } else if ((level === WebView.LogSeverityError) ||
+                           (level === WebView.LogSeverityErrorReport) ||
+                           (level === WebView.LogSeverityFatal)) {
+                    console.error(msg)
+                }
+            }
+
             context: WebContext {
                 id: webcontext
 
                 devtoolsEnabled: debuggingEnabled
-                devtoolsPort: debuggingEnabled ? 9222 : -1
+                devtoolsIp: debuggingDevtoolsIp
+                devtoolsPort: debuggingEnabled ? debuggingDevtoolsPort : -1
 
                 userScripts: [
                     UserScript {

http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/blob/e64d5582/main.cpp
----------------------------------------------------------------------
diff --git a/main.cpp b/main.cpp
index ffef445..2ab8337 100644
--- a/main.cpp
+++ b/main.cpp
@@ -18,15 +18,18 @@
 #include <QtCore>
 #include <QApplication>
 #include <QtQuick>
+#include <QtNetwork/QNetworkInterface>
 
-static void customMessageOutput(
+const int kDebuggingDevtoolsDefaultPort = 9222;
+
+void customMessageOutput(
         QtMsgType type,
         const QMessageLogContext &,
         const QString &msg) {
 
     switch (type) {
     case QtDebugMsg:
-        if (qgetenv("DEBUG").size()) {
+      if (QString::fromUtf8(qgetenv("DEBUG")) == "1") {
             fprintf(stderr, "Debug: %s\n", msg.toStdString().c_str());
         }
         break;
@@ -39,7 +42,23 @@ static void customMessageOutput(
     case QtFatalMsg:
         fprintf(stderr, "Fatal: %s\n", msg.toStdString().c_str());
         abort();
+        break;
+    case QtInfoMsg:
+        fprintf(stderr, "Info: %s\n", msg.toStdString().c_str());
+        break;
+    }
+}
+
+QString getDebuggingDevtoolsIp()
+{
+    QString host;
+    Q_FOREACH(QHostAddress address, QNetworkInterface::allAddresses()) {
+        if (!address.isLoopback() && (address.protocol() == 
QAbstractSocket::IPv4Protocol)) {
+            host = address.toString();
+            break;
+        }
     }
+    return host;
 }
 
 int main(int argc, char *argv[]) {
@@ -75,6 +94,19 @@ int main(int argc, char *argv[]) {
     view.rootContext()->setContextProperty(
                 "debuggingEnabled", debuggingEnabled);
 
+    QString debuggingDevtoolsIp;
+    int debuggingDevtoolsPort = -1;
+
+    if (debuggingEnabled) {
+      debuggingDevtoolsIp = getDebuggingDevtoolsIp();
+      debuggingDevtoolsPort = kDebuggingDevtoolsDefaultPort;
+    }
+
+    view.rootContext()->setContextProperty(
+                "debuggingDevtoolsIp", debuggingDevtoolsIp);
+    view.rootContext()->setContextProperty(
+                "debuggingDevtoolsPort", debuggingDevtoolsPort);
+
     view.rootContext()->setContextProperty(
                 "www", wwwDir.absolutePath());
 


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to