Skip to content
This repository was archived by the owner on Feb 19, 2026. It is now read-only.

Commit 97cefe0

Browse files
committed
fix: task window
1 parent 97f2d27 commit 97cefe0

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

gui/src/main.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ enum Msg {
9898
ToggleLanguage,
9999
WindowOpened(window::Id),
100100
WindowClosed(window::Id),
101+
CloseTaskWindow(window::Id),
101102
}
102103

103104
struct App {
@@ -122,6 +123,7 @@ struct TaskWindow {
122123
abort_handle: Option<AbortHandle>,
123124
max_lines: usize,
124125
auto_scroll: bool,
126+
terminated_by_user: bool,
125127
}
126128

127129
impl App {
@@ -174,7 +176,11 @@ impl App {
174176
if !guard.contains_key(&w.task_id)
175177
|| guard.get(&w.task_id).map(|v| v.is_empty()).unwrap_or(true)
176178
{
177-
to_remove.push(*wid);
179+
// 只有当任务真正完成(非用户终止)时才移除窗口
180+
// 如果任务是被用户终止的,不应该移除窗口,让用户继续查看日志
181+
if !w.terminated_by_user {
182+
to_remove.push(*wid);
183+
}
178184
}
179185
}
180186
}
@@ -341,6 +347,7 @@ impl App {
341347
abort_handle: Some(abort_handle),
342348
max_lines: 1000,
343349
auto_scroll: true,
350+
terminated_by_user: false,
344351
},
345352
);
346353
start_task_for_window(task_id, abort_reg, args);
@@ -392,6 +399,7 @@ impl App {
392399
h.abort();
393400
}
394401
w.running = false;
402+
w.terminated_by_user = true;
395403
}
396404
Task::none()
397405
}
@@ -419,6 +427,10 @@ impl App {
419427
}
420428
Task::none()
421429
}
430+
Msg::CloseTaskWindow(id) => {
431+
// 关闭任务窗口
432+
window::close(id)
433+
}
422434
Msg::WindowClosed(id) => {
423435
if Some(id) == self.main_id {
424436
// Main window is being closed - close all windows to ensure app exits
@@ -463,11 +475,11 @@ impl App {
463475
.width(Length::Fixed(80.0)),
464476
checkbox("Auto Scroll", w.auto_scroll)
465477
.on_toggle(move |checked| Msg::ToggleAutoScroll(id, checked)),
466-
button(text(if w.running { "Terminate" } else { "Stopped" })).on_press(
478+
button(text(if w.running { "终止" } else { "关闭窗口" })).on_press(
467479
if w.running {
468480
Msg::LogTerminate(id)
469481
} else {
470-
Msg::TickAll
482+
Msg::CloseTaskWindow(id)
471483
}
472484
)
473485
]

0 commit comments

Comments
 (0)