Compare commits

..

No commits in common. "signal" and "main" have entirely different histories.
signal ... main

5 changed files with 71 additions and 17 deletions

View File

@ -2,11 +2,15 @@
using v8::FunctionTemplate;
// The top level of the module
// NativeExtension.cc represents the top level of the module.
// C++ constructs that are exposed to javascript are exported here
NAN_MODULE_INIT(InitAll) {
Nan::Set(target, Nan::New("sendDummyKeystroke").ToLocalChecked(),
Nan::GetFunction(Nan::New<FunctionTemplate>(sendDummyKeystroke)).ToLocalChecked());
// Passing target down to the next NAN_MODULE_INIT
MyObject::Init(target);
}
NODE_MODULE(NativeExtension, InitAll)

View File

@ -2,15 +2,10 @@
"targets": [
{
"target_name": "NativeExtension",
"sources": [],
"conditions": [
['OS=="win"', {
"sources": [ "NativeExtension.cc", "functions.cc" ],
"include_dirs" : [
"<!(node -e \"require('nan')\")"
]
}]
]
"sources": [ "NativeExtension.cc", "functions.cc" ],
"include_dirs" : [
"<!(node -e \"require('nan')\")"
]
}
],
}
}

View File

@ -10,3 +10,44 @@ NAN_METHOD(sendDummyKeystroke) {
::SendInput(2, inputs, sizeof(inputs[0]));
}
// Wrapper Impl
Nan::Persistent<v8::Function> MyObject::constructor;
NAN_MODULE_INIT(MyObject::Init) {
v8::Local<v8::FunctionTemplate> tpl = Nan::New<v8::FunctionTemplate>(New);
tpl->SetClassName(Nan::New("MyObject").ToLocalChecked());
tpl->InstanceTemplate()->SetInternalFieldCount(1);
Nan::SetPrototypeMethod(tpl, "plusOne", PlusOne);
constructor.Reset(Nan::GetFunction(tpl).ToLocalChecked());
Nan::Set(target, Nan::New("MyObject").ToLocalChecked(), Nan::GetFunction(tpl).ToLocalChecked());
}
MyObject::MyObject(double value) : value_(value) {
}
MyObject::~MyObject() {
}
NAN_METHOD(MyObject::New) {
if (info.IsConstructCall()) {
double value = info[0]->IsUndefined() ? 0 : Nan::To<double>(info[0]).FromJust();
MyObject *obj = new MyObject(value);
obj->Wrap(info.This());
info.GetReturnValue().Set(info.This());
} else {
const int argc = 1;
v8::Local<v8::Value> argv[argc] = {info[0]};
v8::Local<v8::Function> cons = Nan::New(constructor);
info.GetReturnValue().Set(Nan::NewInstance(cons, argc, argv).ToLocalChecked());
}
}
NAN_METHOD(MyObject::PlusOne) {
MyObject* obj = Nan::ObjectWrap::Unwrap<MyObject>(info.This());
obj->value_ += 1;
info.GetReturnValue().Set(obj->value_);
}

View File

@ -3,6 +3,25 @@
#include <nan.h>
// Example top-level functions. These functions demonstrate how to return various js types.
// Implementations are in functions.cc
NAN_METHOD(sendDummyKeystroke);
// Example with node ObjectWrap
// Based on https://nodejs.org/api/addons.html#addons_wrapping_c_objects but using NAN
class MyObject : public Nan::ObjectWrap {
public:
static NAN_MODULE_INIT(Init);
private:
explicit MyObject(double value = 0);
~MyObject();
static NAN_METHOD(New);
static NAN_METHOD(PlusOne);
static Nan::Persistent<v8::Function> constructor;
double value_;
};
#endif

View File

@ -1,13 +1,8 @@
{
"name": "@signalapp/windows-dummy-keystroke",
"name": "windows-dummy-keystroke",
"version": "1.0.0",
"main": "index.js",
"types": "index.d.ts",
"repository": {
"type": "git",
"url": "git+https://github.com/signalapp/windows-dummy-keystroke.git"
},
"homepage": "https://github.com/signalapp/windows-dummy-keystroke#readme",
"scripts": {
"configure": "node-gyp configure",
"build": "node-gyp build"