Skip to content

Commit

Permalink
Meet requirment of memory cage in recent Electron versions.
Browse files Browse the repository at this point in the history
  • Loading branch information
raphaelmenges committed May 13, 2023
1 parent 369333e commit 14e54da
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -19,6 +19,6 @@
"devDependencies": {
"@types/node": "18.13.0",
"cmake-js": "7.2.0",
"node-addon-api": "6.0.0"
"node-addon-api": "6.1.0"
}
}
3 changes: 2 additions & 1 deletion src/robotjs.cc
@@ -1,4 +1,5 @@
#define NAPI_VERSION 4
#define NODE_API_NO_EXTERNAL_BUFFERS_ALLOWED // https://github.com/nodejs/node-addon-api/blob/main/doc/external_buffer.md
#include <napi.h>
#include <vector>
#include "screen.h"
Expand Down Expand Up @@ -51,7 +52,7 @@ Napi::Value CaptureScreen(const Napi::CallbackInfo& info)
MMBitmapRef bitmap = copyMMBitmapFromDisplayInRect(MMRectMake(x, y, w, h));

uint32_t bufferSize = bitmap->bytewidth * bitmap->height;
auto buffer = Napi::Buffer<char>::New(info.Env(), (char*)bitmap->imageBuffer, bufferSize, myDestroyMMBitmapBuffer);
auto buffer = Napi::Buffer<char>::NewOrCopy(info.Env(), (char*)bitmap->imageBuffer, bufferSize, myDestroyMMBitmapBuffer);

Napi::Object obj = Napi::Object::New(info.Env());
obj.Set("width", bitmap->width);
Expand Down

0 comments on commit 14e54da

Please sign in to comment.