Skip to content

Commit 9298b83

Browse files
authored
Merge pull request #60 from nut-tree/feature/47/remove_bufferfinalizer
Feature/47/remove bufferfinalizer
2 parents dd463e7 + 938e3de commit 9298b83

File tree

2 files changed

+4
-26
lines changed

2 files changed

+4
-26
lines changed

src/buffer_finalizer.h

-14
This file was deleted.

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
| |/ /___ _ _| |__ ___ __ _ _ __ __| |
@@ -761,8 +753,8 @@ Napi::Object _captureScreen(const Napi::CallbackInfo &info)
761753
throw Napi::Error::New(env, "Error: Failed to capture screen");
762754
}
763755

764-
uint32_t bufferSize = (uint32_t)(bitmap->bytewidth * bitmap->height);
765-
Napi::Buffer<char> buffer = Napi::Buffer<char>::New(env, (char *)bitmap->imageBuffer, bufferSize, finalizer);
756+
uint64_t bufferSize = bitmap->bytewidth * bitmap->height;
757+
Napi::Buffer<char> buffer = Napi::Buffer<char>::Copy(env, (char *)bitmap->imageBuffer, bufferSize);
766758

767759
Napi::Object obj = Napi::Object::New(env);
768760
obj.Set(Napi::String::New(env, "width"), Napi::Number::New(env, (double)bitmap->width));
@@ -772,12 +764,12 @@ Napi::Object _captureScreen(const Napi::CallbackInfo &info)
772764
obj.Set(Napi::String::New(env, "bytesPerPixel"), Napi::Number::New(env, bitmap->bytesPerPixel));
773765
obj.Set(Napi::String::New(env, "image"), buffer);
774766

767+
destroyMMBitmap(bitmap);
768+
775769
return obj;
776770
}
777771

778772
Napi::Object Init(Napi::Env env, Napi::Object exports) {
779-
exports.Set(Napi::String::New(env, "theAnswer"), Napi::Function::New(env, _theAnswer));
780-
781773
exports.Set(Napi::String::New(env, "dragMouse"), Napi::Function::New(env, _dragMouse));
782774
exports.Set(Napi::String::New(env, "moveMouse"), Napi::Function::New(env, _moveMouse));
783775
exports.Set(Napi::String::New(env, "getMousePos"), Napi::Function::New(env, _getMousePos));

0 commit comments

Comments
 (0)