diff options
| author | Javier <dev.git@javispedro.com> | 2014-12-03 00:00:42 +0100 |
|---|---|---|
| committer | Javier <dev.git@javispedro.com> | 2014-12-03 00:06:13 +0100 |
| commit | 843e8c2550f69de3b9dfc3ec5f13d2c3a5710896 (patch) | |
| tree | 80f8edf321fed7d1790b609c2dab51c9d22fdd8b /daemon | |
| parent | c35a3a9bea759cadf1e975a2a62e50789cad096c (diff) | |
implement more parts of the new D-Bus API
Diffstat (limited to 'daemon')
| -rw-r--r-- | daemon/appmsgmanager.cpp | 10 | ||||
| -rw-r--r-- | daemon/appmsgmanager.h | 2 | ||||
| -rw-r--r-- | daemon/jskitmanager.cpp | 5 | ||||
| -rw-r--r-- | daemon/jskitmanager.h | 3 | ||||
| -rw-r--r-- | daemon/jskitobjects.cpp | 7 | ||||
| -rw-r--r-- | daemon/manager.cpp | 81 | ||||
| -rw-r--r-- | daemon/manager.h | 37 |
7 files changed, 104 insertions, 41 deletions
diff --git a/daemon/appmsgmanager.cpp b/daemon/appmsgmanager.cpp index b620078..afaabee 100644 --- a/daemon/appmsgmanager.cpp +++ b/daemon/appmsgmanager.cpp @@ -130,6 +130,16 @@ void AppMsgManager::send(const QUuid &uuid, const QVariantMap &data) send(uuid, data, nullCallback, nullCallback); } +void AppMsgManager::launchApp(const QUuid &uuid) +{ + // TODO +} + +void AppMsgManager::closeApp(const QUuid &uuid) +{ + // TODO +} + WatchConnector::Dict AppMsgManager::mapAppKeys(const QUuid &uuid, const QVariantMap &data) { AppInfo info = apps->info(uuid); diff --git a/daemon/appmsgmanager.h b/daemon/appmsgmanager.h index ca1d484..bc9c82f 100644 --- a/daemon/appmsgmanager.h +++ b/daemon/appmsgmanager.h @@ -18,6 +18,8 @@ public: public slots: void send(const QUuid &uuid, const QVariantMap &data); + void launchApp(const QUuid &uuid); + void closeApp(const QUuid &uuid); signals: void appStarted(const QUuid &uuid); diff --git a/daemon/jskitmanager.cpp b/daemon/jskitmanager.cpp index cfd860e..9efc5c8 100644 --- a/daemon/jskitmanager.cpp +++ b/daemon/jskitmanager.cpp @@ -24,6 +24,11 @@ QJSEngine * JSKitManager::engine() return _engine; } +bool JSKitManager::isJSKitAppRunning() const +{ + return _engine != 0; +} + void JSKitManager::showConfiguration() { if (_engine) { diff --git a/daemon/jskitmanager.h b/daemon/jskitmanager.h index fd6040d..07ecec1 100644 --- a/daemon/jskitmanager.h +++ b/daemon/jskitmanager.h @@ -19,10 +19,11 @@ public: ~JSKitManager(); QJSEngine * engine(); + bool isJSKitAppRunning() const; signals: void appNotification(const QUuid &uuid, const QString &title, const QString &body); - void appOpenUrl(const QString &url); + void appOpenUrl(const QUrl &url); public slots: void showConfiguration(); diff --git a/daemon/jskitobjects.cpp b/daemon/jskitobjects.cpp index 9e4cfde..a0bc0ba 100644 --- a/daemon/jskitobjects.cpp +++ b/daemon/jskitobjects.cpp @@ -57,12 +57,7 @@ void JSKitPebble::showSimpleNotificationOnPebble(const QString &title, const QSt void JSKitPebble::openURL(const QUrl &url) { logger()->debug() << "opening url" << url.toString(); - emit _mgr->appOpenUrl(url.toString()); -#if 0 /* Until we figure out how to do this. Maybe signal the daemon? */ - if (!QDesktopServices::openUrl(url)) { - logger()->warn() << "Failed to open URL:" << url; - } -#endif + emit _mgr->appOpenUrl(url); } QJSValue JSKitPebble::createXMLHttpRequest() diff --git a/daemon/manager.cpp b/daemon/manager.cpp index 38b3948..0666de0 100644 --- a/daemon/manager.cpp +++ b/daemon/manager.cpp @@ -56,6 +56,8 @@ Manager::Manager(Settings *settings, QObject *parent) : connect(notifications, SIGNAL(facebookNotify(const QString &,const QString &)), SLOT(onFacebookNotify(const QString &,const QString &))); connect(appmsg, &AppMsgManager::messageReceived, this, &Manager::onAppMessage); + connect(appmsg, &AppMsgManager::appStarted, this, &Manager::onAppOpened); + connect(appmsg, &AppMsgManager::appStopped, this, &Manager::onAppClosed); QDBusConnection session = QDBusConnection::sessionBus(); new WatchAdaptor(proxy); @@ -389,19 +391,82 @@ void Manager::transliterateMessage(const QString &text) } } -void Manager::test() +void Manager::onAppMessage(const QUuid &uuid, const QVariantMap &data) { - logger()->debug() << "Starting test"; - - js->showConfiguration(); + emit proxy->AppMessage(uuid.toString(), data); } -void Manager::onAppMessage(const QUuid &uuid, const QVariantMap &data) +void Manager::onAppOpened(const QUuid &uuid) { - emit proxy->AppMessage(uuid.toString(), data); + currentAppUuid = uuid; + emit proxy->AppOpened(uuid.toString()); } -void Manager::onWebviewClosed(const QString &result) +void Manager::onAppClosed(const QUuid &uuid) { - js->handleWebviewClosed(result); + currentAppUuid = QUuid(); + emit proxy->AppClosed(uuid.toString()); +} + +bool PebbledProxy::SendAppMessage(const QString &uuid, const QVariantMap &data) { + Q_ASSERT(calledFromDBus()); + const QDBusMessage msg = message(); + setDelayedReply(true); + manager()->appmsg->send(uuid, data, [this, msg]() { + QDBusMessage reply = msg.createReply(QVariant::fromValue(true)); + this->connection().send(reply); + }, [this, msg]() { + QDBusMessage reply = msg.createReply(QVariant::fromValue(false)); + this->connection().send(reply); + }); + return false; // D-Bus clients should never see this reply. +} + +QString PebbledProxy::StartAppConfiguration(const QString &uuid) { + Q_ASSERT(calledFromDBus()); + const QDBusMessage msg = message(); + + if (manager()->currentAppUuid != uuid) { + sendErrorReply(msg.interface() + ".Error.AppNotRunning", + "The requested app is not currently opened in the watch"); + return QString(); + } + + if (!manager()->js->isJSKitAppRunning()) { + sendErrorReply(msg.interface() + ".Error.JSNotActive", + "The requested app is not a PebbleKit JS application"); + return QString(); + } + + // After calling showConfiguration() on the script, + // it will (eventually!) return a URL to us via the appOpenUrl signal. + + // So we can't send the D-Bus reply right now. + setDelayedReply(true); + + // Set up a signal handler to catch the appOpenUrl signal. + QMetaObject::Connection c = connect(manager()->js, &JSKitManager::appOpenUrl, + [this,msg,c](const QUrl &url) { + // Workaround: due to a GCC bug we can't capture the uuid parameter, but we can extract + // it again from the original message arguments. + QString uuid = msg.arguments().at(0).toString(); + if (manager()->currentAppUuid != uuid) { + // App was changed while we were waiting for the script.. + QDBusMessage reply = msg.createErrorReply(msg.interface() + ".Error.AppNotRunning", + "The requested app is not currently opened in the watch"); + connection().send(reply); + } else { + QDBusMessage reply = msg.createReply(QVariant::fromValue(url.toString())); + connection().send(reply); + } + + disconnect(c); + }); + // TODO: JS script may fail, never call OpenURL, or something like that + // In those cases we may leak the above connection + // So we need to also set a timeout or similar. + + manager()->js->showConfiguration(); + + return QString(); // This return value should never be used. } diff --git a/daemon/manager.h b/daemon/manager.h index c12d3dc..f099aac 100644 --- a/daemon/manager.h +++ b/daemon/manager.h @@ -62,6 +62,8 @@ class Manager : public QObject, protected QDBusContext QString lastSeenMpris; QVariantMap mprisMetadata; + QUuid currentAppUuid; + QScopedPointer<icu::Transliterator> transliterator; public: @@ -84,8 +86,6 @@ public slots: void applyProfile(); private slots: - void test(); - void onWebviewClosed(const QString &result); void onSettingChanged(const QString &key); void onSettingsChanged(); void onPebbleChanged(); @@ -103,6 +103,8 @@ private slots: void setMprisMetadata(QVariantMap metadata); void onAppMessage(const QUuid &uuid, const QVariantMap &data); + void onAppOpened(const QUuid &uuid); + void onAppClosed(const QUuid &uuid); }; /** This class is what's actually exported over D-Bus, @@ -132,32 +134,13 @@ public slots: inline void Ping(uint val) { manager()->watch->ping(val); } inline void SyncTime() { manager()->watch->time(); } - inline void LaunchApp(const QString &uuid) { /* TODO */ } - inline void CloseApp(const QString &uuid) { /* TODO */ } - - bool SendAppMessage(const QString &uuid, const QVariantMap &data) { - Q_ASSERT(calledFromDBus()); - const QDBusMessage msg = message(); - setDelayedReply(true); - manager()->appmsg->send(uuid, data, [this, msg]() { - QDBusMessage reply = msg.createReply(QVariant::fromValue(true)); - this->connection().send(reply); - }, [this, msg]() { - QDBusMessage reply = msg.createReply(QVariant::fromValue(false)); - this->connection().send(reply); - }); - return false; // D-Bus clients should never see this reply. - } - - QString StartAppConfiguration(const QString &uuid) { - Q_ASSERT(calledFromDBus()); - const QDBusMessage msg = message(); - setDelayedReply(true); + inline void LaunchApp(const QString &uuid) { manager()->appmsg->launchApp(uuid); } + inline void CloseApp(const QString &uuid) { manager()->appmsg->closeApp(uuid); } - // TODO - } + bool SendAppMessage(const QString &uuid, const QVariantMap &data); + QString StartAppConfiguration(const QString &uuid); - inline void SendAppConfiguration(const QString &uuid, const QString &data) { + void SendAppConfiguration(const QString &uuid, const QString &data) { // TODO } @@ -166,6 +149,8 @@ signals: void AddressChanged(); void ConnectedChanged(); void AppMessage(const QString &uuid, const QVariantMap &data); + void AppOpened(const QString &uuid); + void AppClosed(const QString &uuid); }; #endif // MANAGER_H |
