Skip to content

Commit 6775676

Browse files
committed
feat:将agent的输出重定向至主菜单
1 parent 63baaf9 commit 6775676

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

app/utils/maafw.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -270,17 +270,28 @@ def run_task(self, entry: str, pipeline_override: dict = {}) -> bool:
270270
print(
271271
f"agent启动: {agent_data.get("child_exec").replace("{PROJECT_DIR}", maa_config_data.resource_path)}\nMAA库地址{maa_bin}\nsocket_id: {socket_id}"
272272
)
273-
subprocess.Popen(
273+
agent_process = subprocess.Popen(
274274
[
275275
agent_data.get("child_exec").replace("{PROJECT_DIR}", maa_config_data.resource_path),
276276
*agent_data.get("child_args",[]),
277277
maa_bin,
278278
socket_id,
279279
],
280+
stdout=subprocess.PIPE, # 新增stdout管道
281+
stderr=subprocess.STDOUT, # 合并stderr到stdout
282+
text=True, # 以文本模式读取
283+
encoding=sys.getdefaultencoding(), # 使用系统默认编码
280284
)
281-
logger.debug(
282-
f"agent启动: {agent_data.get("child_exec").replace("{PROJECT_DIR}", maa_config_data.resource_path)}\nMAA库地址{maa_bin}\nsocket_id: {socket_id}"
283-
)
285+
286+
# 创建单独线程读取输出
287+
def read_output():
288+
while agent_process.poll() is None:
289+
line = agent_process.stdout.readline()
290+
if line:
291+
signalBus.custom_info.emit({"type": "agent_output", "data": line.strip()})
292+
293+
import threading
294+
threading.Thread(target=read_output, daemon=True).start()
284295
except Exception as e:
285296
logger.error(f"agent启动失败: {e}")
286297
signalBus.custom_info.emit({"type": "error_a"})

app/view/task_interface.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ def init_ui(self):
129129
)
130130
self.init_finish_combox()
131131

132-
133132
def no_ADB_config(self):
134133
"""
135134
没有ADB配置
@@ -254,6 +253,8 @@ def show_custom_info(self, msg):
254253
)
255254
case "agent_start":
256255
self.insert_colored_text(self.tr("Agent service start"))
256+
case "agent_info":
257+
self.insert_colored_text(msg["data"])
257258

258259
# region 拖动事件
259260
def dragEnter(self, event: QDropEvent):
@@ -842,7 +843,7 @@ async def load_resources(self, PROJECT_DIR):
842843

843844
self.focus_tips = {}
844845
self.on_error_list = []
845-
846+
846847
for i in resource_path:
847848
resource = (
848849
i.replace("{PROJECT_DIR}", PROJECT_DIR)
@@ -1173,9 +1174,13 @@ async def run_tasks(self):
11731174
)
11741175

11751176
await maafw.run_task(self.entry, override_options)
1176-
if not self.task_failed and maa_config_data.interface_config["task"][
1177-
enter_index
1178-
].get("periodic", False) and cfg.get(cfg.speedrun):
1177+
if (
1178+
not self.task_failed
1179+
and maa_config_data.interface_config["task"][enter_index].get(
1180+
"periodic", False
1181+
)
1182+
and cfg.get(cfg.speedrun)
1183+
):
11791184
maa_config_data.config["task"][self.config_index][
11801185
"last_run"
11811186
] = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
@@ -1464,7 +1469,6 @@ def Select_Task(self):
14641469
self.SelectTask_Combox_1.setCurrentText(
14651470
maa_config_data.config["task"][Select_Target]["name"]
14661471
)
1467-
14681472

14691473
self.restore_options(maa_config_data.config["task"][Select_Target]["option"])
14701474

@@ -1576,7 +1580,7 @@ def show_task_options(
15761580
layout.addLayout(v_layout)
15771581

15781582
# 时间限制运行
1579-
if task.get("periodic") in [1, 2] and cfg.get(cfg.speedrun):
1583+
if task.get("periodic") in [1, 2] and cfg.get(cfg.speedrun):
15801584
switch_v_layout = QVBoxLayout()
15811585

15821586
# 添加主标签

0 commit comments

Comments
 (0)