-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1.py
More file actions
57 lines (44 loc) · 2.64 KB
/
1.py
File metadata and controls
57 lines (44 loc) · 2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import time
import uiautomation as auto
print("Antigravity 确认守护脚本 v2 启动... 专打 'Confirmation required' 的 Confirm 按钮 (Ctrl+C 停止)")
TARGET_WINDOW_PARTS = ["Antigravity", "Code", "Visual Studio Code", "Confirmation"] # 窗口标题可能的部分
BUTTON_TARGETS = ["Confirm", "确认", "Proceed", "Allow", "Yes", "Accept"] # 按钮文字(加了中文以防)
POLL_INTERVAL = 1.2
MAX_RUN_TIME = 3600 * 8 # 8小时
start_time = time.time()
while time.time() - start_time < MAX_RUN_TIME:
try:
# 从桌面根开始找所有可能相关的顶级窗口
for hwnd in auto.WindowControl(searchDepth=1).GetChildren():
win = auto.ControlFromHandle(hwnd) # 更稳定获取
if not win.Exists(0):
continue
title = (win.Name or "").lower()
class_name = win.ClassName or ""
if any(p.lower() in title for p in TARGET_WINDOW_PARTS) or "code" in class_name.lower():
# 打印窗口信息帮 debug(第一次跑时看一眼)
if time.time() - start_time < 10:
print(f"找到潜在窗口: Title='{win.Name}', Class='{class_name}'")
# 深搜按钮(Electron 层级深,用大 searchDepth)
buttons = win.ButtonControl(searchDepth=10, foundIndex=auto.MatchIndex.All)
for btn in buttons:
btn_name = (btn.Name or "").strip()
if btn_name and any(t.lower() in btn_name.lower() for t in BUTTON_TARGETS):
print(f"→ 发现并点击按钮: '{btn_name}' (在窗口 '{win.Name}')")
try:
btn.Click(simulateMove=False) # 直接点击最快
time.sleep(0.4) # 给 UI 反应
except Exception as e:
print(f"点击失败: {e}")
break # 一个窗口只点一次,避免乱点
# 如果没找到按钮,第一次打印结构(只打印一次,避免刷屏)
if time.time() - start_time < 15 and not buttons:
print("窗口没找到按钮,打印前5层结构供 debug:")
win.PrintControlIdentifiers(maxDepth=5)
time.sleep(POLL_INTERVAL)
except Exception as e:
# 只打印严重错误,忽略常见 OSError/超时
if "timeout" not in str(e).lower() and "invalid" not in str(e).lower():
print(f"罕见错误: {e}")
time.sleep(POLL_INTERVAL)
print("脚本结束。")