Skip to content

Commit 938e3de

Browse files
committed
(#47) Switched to using Buffer::Copy
1 parent 166fb11 commit 938e3de

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

Diff for: src/main.cc

+4-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#include <napi.h>
22

3-
#include "buffer_finalizer.h"
43
#include "keypress.h"
54
#include "microsleep.h"
65
#include "MMBitmap.h"
@@ -11,7 +10,6 @@
1110

1211
int mouseDelay = 10;
1312
int keyboardDelay = 10;
14-
static BufferFinalizer<char> finalizer;
1513

1614
/*
1715
__ __
@@ -243,12 +241,6 @@ Napi::Number _scrollMouse(const Napi::CallbackInfo &info)
243241
return Napi::Number::New(env, 1);
244242
}
245243

246-
Napi::Number _theAnswer(const Napi::CallbackInfo &info) {
247-
Napi::Env env = info.Env();
248-
249-
return Napi::Number::New(env, 42);
250-
}
251-
252244
/*
253245
_ __ _ _
254246
| |/ /___ _ _| |__ ___ __ _ _ __ __| |
@@ -763,8 +755,8 @@ Napi::Object _captureScreen(const Napi::CallbackInfo &info)
763755
throw Napi::Error::New(env, "Error: Failed to capture screen");
764756
}
765757

766-
uint32_t bufferSize = (uint32_t)(bitmap->bytewidth * bitmap->height);
767-
Napi::Buffer<char> buffer = Napi::Buffer<char>::New(env, (char *)bitmap->imageBuffer, bufferSize, finalizer);
758+
uint64_t bufferSize = bitmap->bytewidth * bitmap->height;
759+
Napi::Buffer<char> buffer = Napi::Buffer<char>::Copy(env, (char *)bitmap->imageBuffer, bufferSize);
768760

769761
Napi::Object obj = Napi::Object::New(env);
770762
obj.Set(Napi::String::New(env, "width"), Napi::Number::New(env, (double)bitmap->width));
@@ -774,12 +766,12 @@ Napi::Object _captureScreen(const Napi::CallbackInfo &info)
774766
obj.Set(Napi::String::New(env, "bytesPerPixel"), Napi::Number::New(env, bitmap->bytesPerPixel));
775767
obj.Set(Napi::String::New(env, "image"), buffer);
776768

769+
destroyMMBitmap(bitmap);
770+
777771
return obj;
778772
}
779773

780774
Napi::Object Init(Napi::Env env, Napi::Object exports) {
781-
exports.Set(Napi::String::New(env, "theAnswer"), Napi::Function::New(env, _theAnswer));
782-
783775
exports.Set(Napi::String::New(env, "dragMouse"), Napi::Function::New(env, _dragMouse));
784776
exports.Set(Napi::String::New(env, "moveMouse"), Napi::Function::New(env, _moveMouse));
785777
exports.Set(Napi::String::New(env, "getMousePos"), Napi::Function::New(env, _getMousePos));

0 commit comments

Comments
 (0)