Skip to content

(nut-tree/nut-js#377) window title segfault #134

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 6 commits into from
Sep 20, 2022
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"scripts": {
"clean": "cmake-js clean",
"patch": "node ./patch-packagename.js",
"build:debug": "cmake-js rebuild --debug",
"build:debug": "cmake-js rebuild --CDCMAKE_OSX_ARCHITECTURES=\"arm64;x86_64\" --debug",
"build:release": "cmake-js rebuild --CDCMAKE_OSX_ARCHITECTURES=\"arm64;x86_64\"",
"prepublishOnly": "npm run build:release",
"publish:next": "npm publish --tag next"
Expand Down
55 changes: 5 additions & 50 deletions src/macos/mouse_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,61 +23,16 @@ typedef struct {

double GetDoubleClickTime();

inline bool areSamePoint(MMPoint one, MMPoint other) {
return one.x == other.x && one.y == other.y;
}
bool areSamePoint(MMPoint one, MMPoint other);

inline void recordClickTime(ClickTimer *timer, bool down,
void recordClickTime(ClickTimer *timer, bool down,
MMMouseButton button,
MMPoint currentPoint) {
clock_t milli = clock();
if (button == LEFT_BUTTON) {
if (down) {
timer->left.down = milli;
} else {
timer->left.up = milli;
}
} else if (button == CENTER_BUTTON) {
if (down) {
timer->middle.down = milli;
} else {
timer->middle.up = milli;
}
} else if (button == RIGHT_BUTTON) {
if (down) {
timer->right.down = milli;
} else {
timer->right.up = milli;
}
}
timer->clickLocation = currentPoint;
}
MMPoint currentPoint);

inline clock_t timeSinceLastClick(ClickTimer *timer, bool down, MMMouseButton button, clock_t currentTime) {
if (button == LEFT_BUTTON) {
if (down) {
return currentTime - timer->left.down;
} else {
return currentTime - timer->left.up;
}
} else if (button == CENTER_BUTTON) {
if (down) {
return currentTime - timer->middle.down;
} else {
return currentTime - timer->middle.up;
}
} else if (button == RIGHT_BUTTON) {
if (down) {
return currentTime - timer->right.down;
} else {
return currentTime - timer->right.up;
}
}
return 0;
}
clock_t timeSinceLastClick(ClickTimer *timer, bool down, MMMouseButton button, clock_t currentTime);

#ifdef __cplusplus
}
#endif

#endif
#endif
55 changes: 54 additions & 1 deletion src/macos/mouse_utils.mm
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,57 @@
double GetDoubleClickTime() {
double doubleClickInterval = [NSEvent doubleClickInterval];
return doubleClickInterval * 1000;
}
}

bool areSamePoint(MMPoint one, MMPoint other) {
return one.x == other.x && one.y == other.y;
}

void recordClickTime(ClickTimer *timer, bool down,
MMMouseButton button,
MMPoint currentPoint) {
clock_t milli = clock();
if (button == LEFT_BUTTON) {
if (down) {
timer->left.down = milli;
} else {
timer->left.up = milli;
}
} else if (button == CENTER_BUTTON) {
if (down) {
timer->middle.down = milli;
} else {
timer->middle.up = milli;
}
} else if (button == RIGHT_BUTTON) {
if (down) {
timer->right.down = milli;
} else {
timer->right.up = milli;
}
}
timer->clickLocation = currentPoint;
}

clock_t timeSinceLastClick(ClickTimer *timer, bool down, MMMouseButton button, clock_t currentTime) {
if (button == LEFT_BUTTON) {
if (down) {
return currentTime - timer->left.down;
} else {
return currentTime - timer->left.up;
}
} else if (button == CENTER_BUTTON) {
if (down) {
return currentTime - timer->middle.down;
} else {
return currentTime - timer->middle.up;
}
} else if (button == RIGHT_BUTTON) {
if (down) {
return currentTime - timer->right.down;
} else {
return currentTime - timer->right.up;
}
}
return 0;
}
4 changes: 2 additions & 2 deletions src/macos/window_manager.mm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <CoreGraphics/CGWindow.h>
#import <Foundation/Foundation.h>
#import <AppKit/AppKit.h>
#import <ApplicationServices/ApplicationServices.h>
#include "../window_manager.h"

NSDictionary* getWindowInfo(int64_t windowHandle) {
Expand Down Expand Up @@ -88,7 +88,7 @@ MMRect getWindowRect(const WindowHandle windowHandle) {
auto windowInfo = getWindowInfo(windowHandle);
if (windowInfo != nullptr && windowHandle >= 0) {
NSString *windowName = windowInfo[(id)kCGWindowName];
return [windowName UTF8String];
return std::string([windowName UTF8String], [windowName lengthOfBytesUsingEncoding:NSUTF8StringEncoding]);
}
return "";
}
21 changes: 19 additions & 2 deletions src/startup.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,27 @@
static void startupCheck(void) __attribute__((constructor));
static void startupCheck(void)
{
bool isTrustedProcess = AXIsProcessTrusted();
int showDialog = 1;
CFNumberRef showDialogNumber = CFNumberCreate(0, kCFNumberSInt32Type, &showDialog);
const void *keys[1] = { kAXTrustedCheckOptionPrompt };
const void *values[1] = { showDialogNumber };

CFDictionaryRef opts = CFDictionaryCreate(NULL, keys, values, 1, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);

bool isTrustedProcess = AXIsProcessTrustedWithOptions(opts);
if (!isTrustedProcess) {
std::cout << "##### WARNING! The application running this script is not a trusted process! Please visit https://github.com/nut-tree/nut.js#macos #####" << std::endl;
}

bool hasScreenCaptureAccess = CGPreflightScreenCaptureAccess();
if (!hasScreenCaptureAccess) {
CGRequestScreenCaptureAccess();
std::cout << "##### WARNING! The application running this script is not allowed to capture screen content! Please visit https://github.com/nut-tree/nut.js#macos #####" << std::endl;

}

CFRelease(showDialogNumber);
CFRelease(opts);
}

#endif
#endif