summaryrefslogtreecommitdiff
path: root/daemon/jskitmanager.cpp
diff options
context:
space:
mode:
authorJavier <dev.git@javispedro.com>2014-12-06 23:31:57 +0100
committerJavier <dev.git@javispedro.com>2014-12-06 23:31:57 +0100
commit5499dc58d09f07081c41b8e4dead810a82137939 (patch)
tree6e82f57d36d7a3ae6a4fbc1f6f447d8b5886273b /daemon/jskitmanager.cpp
parentb03ee6521f61d02dcebb5d140f8d308479a89e35 (diff)
properly send acks for incoming appmsgs
Diffstat (limited to 'daemon/jskitmanager.cpp')
-rw-r--r--daemon/jskitmanager.cpp22
1 files changed, 19 insertions, 3 deletions
diff --git a/daemon/jskitmanager.cpp b/daemon/jskitmanager.cpp
index 6b291df..c73d32e 100644
--- a/daemon/jskitmanager.cpp
+++ b/daemon/jskitmanager.cpp
@@ -9,7 +9,6 @@ JSKitManager::JSKitManager(AppManager *apps, AppMsgManager *appmsg, QObject *par
{
connect(_appmsg, &AppMsgManager::appStarted, this, &JSKitManager::handleAppStarted);
connect(_appmsg, &AppMsgManager::appStopped, this, &JSKitManager::handleAppStopped);
- connect(_appmsg, &AppMsgManager::messageReceived, this, &JSKitManager::handleAppMessage);
}
JSKitManager::~JSKitManager()
@@ -83,7 +82,7 @@ void JSKitManager::handleAppStopped(const QUuid &uuid)
}
}
-void JSKitManager::handleAppMessage(const QUuid &uuid, const QVariantMap &data)
+void JSKitManager::handleAppMessage(const QUuid &uuid, const QVariantMap &msg)
{
if (_curApp.uuid() == uuid) {
logger()->debug() << "received a message for the current JSKit app";
@@ -94,7 +93,7 @@ void JSKitManager::handleAppMessage(const QUuid &uuid, const QVariantMap &data)
}
QJSValue eventObj = _engine->newObject();
- eventObj.setProperty("payload", _engine->toScriptValue(data));
+ eventObj.setProperty("payload", _engine->toScriptValue(msg));
_jspebble->invokeCallbacks("appmessage", QJSValueList({eventObj}));
}
@@ -164,6 +163,19 @@ void JSKitManager::startJsApp()
// Now load the actual script
loadJsFile(_curApp.path() + "/pebble-js-app.js");
+ // Setup the message callback
+ QUuid uuid = _curApp.uuid();
+ _appmsg->setMessageHandler(uuid, [this, uuid](const QVariantMap &msg) {
+ QMetaObject::invokeMethod(this, "handleAppMessage", Qt::QueuedConnection,
+ Q_ARG(QUuid, uuid),
+ Q_ARG(QVariantMap, msg));
+
+ // Invoke the slot as a queued connection to give time for the ACK message
+ // to go through first.
+
+ return true;
+ });
+
// We try to invoke the callbacks even if script parsing resulted in error...
_jspebble->invokeCallbacks("ready");
}
@@ -174,6 +186,10 @@ void JSKitManager::stopJsApp()
logger()->debug() << "stopping JS app";
+ if (!_curApp.uuid().isNull()) {
+ _appmsg->clearMessageHandler(_curApp.uuid());
+ }
+
_engine->collectGarbage();
_engine->deleteLater();