Skip to content

Commit

Permalink
Check if all spawn stop
Browse files Browse the repository at this point in the history
  • Loading branch information
iewnfod committed May 25, 2023
1 parent 8414196 commit b6ff8fe
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
24 changes: 20 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ mod ui;


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

root.show();

let mut handlers: Vec<tokio::task::JoinHandle<()>> = vec![];

// app.run().unwrap();

while app.wait() {
app.redraw();
// 刷新状态栏
buffer.status_bar.set_value(unsafe { &ui::STATUS_BAR_CONTENT });

// 刷新文件系统
buffer.refresh_file_system(ui::data::SAVE_DIR);

// 查看是否还有下载在运行
let mut handle_flag = true;
for handle in handlers.iter() {
if !handle.is_finished() { // 如果没有停止,就是 false
handle_flag = false;
}
}
if handle_flag { // 如果还是 true 的话,那就清楚 status bar
ui::change_status_bar_content(&std::string::String::new());
}

if let Some(msg) = receiver.recv() {
match msg {
Message::Start => {
let buffer_clone = buffer.clone();
println!("Start");

tokio::spawn( async {
ui::network::start(buffer_clone).await;
});
handlers.push(
tokio::spawn( async {
ui::network::start(buffer_clone).await;
})
);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ pub fn add_widgets(root: &mut window::Window, sender: app::Sender<Message>) -> B


let mut start_bt = button::Button::default()
.with_label("Start");
.with_label("Start Download");
start_bt.set_color(Color::White);
start_bt.emit(buffer.sender, Message::Start);

Expand Down

0 comments on commit b6ff8fe

Please sign in to comment.