Skip to content

Feature/47/remove bufferfinalizer #60

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions src/buffer_finalizer.h

This file was deleted.

16 changes: 4 additions & 12 deletions src/main.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include <napi.h>

#include "buffer_finalizer.h"
#include "keypress.h"
#include "microsleep.h"
#include "MMBitmap.h"
Expand All @@ -11,7 +10,6 @@

int mouseDelay = 10;
int keyboardDelay = 10;
static BufferFinalizer<char> finalizer;

/*
__ __
Expand Down Expand Up @@ -243,12 +241,6 @@ Napi::Number _scrollMouse(const Napi::CallbackInfo &info)
return Napi::Number::New(env, 1);
}

Napi::Number _theAnswer(const Napi::CallbackInfo &info) {
Napi::Env env = info.Env();

return Napi::Number::New(env, 42);
}

/*
_ __ _ _
| |/ /___ _ _| |__ ___ __ _ _ __ __| |
Expand Down Expand Up @@ -763,8 +755,8 @@ Napi::Object _captureScreen(const Napi::CallbackInfo &info)
throw Napi::Error::New(env, "Error: Failed to capture screen");
}

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

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

destroyMMBitmap(bitmap);

return obj;
}

Napi::Object Init(Napi::Env env, Napi::Object exports) {
exports.Set(Napi::String::New(env, "theAnswer"), Napi::Function::New(env, _theAnswer));

exports.Set(Napi::String::New(env, "dragMouse"), Napi::Function::New(env, _dragMouse));
exports.Set(Napi::String::New(env, "moveMouse"), Napi::Function::New(env, _moveMouse));
exports.Set(Napi::String::New(env, "getMousePos"), Napi::Function::New(env, _getMousePos));
Expand Down