(name)
| 28 | |
| 29 | |
| 30 | def close_visible_window(name): |
| 31 | if win32gui is None or win32con is None: |
| 32 | return "Close is not available because pywin32 is missing." |
| 33 | wanted = normalize_text(name) |
| 34 | if not wanted or wanted in BLOCKED_APPS: |
| 35 | return "That close request is blocked for safety." |
| 36 | matches = [] |
| 37 | |
| 38 | def callback(hwnd, _): |
| 39 | if not win32gui.IsWindowVisible(hwnd): |
| 40 | return |
| 41 | title = win32gui.GetWindowText(hwnd) |
| 42 | if wanted in normalize_text(title): |
| 43 | matches.append((hwnd, title)) |
| 44 | |
| 45 | win32gui.EnumWindows(callback, None) |
| 46 | if not matches: |
| 47 | return f"I could not find an open window matching {name}." |
| 48 | hwnd, title = matches[0] |
| 49 | win32gui.PostMessage(hwnd, win32con.WM_CLOSE, 0, 0) |
| 50 | return f"Closing {title or name}." |
| 51 | |
| 52 | |
| 53 | def is_safe_url(url): |
no test coverage detected