Skip to content

Commit b6ff8fe

Browse files
committed
Check if all spawn stop
1 parent 8414196 commit b6ff8fe

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

src/main.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ mod ui;
44

55

66
// main
7-
#[tokio::main(worker_threads = 3)]
7+
#[tokio::main]
88
async fn main() {
99
// 初始化一些东西
1010
let save_path = std::path::Path::new(ui::data::SAVE_DIR);
@@ -22,24 +22,40 @@ async fn main() {
2222

2323
root.show();
2424

25+
let mut handlers: Vec<tokio::task::JoinHandle<()>> = vec![];
26+
2527
// app.run().unwrap();
2628

2729
while app.wait() {
2830
app.redraw();
2931
// 刷新状态栏
3032
buffer.status_bar.set_value(unsafe { &ui::STATUS_BAR_CONTENT });
33+
3134
// 刷新文件系统
3235
buffer.refresh_file_system(ui::data::SAVE_DIR);
3336

37+
// 查看是否还有下载在运行
38+
let mut handle_flag = true;
39+
for handle in handlers.iter() {
40+
if !handle.is_finished() { // 如果没有停止,就是 false
41+
handle_flag = false;
42+
}
43+
}
44+
if handle_flag { // 如果还是 true 的话,那就清楚 status bar
45+
ui::change_status_bar_content(&std::string::String::new());
46+
}
47+
3448
if let Some(msg) = receiver.recv() {
3549
match msg {
3650
Message::Start => {
3751
let buffer_clone = buffer.clone();
3852
println!("Start");
3953

40-
tokio::spawn( async {
41-
ui::network::start(buffer_clone).await;
42-
});
54+
handlers.push(
55+
tokio::spawn( async {
56+
ui::network::start(buffer_clone).await;
57+
})
58+
);
4359
}
4460
}
4561
}

src/ui.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ pub fn add_widgets(root: &mut window::Window, sender: app::Sender<Message>) -> B
121121

122122

123123
let mut start_bt = button::Button::default()
124-
.with_label("Start");
124+
.with_label("Start Download");
125125
start_bt.set_color(Color::White);
126126
start_bt.emit(buffer.sender, Message::Start);
127127

0 commit comments

Comments
 (0)