This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
Doric/doric-Qt/example/doric/plugin/DoricNotificationPlugin.cpp
2021-07-21 19:03:29 +08:00

47 lines
1.4 KiB
C++

#include "DoricNotificationPlugin.h"
#include "engine/DoricPromise.h"
#include <QCoreApplication>
#include <QJsonDocument>
#include <QJsonObject>
void DoricNotificationPlugin::publish(QString jsValueString,
QString callbackId) {
QJsonDocument document = QJsonDocument::fromJson(jsValueString.toUtf8());
QJsonValue jsValue = document.object();
getContext()->getDriver()->asyncCall(
[this, callbackId] {
QVariantList args;
DoricPromise::resolve(getContext(), callbackId, args);
},
DoricThreadMode::JS);
}
void DoricNotificationPlugin::subscribe(QString jsValueString,
QString callbackId) {
QJsonDocument document = QJsonDocument::fromJson(jsValueString.toUtf8());
QJsonValue jsValue = document.object();
getContext()->getDriver()->asyncCall(
[this, callbackId] {
QVariantList args;
DoricPromise::resolve(getContext(), callbackId, args);
},
DoricThreadMode::JS);
}
void DoricNotificationPlugin::unsubscribe(QString jsValueString,
QString callbackId) {
QJsonDocument document = QJsonDocument::fromJson(jsValueString.toUtf8());
QJsonValue jsValue = document.object();
getContext()->getDriver()->asyncCall(
[this, callbackId] {
QVariantList args;
DoricPromise::resolve(getContext(), callbackId, args);
},
DoricThreadMode::JS);
}