diff options
| author | Javier <dev.git@javispedro.com> | 2014-11-30 20:58:57 +0100 |
|---|---|---|
| committer | Javier <dev.git@javispedro.com> | 2014-11-30 20:58:57 +0100 |
| commit | f7c8244641a4242f6a8c706bd918494b23e48075 (patch) | |
| tree | f84b5ead8f4d621cf47e10489889fb9fef8b1f61 /daemon/jskitmanager.cpp | |
| parent | 4527ab9a4147a8f15bf8ca5613341df9d0029d0c (diff) | |
introduce the AppMsgManager and the JsKitManager
will be used to handle application messages (push, etc)
while the JSKitManager will run PebbleKit JS scripts.
also add the ability to unpack PebbleDicts
Diffstat (limited to 'daemon/jskitmanager.cpp')
| -rw-r--r-- | daemon/jskitmanager.cpp | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/daemon/jskitmanager.cpp b/daemon/jskitmanager.cpp new file mode 100644 index 0000000..698b22b --- /dev/null +++ b/daemon/jskitmanager.cpp @@ -0,0 +1,77 @@ +#include <QQmlEngine> +#include <QJSValueIterator> +#include "jskitmanager.h" +#include "jskitmanager_p.h" + +JSKitPebble::JSKitPebble(JSKitManager *mgr) + : QObject(mgr) +{ +} + +JSKitPebble::~JSKitPebble() +{ +} + +JSKitManager::JSKitManager(AppManager *apps, AppMsgManager *appmsg, QObject *parent) : + QObject(parent), _apps(apps), _appmsg(appmsg), _engine(0) +{ + connect(_appmsg, &AppMsgManager::appStarted, this, &JSKitManager::handleAppStarted); + connect(_appmsg, &AppMsgManager::appStopped, this, &JSKitManager::handleAppStopped); +} + +JSKitManager::~JSKitManager() +{ + if (_engine) { + stopJsApp(); + } +} + +void JSKitManager::handleAppStarted(const QUuid &uuid) +{ + const auto &info = _apps->info(uuid); + if (!info.uuid.isNull() && info.isJSKit) { + logger()->debug() << "Preparing to start JSKit app" << info.uuid << info.shortName; + _curApp = info; + startJsApp(); + } +} + +void JSKitManager::handleAppStopped(const QUuid &uuid) +{ + if (!_curApp.uuid.isNull()) { + if (_curApp.uuid != uuid) { + logger()->warn() << "Closed app with invalid UUID"; + } + + _curApp = AppManager::AppInfo(); + } +} + +void JSKitManager::startJsApp() +{ + if (_engine) stopJsApp(); + _engine = new QJSEngine(this); + _jspebble = new JSKitPebble(this); + + QJSValue globalObj = _engine->globalObject(); + + globalObj.setProperty("Pebble", _engine->newQObject(_jspebble)); + + QJSValueIterator it(globalObj); + while (it.hasNext()) { + it.next(); + logger()->debug() << "JS property:" << it.name(); + } +} + +void JSKitManager::stopJsApp() +{ + if (!_engine) return; // Nothing to do! + + _engine->collectGarbage(); + + delete _engine; + _engine = 0; + delete _jspebble; + _jspebble = 0; +} |
