myagent-ai 1.47.29 → 1.47.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/core/vnc_manager.py +88 -2
- package/package.json +1 -1
package/core/vnc_manager.py
CHANGED
|
@@ -56,6 +56,72 @@ logger = get_logger("myagent.vnc")
|
|
|
56
56
|
|
|
57
57
|
DEFAULT_DISPLAY = ":99"
|
|
58
58
|
DEFAULT_XVFB_RESOLUTION = "1080x1920x24" # [v1.47.3] 默认竖屏(手机),旋转切换到横屏
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def _detect_android_screen_size() -> Optional[tuple]:
|
|
62
|
+
"""[v1.47.29] 检测 Android 设备屏幕物理尺寸(宽x高,像素)。
|
|
63
|
+
|
|
64
|
+
优先级:
|
|
65
|
+
1. 环境变量 MYAGENT_SCREEN (用户手动指定,格式 "1097x550")
|
|
66
|
+
2. getprop ro.hardware.screen_width/height (部分 ROM)
|
|
67
|
+
3. /sys/class/graphics/fb0/virtual_size (内核帧缓冲区)
|
|
68
|
+
4. getprop qemu.sf.lcd_density + ro.sf.lcd_density 推算
|
|
69
|
+
|
|
70
|
+
Returns:
|
|
71
|
+
(width, height) 元组,检测失败返回 None
|
|
72
|
+
"""
|
|
73
|
+
# 1. 环境变量
|
|
74
|
+
env_screen = os.environ.get("MYAGENT_SCREEN", "").strip()
|
|
75
|
+
if env_screen and "x" in env_screen:
|
|
76
|
+
try:
|
|
77
|
+
parts = env_screen.lower().split("x")
|
|
78
|
+
w, h = int(parts[0]), int(parts[1])
|
|
79
|
+
if w > 0 and h > 0:
|
|
80
|
+
logger.info(f"屏幕尺寸来自环境变量 MYAGENT_SCREEN: {w}x{h}")
|
|
81
|
+
return (w, h)
|
|
82
|
+
except (ValueError, IndexError):
|
|
83
|
+
pass
|
|
84
|
+
|
|
85
|
+
# 2. getprop 属性(部分 ROM 有 ro.hardware.screen_width/height)
|
|
86
|
+
try:
|
|
87
|
+
result_w = subprocess.run(
|
|
88
|
+
["getprop", "ro.hardware.screen_width"],
|
|
89
|
+
capture_output=True, text=True, timeout=3,
|
|
90
|
+
)
|
|
91
|
+
result_h = subprocess.run(
|
|
92
|
+
["getprop", "ro.hardware.screen_height"],
|
|
93
|
+
capture_output=True, text=True, timeout=3,
|
|
94
|
+
)
|
|
95
|
+
if result_w.returncode == 0 and result_h.returncode == 0:
|
|
96
|
+
sw = result_w.stdout.strip()
|
|
97
|
+
sh = result_h.stdout.strip()
|
|
98
|
+
if sw and sh and sw.isdigit() and sh.isdigit():
|
|
99
|
+
w, h = int(sw), int(sh)
|
|
100
|
+
if w > 0 and h > 0:
|
|
101
|
+
logger.info(f"屏幕尺寸来自 getprop: {w}x{h}")
|
|
102
|
+
return (w, h)
|
|
103
|
+
except Exception:
|
|
104
|
+
pass
|
|
105
|
+
|
|
106
|
+
# 3. 内核帧缓冲区尺寸
|
|
107
|
+
fb_path = "/sys/class/graphics/fb0/virtual_size"
|
|
108
|
+
try:
|
|
109
|
+
if os.path.exists(fb_path):
|
|
110
|
+
with open(fb_path, "r") as f:
|
|
111
|
+
content = f.read().strip()
|
|
112
|
+
# 格式通常是 "1097,550"
|
|
113
|
+
if "," in content:
|
|
114
|
+
parts = content.split(",")
|
|
115
|
+
w, h = int(parts[0]), int(parts[1])
|
|
116
|
+
if w > 0 and h > 0:
|
|
117
|
+
logger.info(f"屏幕尺寸来自帧缓冲区: {w}x{h}")
|
|
118
|
+
return (w, h)
|
|
119
|
+
except Exception:
|
|
120
|
+
pass
|
|
121
|
+
|
|
122
|
+
return None
|
|
123
|
+
|
|
124
|
+
|
|
59
125
|
DEFAULT_X11VNC_PORT = 5900
|
|
60
126
|
DEFAULT_NOVNC_PORT = 6080 # WebSocket 代理端口(供 noVNC 客户端连接)
|
|
61
127
|
|
|
@@ -75,11 +141,21 @@ class VNCManager:
|
|
|
75
141
|
def __init__(
|
|
76
142
|
self,
|
|
77
143
|
display: str = DEFAULT_DISPLAY,
|
|
78
|
-
resolution: str =
|
|
144
|
+
resolution: str = "",
|
|
79
145
|
x11vnc_port: int = DEFAULT_X11VNC_PORT,
|
|
80
146
|
novnc_port: int = DEFAULT_NOVNC_PORT,
|
|
81
147
|
):
|
|
82
148
|
self.display = display
|
|
149
|
+
# [v1.47.29] 自动检测 Android 屏幕尺寸设置 VNC 分辨率
|
|
150
|
+
if not resolution:
|
|
151
|
+
screen_size = _detect_android_screen_size()
|
|
152
|
+
if screen_size:
|
|
153
|
+
w, h = screen_size
|
|
154
|
+
resolution = f"{w}x{h}x24"
|
|
155
|
+
logger.info(f"VNC 分辨率已适配设备屏幕: {w}x{h}")
|
|
156
|
+
else:
|
|
157
|
+
resolution = DEFAULT_XVFB_RESOLUTION
|
|
158
|
+
logger.info(f"未检测到设备屏幕尺寸,使用默认分辨率: {resolution}")
|
|
83
159
|
self.resolution = resolution
|
|
84
160
|
self.x11vnc_port = x11vnc_port
|
|
85
161
|
self.novnc_port = novnc_port
|
|
@@ -5015,9 +5091,19 @@ exec "$BROWSER" "$@"
|
|
|
5015
5091
|
"-nowcr", # 禁用 cursor shape updates
|
|
5016
5092
|
"-nocursorshape",
|
|
5017
5093
|
"-deferupdate", "5", # 延迟更新(降低带宽)
|
|
5018
|
-
"-scale", "2/3", # 缩小 2/3(降低带宽)
|
|
5019
5094
|
]
|
|
5020
5095
|
|
|
5096
|
+
# [v1.47.29] VNC 缩放策略:分辨率匹配屏幕时不缩放,大分辨率缩小 2/3
|
|
5097
|
+
try:
|
|
5098
|
+
res_parts = self.resolution.split("x")
|
|
5099
|
+
res_w, res_h = int(res_parts[0]), int(res_parts[1])
|
|
5100
|
+
if res_w * res_h > 1600 * 900:
|
|
5101
|
+
# 大分辨率(如 1080x1920)→ 缩小 2/3 降低带宽
|
|
5102
|
+
cmd.extend(["-scale", "2/3"])
|
|
5103
|
+
# else: 小/匹配分辨率 → 不缩放,保持清晰
|
|
5104
|
+
except (ValueError, IndexError):
|
|
5105
|
+
cmd.extend(["-scale", "2/3"])
|
|
5106
|
+
|
|
5021
5107
|
# [v1.18.5] 不使用 -threads 模式:与 -scale 组合在 0.9.17 中
|
|
5022
5108
|
# 会导致父进程 fork 后立即退出,端口延迟监听
|
|
5023
5109
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "myagent-ai",
|
|
3
|
-
"version": "1.47.
|
|
3
|
+
"version": "1.47.30",
|
|
4
4
|
"description": "\u672c\u5730\u684c\u9762\u7aef\u6267\u884c\u578bAI\u52a9\u624b - Open Interpreter \u98ce\u683c | Local Desktop Execution-Oriented AI Assistant",
|
|
5
5
|
"main": "main.py",
|
|
6
6
|
"bin": {
|