add notification plugin

This commit is contained in:
王劲鹏 2021-06-07 17:12:55 +08:00 committed by osborn
parent 8c0b4d0b11
commit bb48faaf47
3 changed files with 73 additions and 0 deletions

View File

@ -38,6 +38,7 @@ SOURCES += \
engine/v8/V8Executor.cpp \ engine/v8/V8Executor.cpp \
plugin/DoricModalPlugin.cpp \ plugin/DoricModalPlugin.cpp \
plugin/DoricNetworkPlugin.cpp \ plugin/DoricNetworkPlugin.cpp \
plugin/DoricNotificationPlugin.cpp \
plugin/DoricPopoverPlugin.cpp \ plugin/DoricPopoverPlugin.cpp \
plugin/DoricShaderPlugin.cpp \ plugin/DoricShaderPlugin.cpp \
plugin/DoricStoragePlugin.cpp \ plugin/DoricStoragePlugin.cpp \
@ -124,6 +125,7 @@ HEADERS += \
plugin/DoricModalPlugin.h \ plugin/DoricModalPlugin.h \
plugin/DoricNativePlugin.h \ plugin/DoricNativePlugin.h \
plugin/DoricNetworkPlugin.h \ plugin/DoricNetworkPlugin.h \
plugin/DoricNotificationPlugin.h \
plugin/DoricPopoverPlugin.h \ plugin/DoricPopoverPlugin.h \
plugin/DoricShaderPlugin.h \ plugin/DoricShaderPlugin.h \
plugin/DoricStoragePlugin.h \ plugin/DoricStoragePlugin.h \

View File

@ -0,0 +1,46 @@
#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);
}

View File

@ -0,0 +1,25 @@
#ifndef DORICNOTIFICATIONPLUGIN_H
#define DORICNOTIFICATIONPLUGIN_H
#include "DoricExport.h"
#include "DoricNativePlugin.h"
#include <QUdpSocket>
class DORIC_EXPORT DoricNotificationPlugin : public DoricNativePlugin {
Q_OBJECT
private:
QUdpSocket udpSocket;
public:
using DoricNativePlugin::DoricNativePlugin;
Q_INVOKABLE void publish(QString jsValueString, QString callbackId);
Q_INVOKABLE void subscribe(QString jsValueString, QString callbackId);
Q_INVOKABLE void unsubscribe(QString jsValueString, QString callbackId);
};
#endif // DORICNOTIFICATIONPLUGIN_H