Skip to content

Commit 08edf8b

Browse files
committed
(#18) Migrating window tests to playwright, WIP
1 parent 4097c9b commit 08edf8b

File tree

5 files changed

+4475
-4515
lines changed

5 files changed

+4475
-4515
lines changed

src/macos/window_manager.mm

+5-14
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,7 @@ bool focusWindow(const WindowHandle windowHandle) {
200200
}
201201

202202
/**
203-
* Resizes and repositions the window provided via its handle to the specified rectangle.
204-
*
205-
* This function retrieves window information using the provided window handle, then uses
206-
* macOS Accessibility APIs to resize and reposition the window to fit within the provided
207-
* rectangle dimensions and location.
203+
* Resizes the window provided via its handle to the specified width/height.
208204
*
209205
* @param windowHandle Handle to the window that needs to be resized.
210206
* @param newSize The width/height to which the window should be resized.
@@ -255,11 +251,7 @@ bool resizeWindow(const WindowHandle windowHandle, const MMSize newSize) {
255251
}
256252

257253
/**
258-
* Resizes and repositions the window provided via its handle to the specified rectangle.
259-
*
260-
* This function retrieves window information using the provided window handle, then uses
261-
* macOS Accessibility APIs to resize and reposition the window to fit within the provided
262-
* rectangle dimensions and location.
254+
* Moves the window provided via its handle to the specified point.
263255
*
264256
* @param windowHandle Handle to the window that needs to be resized.
265257
* @param newOrigin The x/y coordinates to which the window should be repositioned.
@@ -280,8 +272,7 @@ bool moveWindow(const WindowHandle windowHandle, const MMPoint newOrigin) {
280272
AXUIElementRef app = AXUIElementCreateApplication(pid);
281273
AXUIElementRef window;
282274

283-
AXError error = AXUIElementCopyAttributeValue(app, kAXFocusedWindowAttribute,
284-
(CFTypeRef *) &window);
275+
AXError error = AXUIElementCopyAttributeValue(app, kAXFocusedWindowAttribute, (CFTypeRef *) &window);
285276

286277
// If no error occurred, proceed with the resize and reposition operations
287278
if (error == kAXErrorSuccess) {
@@ -299,12 +290,12 @@ bool moveWindow(const WindowHandle windowHandle, const MMPoint newOrigin) {
299290
CFRelease(app);
300291

301292
// Return true to indicate successful resize
302-
return true;
293+
return YES;
303294
} else {
304295
// NSLog(@"Could not resize window with window handle %lld", windowHandle);
305296
CFRelease(app);
306297
return false;
307298
}
308299

309-
return true;
300+
return YES;
310301
}

src/main.cc

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "screen.h"
88
#include "screengrab.h"
99
#include "window_manager.h"
10+
#include <iostream>
1011

1112
int mouseDelay = 10;
1213
int keyboardDelay = 10;
@@ -688,14 +689,15 @@ Napi::Boolean _moveWindow(const Napi::CallbackInfo& info) {
688689
}
689690

690691
WindowHandle windowHandle = info[0].As<Napi::Number>().Int64Value();
691-
auto rectObj = info[1].As<Napi::Object>();
692692

693+
auto rectObj = info[1].As<Napi::Object>();
693694
if (!rectObj.Has("x") || !rectObj.Has("y")) {
694695
throw Napi::TypeError::New(env, "Invalid second parameter. Expected object of shape {x: number, y: number}");
695696
}
696697

697698
auto x = rectObj.Get("x").As<Napi::Number>().Int64Value();
698699
auto y = rectObj.Get("y").As<Napi::Number>().Int64Value();
700+
std::cout << "moving to " << x << ", " << y << std::endl;
699701

700702
auto newOrigin = MMPointMake(x, y);
701703

0 commit comments

Comments
 (0)