From b013bc846381ec203e6a6f90d094de85b795c36a Mon Sep 17 00:00:00 2001 From: Teodor Nikolov Date: Thu, 9 Apr 2026 14:05:05 +0300 Subject: [PATCH 1/2] added minimize and maximize command --- lib/commands/app.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/commands/app.ts b/lib/commands/app.ts index 4faa938..b7b8034 100644 --- a/lib/commands/app.ts +++ b/lib/commands/app.ts @@ -64,6 +64,24 @@ export async function getPageSource(this: NovaWindowsDriver): Promise { return await this.sendPowerShellCommand(GET_PAGE_SOURCE_COMMAND.format(AutomationElement.automationRoot)); } +export async function maximizeWindow(this: NovaWindowsDriver): Promise { + const automationRoot = new FoundAutomationElement(AutomationElement.automationRoot.buildGetPropertyCommand(Property.RUNTIME_ID)); + try { + await this.sendPowerShellCommand(automationRoot.buildMaximizeCommand()); + } catch { + throw new errors.UnknownError('Failed to maximize the window.'); + } +} + +export async function minimizeWindow(this: NovaWindowsDriver): Promise { + const automationRoot = new FoundAutomationElement(AutomationElement.automationRoot.buildGetPropertyCommand(Property.RUNTIME_ID)); + try { + await this.sendPowerShellCommand(automationRoot.buildMinimizeCommand()); + } catch { + throw new errors.UnknownError('Failed to minimize the window.'); + } +} + export async function getScreenshot(this: NovaWindowsDriver): Promise { const automationRootId = await this.sendPowerShellCommand(AutomationElement.automationRoot.buildCommand()); From 49aee1c2992e10d21657fa6238f5baa2a6013f6a Mon Sep 17 00:00:00 2001 From: Teodor Nikolov Date: Thu, 9 Apr 2026 14:05:26 +0300 Subject: [PATCH 2/2] changed finding new applicaiton window logic --- lib/commands/app.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/commands/app.ts b/lib/commands/app.ts index b7b8034..3d56438 100644 --- a/lib/commands/app.ts +++ b/lib/commands/app.ts @@ -305,10 +305,17 @@ export async function waitForNewWindow(this: NovaWindowsDriver, pid: number, tim let attempts = 0; while (Date.now() - start < timeout) { - const handles = getWindowAllHandlesForProcessIds([pid]); + // const handles = getWindowAllHandlesForProcessIds([pid]); - if (handles.length > 0) { - return handles[handles.length - 1]; + // if (handles.length > 0) { + // return handles[handles.length - 1]; + // } + + const elements = await this.sendPowerShellCommand(AutomationElement.rootElement.findAll(TreeScope.CHILDREN, new PropertyCondition(Property.PROCESS_ID, new PSInt32(pid))).buildCommand()); + const elementIds = elements.split('\n').map((id) => id.trim()).filter(Boolean); + if (elementIds.length > 0) { + const nativeWindowHandle = await this.sendPowerShellCommand(new FoundAutomationElement(elementIds[0]).buildGetPropertyCommand(Property.NATIVE_WINDOW_HANDLE)); + return Number(nativeWindowHandle); } this.log.debug(`Waiting for the process window to appear... (${++attempts}/${Math.floor(timeout / SLEEP_INTERVAL_MS)})`);