Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
905685eef1 | ||
|
|
f68c5a9c55 | ||
|
|
2227c50613 |
@ -2,15 +2,11 @@
|
||||
|
||||
using v8::FunctionTemplate;
|
||||
|
||||
// NativeExtension.cc represents the top level of the module.
|
||||
// C++ constructs that are exposed to javascript are exported here
|
||||
// The top level of the module
|
||||
|
||||
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)
|
||||
|
||||
15
binding.gyp
15
binding.gyp
@ -2,10 +2,15 @@
|
||||
"targets": [
|
||||
{
|
||||
"target_name": "NativeExtension",
|
||||
"sources": [ "NativeExtension.cc", "functions.cc" ],
|
||||
"include_dirs" : [
|
||||
"<!(node -e \"require('nan')\")"
|
||||
]
|
||||
"sources": [],
|
||||
"conditions": [
|
||||
['OS=="win"', {
|
||||
"sources": [ "NativeExtension.cc", "functions.cc" ],
|
||||
"include_dirs" : [
|
||||
"<!(node -e \"require('nan')\")"
|
||||
]
|
||||
}]
|
||||
]
|
||||
}
|
||||
],
|
||||
}
|
||||
}
|
||||
|
||||
41
functions.cc
41
functions.cc
@ -10,44 +10,3 @@ 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_);
|
||||
}
|
||||
|
||||
19
functions.h
19
functions.h
@ -3,25 +3,6 @@
|
||||
|
||||
#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
|
||||
|
||||
@ -1,8 +1,13 @@
|
||||
{
|
||||
"name": "windows-dummy-keystroke",
|
||||
"name": "@signalapp/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"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user