Added native event payload on the event listener

This commit is contained in:
Atul R
2019-06-22 20:00:44 +02:00
parent 9f6ecc19dc
commit 1bdf06c4c4
4 changed files with 11 additions and 5 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
#include "eventsmap.h"
std::unordered_map<std::string, int> EventsMap::events {
std::unordered_map<std::string, int> EventsMap::eventTypes {
{ "None", QEvent::None },
{ "ActionAdded", QEvent::ActionAdded },
{ "ActionChanged", QEvent::ActionChanged },
+5 -2
View File
@@ -1,10 +1,12 @@
#include "eventwidget.h"
#include "deps/spdlog/spdlog.h"
#include <napi.h>
void EventWidget::subscribeToQtEvent(std::string evtString){
try {
int evtType = EventsMap::events.at(evtString);
int evtType = EventsMap::eventTypes.at(evtString);
this->subscribedEvents.insert({static_cast<QEvent::Type>(evtType), evtString});
spdlog::info("EventWidget: subscribed to {}", evtString.c_str());
} catch (...) {
spdlog::info("EventWidget: Couldn't subscribe to qt event {}. If this is a signal you can safely ignore this warning", evtString.c_str());
}
@@ -16,7 +18,8 @@ void EventWidget::event(QEvent* event){
QEvent::Type evtType = event->type();
std::string eventTypeString = subscribedEvents.at(evtType);
this->emitOnNode->call([=](Napi::Env env, std::vector<napi_value>& args) {
args = { Napi::String::New(env, eventTypeString) };
Napi::Value nativeEvent = Napi::External<QEvent>::New(env, event);
args = { Napi::String::New(env, eventTypeString), nativeEvent };
});
} catch (...) {
// Do nothing