From b37e4d4372e405eb19a1bd21d6e8a8168b9570b1 Mon Sep 17 00:00:00 2001 From: lizhanyuan <949777411@qq.com> Date: Sun, 29 Mar 2026 14:26:56 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20.exe=E5=90=AF=E5=8A=A8=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E6=9C=80=E5=A4=A7=E5=8C=96=E5=B9=B6=E5=BC=BA=E5=88=B6?= =?UTF-8?q?=E5=89=8D=E5=8F=B0=EF=BC=88WaitForInputIdle+SetForegroundWindow?= =?UTF-8?q?=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- desktop_env/controllers/setup.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/desktop_env/controllers/setup.py b/desktop_env/controllers/setup.py index f7637c1..7ebe236 100644 --- a/desktop_env/controllers/setup.py +++ b/desktop_env/controllers/setup.py @@ -309,6 +309,30 @@ class SetupController: if command[0] == "google-chrome" and self.use_proxy: command.append("--proxy-server=http://127.0.0.1:18888") # Use the proxy server set up by _proxy_setup + # Wrap Windows .exe launches with PowerShell to open maximized and focused + if isinstance(command, list) and command and str(command[0]).endswith(".exe"): + exe = command[0].replace("'", "\\'") + args = command[1:] + ps_args = ", ".join(f"'{a}'" for a in args) if args else "" + ps_cmd = f"$p = Start-Process '{exe}'" + if ps_args: + ps_cmd += f" -ArgumentList {ps_args}" + ps_cmd += ( + " -WindowStyle Maximized -PassThru;" + " $p.WaitForInputIdle(15000) | Out-Null;" + " Add-Type -TypeDefinition '" + "using System;using System.Runtime.InteropServices;" + "public class Win32{" + "[DllImport(\"user32.dll\")]public static extern bool SetForegroundWindow(IntPtr h);" + "[DllImport(\"user32.dll\")]public static extern bool BringWindowToTop(IntPtr h);" + "}';" + " [Win32]::SetForegroundWindow($p.MainWindowHandle);" + " [Win32]::BringWindowToTop($p.MainWindowHandle)" + ) + command = ["powershell", "-Command", ps_cmd] + shell = False + logger.info(f"Wrapped launch command with PowerShell maximized+focused: {ps_cmd}") + payload = json.dumps({"command": command, "shell": shell}) headers = {"Content-Type": "application/json"}