fix(automation): correct nut.js Window API usage in WindowFocusService
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { getWindows, getActiveWindow, focusWindow, Window } from '@nut-tree-fork/nut-js';
|
||||
import { getWindows, getActiveWindow } from '@nut-tree-fork/nut-js';
|
||||
import type { ScreenRegion } from '../../../domain/value-objects/ScreenRegion';
|
||||
import type { WindowInfo, WindowFocusResult } from '../../../application/ports/IScreenAutomation';
|
||||
import type { ILogger } from '../../../application/ports/ILogger';
|
||||
@@ -30,18 +30,17 @@ export class WindowFocusService {
|
||||
|
||||
const windows = await getWindows();
|
||||
|
||||
for (const windowHandle of windows) {
|
||||
for (const windowObj of windows) {
|
||||
try {
|
||||
const windowRef = new Window(windowHandle);
|
||||
const title = await windowRef.getTitle();
|
||||
const title = await windowObj.getTitle();
|
||||
|
||||
if (title.toLowerCase().includes(pattern.toLowerCase())) {
|
||||
this.logger.debug('Found matching window', { title, handle: windowHandle });
|
||||
this.logger.debug('Found matching window', { title });
|
||||
|
||||
await focusWindow(windowRef);
|
||||
await windowObj.focus();
|
||||
|
||||
// Get window bounds after focusing
|
||||
const region = await windowRef.getRegion();
|
||||
const region = await windowObj.getRegion();
|
||||
const bounds: ScreenRegion = {
|
||||
x: region.left,
|
||||
y: region.top,
|
||||
@@ -52,7 +51,7 @@ export class WindowFocusService {
|
||||
const windowInfo: WindowInfo = {
|
||||
title,
|
||||
bounds,
|
||||
handle: windowHandle,
|
||||
handle: 0, // Window objects don't expose raw handles
|
||||
isActive: true,
|
||||
};
|
||||
|
||||
@@ -65,7 +64,7 @@ export class WindowFocusService {
|
||||
}
|
||||
} catch (windowError) {
|
||||
// Skip windows that can't be accessed
|
||||
this.logger.debug('Could not access window', { handle: windowHandle, error: String(windowError) });
|
||||
this.logger.debug('Could not access window', { error: String(windowError) });
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@@ -128,11 +127,10 @@ export class WindowFocusService {
|
||||
const activeWindow = await getActiveWindow();
|
||||
const activeTitle = await activeWindow.getTitle();
|
||||
|
||||
for (const windowHandle of windows) {
|
||||
for (const windowObj of windows) {
|
||||
try {
|
||||
const windowRef = new Window(windowHandle);
|
||||
const title = await windowRef.getTitle();
|
||||
const region = await windowRef.getRegion();
|
||||
const title = await windowObj.getTitle();
|
||||
const region = await windowObj.getRegion();
|
||||
|
||||
const bounds: ScreenRegion = {
|
||||
x: region.left,
|
||||
@@ -144,7 +142,7 @@ export class WindowFocusService {
|
||||
result.push({
|
||||
title,
|
||||
bounds,
|
||||
handle: windowHandle,
|
||||
handle: 0, // Window objects don't expose raw handles
|
||||
isActive: title === activeTitle,
|
||||
});
|
||||
} catch {
|
||||
@@ -170,10 +168,9 @@ export class WindowFocusService {
|
||||
try {
|
||||
const windows = await getWindows();
|
||||
|
||||
for (const windowHandle of windows) {
|
||||
for (const windowObj of windows) {
|
||||
try {
|
||||
const windowRef = new Window(windowHandle);
|
||||
const title = await windowRef.getTitle();
|
||||
const title = await windowObj.getTitle();
|
||||
|
||||
if (title.toLowerCase().includes(pattern.toLowerCase())) {
|
||||
return true;
|
||||
@@ -201,13 +198,12 @@ export class WindowFocusService {
|
||||
try {
|
||||
const windows = await getWindows();
|
||||
|
||||
for (const windowHandle of windows) {
|
||||
for (const windowObj of windows) {
|
||||
try {
|
||||
const windowRef = new Window(windowHandle);
|
||||
const title = await windowRef.getTitle();
|
||||
const title = await windowObj.getTitle();
|
||||
|
||||
if (title.toLowerCase().includes(pattern.toLowerCase())) {
|
||||
const region = await windowRef.getRegion();
|
||||
const region = await windowObj.getRegion();
|
||||
|
||||
return {
|
||||
x: region.left,
|
||||
|
||||
Reference in New Issue
Block a user