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 { ScreenRegion } from '../../../domain/value-objects/ScreenRegion';
|
||||||
import type { WindowInfo, WindowFocusResult } from '../../../application/ports/IScreenAutomation';
|
import type { WindowInfo, WindowFocusResult } from '../../../application/ports/IScreenAutomation';
|
||||||
import type { ILogger } from '../../../application/ports/ILogger';
|
import type { ILogger } from '../../../application/ports/ILogger';
|
||||||
@@ -30,18 +30,17 @@ export class WindowFocusService {
|
|||||||
|
|
||||||
const windows = await getWindows();
|
const windows = await getWindows();
|
||||||
|
|
||||||
for (const windowHandle of windows) {
|
for (const windowObj of windows) {
|
||||||
try {
|
try {
|
||||||
const windowRef = new Window(windowHandle);
|
const title = await windowObj.getTitle();
|
||||||
const title = await windowRef.getTitle();
|
|
||||||
|
|
||||||
if (title.toLowerCase().includes(pattern.toLowerCase())) {
|
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
|
// Get window bounds after focusing
|
||||||
const region = await windowRef.getRegion();
|
const region = await windowObj.getRegion();
|
||||||
const bounds: ScreenRegion = {
|
const bounds: ScreenRegion = {
|
||||||
x: region.left,
|
x: region.left,
|
||||||
y: region.top,
|
y: region.top,
|
||||||
@@ -52,7 +51,7 @@ export class WindowFocusService {
|
|||||||
const windowInfo: WindowInfo = {
|
const windowInfo: WindowInfo = {
|
||||||
title,
|
title,
|
||||||
bounds,
|
bounds,
|
||||||
handle: windowHandle,
|
handle: 0, // Window objects don't expose raw handles
|
||||||
isActive: true,
|
isActive: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -65,7 +64,7 @@ export class WindowFocusService {
|
|||||||
}
|
}
|
||||||
} catch (windowError) {
|
} catch (windowError) {
|
||||||
// Skip windows that can't be accessed
|
// 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;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -128,11 +127,10 @@ export class WindowFocusService {
|
|||||||
const activeWindow = await getActiveWindow();
|
const activeWindow = await getActiveWindow();
|
||||||
const activeTitle = await activeWindow.getTitle();
|
const activeTitle = await activeWindow.getTitle();
|
||||||
|
|
||||||
for (const windowHandle of windows) {
|
for (const windowObj of windows) {
|
||||||
try {
|
try {
|
||||||
const windowRef = new Window(windowHandle);
|
const title = await windowObj.getTitle();
|
||||||
const title = await windowRef.getTitle();
|
const region = await windowObj.getRegion();
|
||||||
const region = await windowRef.getRegion();
|
|
||||||
|
|
||||||
const bounds: ScreenRegion = {
|
const bounds: ScreenRegion = {
|
||||||
x: region.left,
|
x: region.left,
|
||||||
@@ -144,7 +142,7 @@ export class WindowFocusService {
|
|||||||
result.push({
|
result.push({
|
||||||
title,
|
title,
|
||||||
bounds,
|
bounds,
|
||||||
handle: windowHandle,
|
handle: 0, // Window objects don't expose raw handles
|
||||||
isActive: title === activeTitle,
|
isActive: title === activeTitle,
|
||||||
});
|
});
|
||||||
} catch {
|
} catch {
|
||||||
@@ -170,10 +168,9 @@ export class WindowFocusService {
|
|||||||
try {
|
try {
|
||||||
const windows = await getWindows();
|
const windows = await getWindows();
|
||||||
|
|
||||||
for (const windowHandle of windows) {
|
for (const windowObj of windows) {
|
||||||
try {
|
try {
|
||||||
const windowRef = new Window(windowHandle);
|
const title = await windowObj.getTitle();
|
||||||
const title = await windowRef.getTitle();
|
|
||||||
|
|
||||||
if (title.toLowerCase().includes(pattern.toLowerCase())) {
|
if (title.toLowerCase().includes(pattern.toLowerCase())) {
|
||||||
return true;
|
return true;
|
||||||
@@ -201,13 +198,12 @@ export class WindowFocusService {
|
|||||||
try {
|
try {
|
||||||
const windows = await getWindows();
|
const windows = await getWindows();
|
||||||
|
|
||||||
for (const windowHandle of windows) {
|
for (const windowObj of windows) {
|
||||||
try {
|
try {
|
||||||
const windowRef = new Window(windowHandle);
|
const title = await windowObj.getTitle();
|
||||||
const title = await windowRef.getTitle();
|
|
||||||
|
|
||||||
if (title.toLowerCase().includes(pattern.toLowerCase())) {
|
if (title.toLowerCase().includes(pattern.toLowerCase())) {
|
||||||
const region = await windowRef.getRegion();
|
const region = await windowObj.getRegion();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
x: region.left,
|
x: region.left,
|
||||||
|
|||||||
Reference in New Issue
Block a user