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"}